Skip to content

Commit

Permalink
upgrade to 2.0.0-BETA2 with JDK11
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu committed Dec 30, 2018
1 parent 132a120 commit a7ededa
Show file tree
Hide file tree
Showing 23 changed files with 684 additions and 29 deletions.
35 changes: 34 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# Change Log

## [1.5.24](https://github.com/networknt/light-rest-4j/tree/1.5.24) (2018-12-15)
[Full Changelog](https://github.com/networknt/light-rest-4j/compare/1.5.23...1.5.24)

**Fixed bugs:**

- OpenAPI validation does not fail when incorrect types are passed in the Request Body [\#64](https://github.com/networknt/light-rest-4j/issues/64)

**Merged pull requests:**

- made changes based on comments of https://github.com/networknt/light-rest-4j/pull/65 [\#66](https://github.com/networknt/light-rest-4j/pull/66) ([BalloonWen](https://github.com/BalloonWen))
- Fixed \#64 [\#65](https://github.com/networknt/light-rest-4j/pull/65) ([BalloonWen](https://github.com/BalloonWen))

## [1.5.23](https://github.com/networknt/light-rest-4j/tree/1.5.23) (2018-12-01)
[Full Changelog](https://github.com/networknt/light-rest-4j/compare/1.5.22...1.5.23)

**Merged pull requests:**

- OpenApiHelper class will not fail when the optional servers section is not provided [\#63](https://github.com/networknt/light-rest-4j/pull/63) ([zabooma](https://github.com/zabooma))

## [1.5.22](https://github.com/networknt/light-rest-4j/tree/1.5.22) (2018-11-10)
[Full Changelog](https://github.com/networknt/light-rest-4j/compare/1.5.21...1.5.22)

**Closed issues:**

- Configured class: com.foo.reportListener.handler.SpecYamlGetHandler has not been found [\#61](https://github.com/networknt/light-rest-4j/issues/61)

## [1.5.21](https://github.com/networknt/light-rest-4j/tree/1.5.21) (2018-10-26)
[Full Changelog](https://github.com/networknt/light-rest-4j/compare/1.5.20...1.5.21)

**Implemented enhancements:**

- add an endpoint to serve swagger-ui for manual testing [\#30](https://github.com/networknt/light-rest-4j/issues/30)

## [1.5.20](https://github.com/networknt/light-rest-4j/tree/1.5.20) (2018-10-05)
[Full Changelog](https://github.com/networknt/light-rest-4j/compare/1.5.19...1.5.20)

Expand Down Expand Up @@ -269,4 +302,4 @@



\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,18 @@ private static String getOAuth2Name() {
}

private static String getBasePath() {

String basePath = "";
Server server = openApi3.getServer(0);
String url = server.getUrl();
if(url != null) {
String url = null;
if (openApi3.getServers().size() > 0) {
Server server = openApi3.getServer(0);
url = server.getUrl();
}
if (url != null) {
// find "://" index
int protocolIndex = url.indexOf("://");
int pathIndex = url.indexOf('/', protocolIndex + 3);
if(pathIndex > 0) {
if (pathIndex > 0) {
basePath = url.substring(pathIndex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.networknt.audit.AuditHandler;
import com.networknt.client.Http2Client;
import com.networknt.config.Config;
import com.networknt.exception.ClientException;
import com.networknt.status.Status;
import com.networknt.status.exception.ClientException;
import io.undertow.Handlers;
import io.undertow.Undertow;
import io.undertow.client.ClientConnection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.networknt.audit.AuditHandler;
import com.networknt.config.Config;
import com.networknt.exception.ExpiredTokenException;
import com.networknt.handler.Handler;
import com.networknt.handler.MiddlewareHandler;
import com.networknt.httpstring.HttpStringConstants;
Expand All @@ -27,6 +26,7 @@
import com.networknt.oas.model.SecurityParameter;
import com.networknt.oas.model.SecurityRequirement;
import com.networknt.security.JwtHelper;
import com.networknt.status.exception.ExpiredTokenException;
import com.networknt.utility.Constants;
import com.networknt.utility.ModuleRegistry;
import io.undertow.Handlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import com.networknt.client.Http2Client;
import com.networknt.config.Config;
import com.networknt.exception.ClientException;
import com.networknt.status.Status;
import com.networknt.status.exception.ClientException;
import io.undertow.Handlers;
import io.undertow.Undertow;
import io.undertow.client.ClientConnection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
import com.networknt.jsonoverlay.Overlay;
import com.networknt.oas.model.Parameter;
import com.networknt.oas.model.RequestBody;
import com.networknt.oas.model.impl.ParameterImpl;
import com.networknt.oas.model.impl.RequestBodyImpl;
import com.networknt.oas.model.impl.SchemaImpl;
import com.networknt.schema.SchemaValidatorsConfig;
import com.networknt.status.Status;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.HeaderValues;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.Collection;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -109,7 +110,9 @@ private Status validateRequestBody(Object requestBody, final OpenApiOperation op
}
return null;
}
return schemaValidator.validate(requestBody, Overlay.toJson((SchemaImpl)specBody.getContentMediaType("application/json").getSchema()));
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
config.setTypeLoose(false);
return schemaValidator.validate(requestBody, Overlay.toJson((SchemaImpl)specBody.getContentMediaType("application/json").getSchema()), config);
}

private Status validatePathParameters(final NormalisedPath requestPath, final OpenApiOperation openApiOperation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
import com.networknt.oas.model.impl.OpenApi3Impl;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SchemaValidatorsConfig;
import com.networknt.schema.ValidationMessage;
import com.networknt.status.Status;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -74,15 +73,19 @@ public SchemaValidator(final OpenApi3 api) {
*
* @param value The value to validate
* @param schema The property schema to validate the value against
* @param config The config model for some validator
*
* @return A status containing error code and description
*/
public Status validate(final Object value, final JsonNode schema) {
return doValidate(value, schema);
public Status validate(final Object value, final JsonNode schema, SchemaValidatorsConfig config) {
return doValidate(value, schema, config);
}

public Status validate(final Object value, final JsonNode schema) {
return doValidate(value, schema, null);
}

private Status doValidate(final Object value, final JsonNode schema) {
private Status doValidate(final Object value, final JsonNode schema, SchemaValidatorsConfig config) {
requireNonNull(schema, "A schema is required");

Status status = null;
Expand All @@ -91,7 +94,7 @@ private Status doValidate(final Object value, final JsonNode schema) {
if(jsonNode != null) {
((ObjectNode)schema).set(COMPONENTS_FIELD, jsonNode);
}
JsonSchema jsonSchema = JsonSchemaFactory.getInstance().getSchema(schema);
JsonSchema jsonSchema = JsonSchemaFactory.getInstance().getSchema(schema, config);
final JsonNode content = Config.getInstance().getMapper().valueToTree(value);
processingReport = jsonSchema.validate(content);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import com.networknt.body.BodyHandler;
import com.networknt.client.Http2Client;
import com.networknt.config.Config;
import com.networknt.exception.ClientException;
import com.networknt.status.Status;
import com.networknt.status.exception.ClientException;
import io.undertow.Handlers;
import io.undertow.Undertow;
import io.undertow.client.ClientConnection;
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<version.swagger-parser>1.0.34</version.swagger-parser>
<version.swagger-core>1.5.18</version.swagger-core>
<version.jsr305>3.0.2</version.jsr305>
<version.json-schema-validator>0.1.23</version.json-schema-validator>
<version.json-schema-validator>0.1.25</version.json-schema-validator>
<versions.maven-version>2.4</versions.maven-version>
<argLine>-Xmx512m -XX:MaxPermSize=256m</argLine>
</properties>
Expand All @@ -95,6 +95,7 @@
<module>openapi-meta</module>
<module>openapi-validator</module>
<module>openapi-security</module>
<module>specification</module>
</modules>

<dependencyManagement>
Expand Down
73 changes: 73 additions & 0 deletions specification/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>light-rest-4j</artifactId>
<groupId>com.networknt</groupId>
<version>2.0.0-BETA2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.networknt</groupId>
<artifactId>specification</artifactId>


<dependencies>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>config</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>utility</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>security</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>handler</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>status</artifactId>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>com.networknt</groupId>
<artifactId>client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

package com.networknt.specification;

import com.networknt.config.Config;
import com.networknt.handler.LightHttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.HttpString;

/**
* Display API Specification
*
* @author Gavin Chen
*/
public class SpecDisplayHandler implements LightHttpHandler {
public static final String CONFIG_NAME = "specification";

public SpecDisplayHandler(){
}

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
SpecificationConfig config = (SpecificationConfig)Config.getInstance().getJsonObjectConfig(CONFIG_NAME, SpecificationConfig.class);
final String payload = Config.getInstance().getStringFromFile(config.getFileName());
exchange.getResponseHeaders().add(new HttpString("Content-Type"), config.getContentType());
exchange.getResponseSender().send(payload);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

package com.networknt.specification;

import com.networknt.handler.LightHttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.HttpString;

/**
* Display API Specification in Swagger editor UI
*
* @author Gavin Chen
*/
public class SpecSwaggerUIHandler implements LightHttpHandler {

public SpecSwaggerUIHandler(){}



@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {

exchange.getResponseHeaders().add(new HttpString("Content-Type"), "text/html");
exchange.getResponseSender().send(getDisplayHtml());
}

private String getDisplayHtml() {
return "<html>\n" +
"<head>\n" +
" <title>OpenAPI Spec</title>\n" +
" <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.3/swagger-ui.css\">\n" +
"</head>\n" +
"<body>\n" +
"<div id=\"swagger-ui\"></div>\n" +
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.3/swagger-ui-bundle.js\"></script>\n" +
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.19.3/swagger-ui-standalone-preset.js\"></script>\n" +
"<script>\n" +
"window.onload = function() {\n" +
"\n" +
" const ui = SwaggerUIBundle({\n" +
" url: \"spec.yaml\",\n" +
" validatorUrl : false,\n" +
" dom_id: '#swagger-ui',\n" +
" deepLinking: true,\n" +
" presets: [\n" +
" SwaggerUIBundle.presets.apis,\n" +
" SwaggerUIStandalonePreset\n" +
" ],\n" +
" plugins: [\n" +
" SwaggerUIBundle.plugins.DownloadUrl\n" +
" ],\n" +
" layout: \"StandaloneLayout\"\n" +
" })\n" +
"\n" +
" window.ui = ui\n" +
"}\n" +
"</script>\n" +
"</body>\n" +
"</html>";
}
}
Loading

0 comments on commit a7ededa

Please sign in to comment.