Skip to content

Commit

Permalink
Merge branch '1.6.x' into fix/#314-config-parameterization
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu committed Jul 1, 2019
2 parents ac15967 + c9177d3 commit b71ecfe
Show file tree
Hide file tree
Showing 17 changed files with 243 additions and 85 deletions.
24 changes: 15 additions & 9 deletions codegen-core/src/main/java/com/networknt/codegen/Generator.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.networknt.codegen;

import com.fizzed.rocker.runtime.ArrayOfByteArraysOutput;
import com.fizzed.rocker.runtime.DefaultRockerModel;
import com.jsoniter.any.Any;
import org.apache.commons.io.IOUtils;

import java.io.File;
import static java.io.File.separator;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -14,13 +10,14 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermission;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static java.io.File.separator;
import com.fizzed.rocker.runtime.ArrayOfByteArraysOutput;
import com.fizzed.rocker.runtime.DefaultRockerModel;
import com.jsoniter.any.Any;

import org.apache.commons.io.IOUtils;

/**
* This is the interface that every generator needs to implement. There are three methods
Expand Down Expand Up @@ -165,4 +162,13 @@ default boolean checkExist(String folder, String path, String filename) throws I
return Files.exists(Paths.get(absPath));
}

static void copyFile(final InputStream is, final java.nio.file.Path folder) throws IOException {
java.nio.file.Path parent = folder.getParent();
if (!Files.isDirectory(parent)) {
Files.createDirectories(parent);
}

Files.copy(is, folder, StandardCopyOption.REPLACE_EXISTING);
}

}
8 changes: 8 additions & 0 deletions codegen-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
<groupId>com.networknt</groupId>
<artifactId>resource</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>health</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>info</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.networknt.rpc.Handler;
import com.networknt.rpc.router.JsonHandler;
import com.networknt.rpc.router.ServiceHandler;
import com.networknt.status.Status;
import com.networknt.utility.HashUtil;
import com.networknt.utility.NioUtils;
import io.undertow.server.HttpServerExchange;
Expand All @@ -26,7 +25,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.InvalidParameterException;
import java.util.*;

import static java.io.File.separator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.networknt.rpc.Handler;
import com.networknt.rpc.router.JsonHandler;
import com.networknt.rpc.router.ServiceHandler;
import com.networknt.status.Status;
import com.networknt.utility.HashUtil;
import com.networknt.utility.NioUtils;
import io.undertow.server.HttpServerExchange;
Expand Down
86 changes: 86 additions & 0 deletions codegen-web/src/main/resources/config/handler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Handler middleware chain configuration
---
enabled: true

#------------------------------------------------------------------------------
# Support individual handler chains for each separate endpoint. It allows framework
# handlers like health check, server info to bypass majority of the middleware handlers
# and allows mixing multiple frameworks like OpenAPI and GraphQL in the same instance.
#
# handlers -- list of handlers to be used across chains in this microservice
# including the routing handlers for ALL endpoints
# -- format: fully qualified handler class name@optional:given name
# chains -- allows forming of [1..N] chains, which could be wholly or
# used to form handler chains for each endpoint
# ex.: default chain below, reused partially across multiple endpoints
# paths -- list all the paths to be used for routing within the microservice
# ---- path: the URI for the endpoint (ex.: path: '/v1/pets')
# ---- method: the operation in use (ex.: 'post')
# ---- exec: handlers to be executed -- this element forms the list and
# the order of execution for the handlers
#
# IMPORTANT NOTES:
# - to avoid executing a handler, it has to be removed/commented out in the chain
# or change the enabled:boolean to false for a middleware handler configuration.
# - all handlers, routing handler included, are to be listed in the execution chain
# - for consistency, give a name to each handler; it is easier to refer to a name
# vs a fully qualified class name and is more elegant
# - you can list in chains the fully qualified handler class names, and avoid using the
# handlers element altogether
#------------------------------------------------------------------------------
handlers:
# Light-framework cross-cutting concerns implemented in the microservice
- com.networknt.exception.ExceptionHandler@exception
- com.networknt.metrics.MetricsHandler@metrics
- com.networknt.traceability.TraceabilityHandler@traceability
- com.networknt.correlation.CorrelationHandler@correlation
# Cors handler to handler post/put pre-flight
- com.networknt.cors.CorsHttpHandler@cors
# - com.networknt.openapi.OpenApiHandler@specification
# - com.networknt.openapi.JwtVerifyHandler@security
# - com.networknt.body.BodyHandler@body
# - com.networknt.audit.AuditHandler@audit
# - com.networknt.sanitizer.SanitizerHandler@sanitizer
# - com.networknt.openapi.ValidatorHandler@validator
# Header middleware to manipulate request and/or response headers before or after downstream server
# - com.networknt.header.HeaderHandler@header
# Direct requests to named services based on the request path
# - com.networknt.router.middleware.PathPrefixServiceHandler@path
# - com.networknt.router.RouterHandler@router
# - com.networknt.resource.PathResourceHandler@resource
- com.networknt.rpc.router.JsonHandler@json
# Customer business domain specific cross-cutting concerns handlers
# - com.example.validator.CustomizedValidator@custvalidator
# Framework endpoint handlers
- com.networknt.health.HealthGetHandler@health
- com.networknt.info.ServerInfoGetHandler@info
# - com.networknt.metrics.prometheus.PrometheusGetHandler@getprometheus

chains:
default:
- exception
- metrics
- traceability
- correlation
- json

paths:
- path: '/codegen'
method: 'POST'
exec:
- default
- path: '/codegen'
method: 'GET'
exec:
- default

- path: '/health/com.networknt.codegen-web-2.0.0'
method: 'get'
exec:
- health

# In most case, the /server/info endpoint shouldn't be exposed. If it is, then it must be protected by OAuth 2.0 or Basic Auth
- path: '/server/info'
method: 'get'
exec:
- info
4 changes: 4 additions & 0 deletions codegen-web/src/main/resources/config/rpc-router.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
description: RPC router description
handlerPackage: 'com.networknt.codegen'
jsonPath: /codegen
2 changes: 1 addition & 1 deletion codegen-web/src/main/resources/config/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enableTwoWayTls: false
truststoreName: server.truststore

# Unique service identifier. Used in service registration and discovery etc.
serviceId: com.networknt.example-graphql-subscription-1.0.0
serviceId: com.networknt.codegen-web-1.6.0

# Flag to enable service registration. Only be true if running as standalone Java jar.
enableRegistry: false
Expand Down
15 changes: 1 addition & 14 deletions codegen-web/src/main/resources/config/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,7 @@ singletons:
# - com.networknt.server.ShutdownHookProvider:
# - com.networknt.server.Test1ShutdownHook
# - com.networknt.server.Test2ShutdownHook
# MiddlewareHandler implementations
- com.networknt.handler.MiddlewareHandler:
# Exception Global exception handler that needs to be called first.
- com.networknt.exception.ExceptionHandler
# Metrics In order to calculate response time accurately, this needs to be the second.
- com.networknt.metrics.MetricsHandler
# Traceability Put traceabilityId into response header from request header if it exists
- com.networknt.traceability.TraceabilityHandler
# Correlation Create correlationId if it doesn't exist in the request header and put it into the request header
- com.networknt.correlation.CorrelationHandler
# Cors handler to handler post/put pre-flight
- com.networknt.cors.CorsHttpHandler
# SimpleAudit Log important info about the request into audit log
- com.networknt.audit.AuditHandler

# Generator interface implementations
- com.networknt.codegen.Generator:
- com.networknt.codegen.rest.OpenApiGenerator
Expand Down
10 changes: 8 additions & 2 deletions codegen-web/src/main/resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@
},
"framework": {
"type": "string"
},
"release": {
"type": "string"
}
},
"required": ["configType", "modelType", "framework"]
"required": ["configType", "modelType", "framework", "release"]
},
"maxItems": 5,
"minItems": 1
Expand Down Expand Up @@ -91,9 +94,12 @@
},
"framework": {
"type" : "string"
},
"release": {
"type" : "string"
}
},
"required": ["configType", "modelType", "framework"]
"required": ["configType", "modelType", "framework", "release"]
},
"scope": "codegen.w"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testGenerator() throws ClientException, ApiException, UnsupportedEnc
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.networknt.client.Http2Client;
import com.networknt.exception.ApiException;
import com.networknt.exception.ClientException;
import io.undertow.UndertowOptions;
import io.undertow.client.ClientConnection;
import io.undertow.client.ClientRequest;
import io.undertow.client.ClientResponse;
Expand All @@ -20,7 +19,6 @@
import org.xnio.OptionMap;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -80,7 +78,7 @@ public void testMissingGeneratorItem() throws ClientException {
}
try {
connection.getIoThread().execute(() -> {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");

request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
Expand Down Expand Up @@ -133,7 +131,7 @@ public void testInvalidFrameworkMultiple() throws ClientException, IOException {
}
try {
connection.getIoThread().execute(() -> {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down Expand Up @@ -185,7 +183,7 @@ public void testInvalidFrameworkSingle() throws ClientException, IOException {
}
try {
connection.getIoThread().execute(() -> {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down Expand Up @@ -234,7 +232,7 @@ public void testGeneratorMultipleText() throws ClientException, ApiException, IO
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down Expand Up @@ -278,7 +276,7 @@ public void testGeneratorSingleText() throws ClientException, ApiException, IOEx
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down Expand Up @@ -322,7 +320,7 @@ public void testGeneratorMultipleAllUrl() throws ClientException, ApiException,
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down Expand Up @@ -366,7 +364,7 @@ public void testGeneratorSingleModelUrl() throws ClientException, ApiException,
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testGetSchema() throws ClientException, ApiException, UnsupportedEnc
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/api/json");
final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/codegen");
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, auth);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
Expand Down
5 changes: 3 additions & 2 deletions codegen-web/view/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ export function submitForm(action) {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'env_tag': action.data.release
},
body: JSON.stringify(action)
};
//console.log(request);
console.log(action.data.release);
try {
const response = await fetch('/portal/query', request);
const response = await fetch('/codegen', request);
const data = await response.blob();
const filename = 'light-project.zip';
if (typeof window.navigator.msSaveBlob !== 'undefined') {
Expand Down
Loading

0 comments on commit b71ecfe

Please sign in to comment.