diff --git a/CHANGELOG.md b/CHANGELOG.md
index 202e12dd..445bb971 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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)
@@ -269,4 +302,4 @@
-\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\ No newline at end of file
+\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
diff --git a/openapi-meta/src/main/java/com/networknt/openapi/OpenApiHelper.java b/openapi-meta/src/main/java/com/networknt/openapi/OpenApiHelper.java
index b81f36b3..eabe3831 100644
--- a/openapi-meta/src/main/java/com/networknt/openapi/OpenApiHelper.java
+++ b/openapi-meta/src/main/java/com/networknt/openapi/OpenApiHelper.java
@@ -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);
}
}
diff --git a/openapi-meta/src/test/java/com/networknt/openapi/OpenApiHandlerTest.java b/openapi-meta/src/test/java/com/networknt/openapi/OpenApiHandlerTest.java
index ebc57e24..447c28c9 100644
--- a/openapi-meta/src/test/java/com/networknt/openapi/OpenApiHandlerTest.java
+++ b/openapi-meta/src/test/java/com/networknt/openapi/OpenApiHandlerTest.java
@@ -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;
diff --git a/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java b/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java
index 1e62a630..6631bdfa 100644
--- a/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java
+++ b/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java
@@ -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;
@@ -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;
diff --git a/openapi-security/src/test/java/com/networknt/openapi/JwtVerifyHandlerTest.java b/openapi-security/src/test/java/com/networknt/openapi/JwtVerifyHandlerTest.java
index 4210a4eb..43ef50e4 100644
--- a/openapi-security/src/test/java/com/networknt/openapi/JwtVerifyHandlerTest.java
+++ b/openapi-security/src/test/java/com/networknt/openapi/JwtVerifyHandlerTest.java
@@ -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;
diff --git a/openapi-validator/src/main/java/com/networknt/openapi/RequestValidator.java b/openapi-validator/src/main/java/com/networknt/openapi/RequestValidator.java
index 99f8e221..3d6a27c2 100644
--- a/openapi-validator/src/main/java/com/networknt/openapi/RequestValidator.java
+++ b/openapi-validator/src/main/java/com/networknt/openapi/RequestValidator.java
@@ -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;
@@ -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) {
diff --git a/openapi-validator/src/main/java/com/networknt/openapi/SchemaValidator.java b/openapi-validator/src/main/java/com/networknt/openapi/SchemaValidator.java
index 51907378..06e293c3 100644
--- a/openapi-validator/src/main/java/com/networknt/openapi/SchemaValidator.java
+++ b/openapi-validator/src/main/java/com/networknt/openapi/SchemaValidator.java
@@ -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;
@@ -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;
@@ -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) {
diff --git a/openapi-validator/src/test/java/com/networknt/openapi/ValidatorHandlerTest.java b/openapi-validator/src/test/java/com/networknt/openapi/ValidatorHandlerTest.java
index 4151d944..dbaa4d9b 100644
--- a/openapi-validator/src/test/java/com/networknt/openapi/ValidatorHandlerTest.java
+++ b/openapi-validator/src/test/java/com/networknt/openapi/ValidatorHandlerTest.java
@@ -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;
diff --git a/pom.xml b/pom.xml
index 8d436b7e..ce8106fb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,7 +83,7 @@
1.0.34
1.5.18
3.0.2
- 0.1.23
+ 0.1.25
2.4
-Xmx512m -XX:MaxPermSize=256m
@@ -95,6 +95,7 @@
openapi-meta
openapi-validator
openapi-security
+ specification
diff --git a/specification/pom.xml b/specification/pom.xml
new file mode 100644
index 00000000..b49f6a60
--- /dev/null
+++ b/specification/pom.xml
@@ -0,0 +1,73 @@
+
+
+
+ light-rest-4j
+ com.networknt
+ 2.0.0-BETA2
+
+ 4.0.0
+
+ com.networknt
+ specification
+
+
+
+
+ com.networknt
+ config
+
+
+ com.networknt
+ utility
+
+
+ com.networknt
+ security
+
+
+ com.networknt
+ handler
+
+
+ com.networknt
+ status
+
+
+ io.undertow
+ undertow-core
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
+
+ org.slf4j
+ slf4j-api
+
+
+
+ com.networknt
+ client
+ test
+
+
+ ch.qos.logback
+ logback-classic
+ test
+
+
+ junit
+ junit
+ test
+
+
+ org.apache.commons
+ commons-text
+ test
+
+
+
+
+
\ No newline at end of file
diff --git a/specification/src/main/java/com/networknt/specification/SpecDisplayHandler.java b/specification/src/main/java/com/networknt/specification/SpecDisplayHandler.java
new file mode 100644
index 00000000..baef76d3
--- /dev/null
+++ b/specification/src/main/java/com/networknt/specification/SpecDisplayHandler.java
@@ -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);
+ }
+
+}
diff --git a/specification/src/main/java/com/networknt/specification/SpecSwaggerUIHandler.java b/specification/src/main/java/com/networknt/specification/SpecSwaggerUIHandler.java
new file mode 100644
index 00000000..81d8e527
--- /dev/null
+++ b/specification/src/main/java/com/networknt/specification/SpecSwaggerUIHandler.java
@@ -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 "\n" +
+ "\n" +
+ " OpenAPI Spec\n" +
+ " \n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "";
+ }
+}
diff --git a/specification/src/main/java/com/networknt/specification/SpecificationConfig.java b/specification/src/main/java/com/networknt/specification/SpecificationConfig.java
new file mode 100644
index 00000000..810b5bd9
--- /dev/null
+++ b/specification/src/main/java/com/networknt/specification/SpecificationConfig.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2016 Network New Technologies Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.networknt.specification;
+
+/**
+ * Config class for Spec display Handler
+ *
+ */
+public class SpecificationConfig {
+ String fileName;
+ String contentType;
+
+ public SpecificationConfig() {
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+}
diff --git a/specification/src/main/resources/config/specification.yml b/specification/src/main/resources/config/specification.yml
new file mode 100644
index 00000000..b9e67c6b
--- /dev/null
+++ b/specification/src/main/resources/config/specification.yml
@@ -0,0 +1,5 @@
+---
+# Sepcification type and file name definition
+
+fileName: config/openapi.yaml
+contentType: text/yaml
diff --git a/specification/src/test/java/com/networknt/specification/SpecDisplayHandlerTest.java b/specification/src/test/java/com/networknt/specification/SpecDisplayHandlerTest.java
new file mode 100644
index 00000000..5d5a5c49
--- /dev/null
+++ b/specification/src/test/java/com/networknt/specification/SpecDisplayHandlerTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2016 Network New Technologies Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.networknt.specification;
+
+import com.networknt.client.Http2Client;
+import com.networknt.status.exception.ClientException;
+import io.undertow.Handlers;
+import io.undertow.Undertow;
+import io.undertow.client.ClientConnection;
+import io.undertow.client.ClientRequest;
+import io.undertow.client.ClientResponse;
+import io.undertow.server.HttpHandler;
+import io.undertow.server.RoutingHandler;
+import io.undertow.util.Headers;
+import io.undertow.util.Methods;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xnio.IoUtils;
+import org.xnio.OptionMap;
+
+import java.net.URI;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Created by Gavin Chen.
+ */
+public class SpecDisplayHandlerTest {
+ static final Logger logger = LoggerFactory.getLogger(SpecDisplayHandlerTest.class);
+
+ static Undertow server = null;
+
+ @BeforeClass
+ public static void setUp() {
+ if(server == null) {
+ logger.info("starting server");
+ HttpHandler handler = getTestHandler();
+ server = Undertow.builder()
+ .addHttpListener(8080, "localhost")
+ .setHandler(handler)
+ .build();
+ server.start();
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ if(server != null) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException ignored) {
+
+ }
+ server.stop();
+ logger.info("The server is stopped.");
+ }
+ }
+
+ static RoutingHandler getTestHandler() {
+ return Handlers.routing().add(Methods.GET, "/spec.yml", new SpecDisplayHandler());
+ }
+
+ @Test
+ public void testSpec() throws Exception {
+ final Http2Client client = Http2Client.getInstance();
+ final CountDownLatch latch = new CountDownLatch(1);
+ final ClientConnection connection;
+ try {
+ connection = client.connect(new URI("http://localhost:8080"), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, OptionMap.EMPTY).get();
+ } catch (Exception e) {
+ throw new ClientException(e);
+ }
+ final AtomicReference reference = new AtomicReference<>();
+ try {
+ ClientRequest request = new ClientRequest().setPath("/spec.yml").setMethod(Methods.GET);
+ request.getRequestHeaders().put(Headers.HOST, "localhost");
+ connection.sendRequest(request, client.createClientCallback(reference, latch));
+ latch.await();
+ } catch (Exception e) {
+ logger.error("Exception: ", e);
+ throw new ClientException(e);
+ } finally {
+ IoUtils.safeClose(connection);
+ }
+ int statusCode = reference.get().getResponseCode();
+ String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
+ Assert.assertEquals(200, statusCode);
+ Assert.assertNotNull( body);
+ }
+}
diff --git a/specification/src/test/resources/config/openapi.yaml b/specification/src/test/resources/config/openapi.yaml
new file mode 100644
index 00000000..7a8a9bc9
--- /dev/null
+++ b/specification/src/test/resources/config/openapi.yaml
@@ -0,0 +1,211 @@
+openapi: 3.0.0
+info:
+ version: 1.0.0
+ title: Swagger Petstore
+ license:
+ name: MIT
+servers:
+ - url: 'http://petstore.swagger.io/v1'
+paths:
+ /pets:
+ parameters:
+ - $ref: '#/components/parameters/accessId'
+ - $ref: '#/components/parameters/requestId'
+ get:
+ summary: List all pets
+ operationId: listPets
+ tags:
+ - pets
+ parameters:
+ - name: limit
+ in: query
+ description: How many items to return at one time (max 100)
+ required: false
+ schema:
+ type: integer
+ format: int32
+ - name: all
+ in: query
+ description: Retrieve all for defect 57
+ schema:
+ type: boolean
+ security:
+ - petstore_auth:
+ - 'read:pets'
+ responses:
+ '200':
+ description: An paged array of pets
+ headers:
+ x-next:
+ description: A link to the next page of responses
+ schema:
+ type: string
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/Pet'
+ example:
+ - id: 1
+ name: catten
+ tag: cat
+ - id: 2
+ name: doggy
+ tag: dog
+ default:
+ description: unexpected error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Error'
+ post:
+ summary: Create a pet
+ operationId: createPets
+ requestBody:
+ description: Pet to add to the store
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Pet'
+ tags:
+ - pets
+ security:
+ - petstore_auth:
+ - 'read:pets'
+ - 'write:pets'
+ responses:
+ '201':
+ description: Null response
+ default:
+ description: unexpected error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Error'
+ '/pets/{petId}':
+ get:
+ summary: Info for a specific pet
+ operationId: showPetById
+ tags:
+ - pets
+ parameters:
+ - name: petId
+ in: path
+ required: true
+ description: The id of the pet to retrieve
+ schema:
+ type: string
+ security:
+ - petstore_auth:
+ - 'read:pets'
+ responses:
+ '200':
+ description: Expected response to a valid request
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Pet'
+ example:
+ id: 1
+ name: Jessica Right
+ tag: pet
+ default:
+ description: unexpected error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Error'
+ delete:
+ summary: Delete a specific pet
+ operationId: deletePetById
+ tags:
+ - pets
+ parameters:
+ - name: petId
+ in: path
+ required: true
+ description: The id of the pet to delete oneOf test issue 58
+ schema:
+ type: string
+ - name: key
+ in: header
+ required: true
+ description: The key header
+ schema:
+ type: string
+ security:
+ - petstore_auth:
+ - 'write:pets'
+ responses:
+ '200':
+ description: Expected response to a valid request
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Pet'
+ examples:
+ response:
+ value:
+ id: 1
+ name: Jessica Right
+ tag: pet
+ default:
+ description: unexpected error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Error'
+components:
+ parameters:
+ accessId:
+ name: accessId
+ in: header
+ description: unique id that identifies a partner
+ required: true
+ schema:
+ type: string
+ maximum: 50
+ requestId:
+ name: requestId
+ in: header
+ description: partner generated unique id for each request used for message tracking purposes
+ required: true
+ schema:
+ type: string
+ minimum: 1
+ maximum: 64
+ securitySchemes:
+ petstore_auth:
+ type: oauth2
+ description: This API uses OAuth 2 with the client credential grant flow.
+ flows:
+ clientCredentials:
+ tokenUrl: 'https://localhost:6882/token'
+ scopes:
+ 'write:pets': modify pets in your account
+ 'read:pets': read your pets
+ schemas:
+ Pet:
+ required:
+ - id
+ - name
+ properties:
+ id:
+ type: integer
+ format: int64
+ name:
+ type: string
+ tag:
+ type: string
+ Error:
+ required:
+ - code
+ - message
+ properties:
+ code:
+ type: integer
+ format: int32
+ message:
+ type: string
diff --git a/specification/src/test/resources/logback-test.xml b/specification/src/test/resources/logback-test.xml
new file mode 100644
index 00000000..0cace6d8
--- /dev/null
+++ b/specification/src/test/resources/logback-test.xml
@@ -0,0 +1,72 @@
+
+
+
+
+ TODO create logger for audit only.
+ http://stackoverflow.com/questions/2488558/logback-to-log-different-messages-to-two-files
+
+ PROFILER
+
+ NEUTRAL
+
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5marker %-5level %logger{36} - %msg%n
+
+
+
+
+ target/test.log
+ false
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %class{36}:%L %M - %msg%n
+
+
+
+
+
+ target/audit.log
+
+ %-5level [%thread] %date{ISO8601} %F:%L - %msg%n
+ true
+
+
+ target/audit.log.%i.zip
+ 1
+ 5
+
+
+ 200MB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/swagger-meta/src/test/java/com/networknt/swagger/SwaggerHandlerTest.java b/swagger-meta/src/test/java/com/networknt/swagger/SwaggerHandlerTest.java
index 881357bc..ebf64e85 100644
--- a/swagger-meta/src/test/java/com/networknt/swagger/SwaggerHandlerTest.java
+++ b/swagger-meta/src/test/java/com/networknt/swagger/SwaggerHandlerTest.java
@@ -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;
diff --git a/swagger-security/src/main/java/com/networknt/security/JwtVerifyHandler.java b/swagger-security/src/main/java/com/networknt/security/JwtVerifyHandler.java
index 8d213d38..92f6476a 100644
--- a/swagger-security/src/main/java/com/networknt/security/JwtVerifyHandler.java
+++ b/swagger-security/src/main/java/com/networknt/security/JwtVerifyHandler.java
@@ -18,10 +18,10 @@
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;
+import com.networknt.status.exception.ExpiredTokenException;
import com.networknt.swagger.ApiNormalisedPath;
import com.networknt.swagger.NormalisedPath;
import com.networknt.swagger.SwaggerHelper;
diff --git a/swagger-security/src/test/java/com/networknt/security/JwtVerifyHandlerTest.java b/swagger-security/src/test/java/com/networknt/security/JwtVerifyHandlerTest.java
index 494a10d6..a3aa926e 100644
--- a/swagger-security/src/test/java/com/networknt/security/JwtVerifyHandlerTest.java
+++ b/swagger-security/src/test/java/com/networknt/security/JwtVerifyHandlerTest.java
@@ -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 com.networknt.swagger.SwaggerHandler;
import io.undertow.Handlers;
import io.undertow.Undertow;
diff --git a/swagger-validator/src/main/java/com/networknt/validator/RequestValidator.java b/swagger-validator/src/main/java/com/networknt/validator/RequestValidator.java
index 436e0a21..4bf199f9 100644
--- a/swagger-validator/src/main/java/com/networknt/validator/RequestValidator.java
+++ b/swagger-validator/src/main/java/com/networknt/validator/RequestValidator.java
@@ -17,6 +17,7 @@
package com.networknt.validator;
import com.networknt.body.BodyHandler;
+import com.networknt.schema.SchemaValidatorsConfig;
import com.networknt.status.Status;
import com.networknt.swagger.NormalisedPath;
import com.networknt.swagger.SwaggerOperation;
@@ -28,7 +29,8 @@
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;
@@ -111,6 +113,8 @@ private Status validateRequestBody(Object requestBody,
}
return null;
}
+ SchemaValidatorsConfig config = new SchemaValidatorsConfig();
+ config.setTypeLoose(false);
return schemaValidator.validate(requestBody, ((BodyParameter)bodyParameter.get()).getSchema());
}
diff --git a/swagger-validator/src/main/java/com/networknt/validator/SchemaValidator.java b/swagger-validator/src/main/java/com/networknt/validator/SchemaValidator.java
index dfc9acb8..32626825 100644
--- a/swagger-validator/src/main/java/com/networknt/validator/SchemaValidator.java
+++ b/swagger-validator/src/main/java/com/networknt/validator/SchemaValidator.java
@@ -19,10 +19,10 @@
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.networknt.config.Config;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.ValidationMessage;
+import com.networknt.schema.SchemaValidatorsConfig;
import com.networknt.status.Status;
import com.networknt.utility.Util;
import io.swagger.models.Model;
@@ -79,7 +79,7 @@ public SchemaValidator(final Swagger api) {
* @return A status containing error code and description
*/
public Status validate(final Object value, final Property schema) {
- return doValidate(value, schema);
+ return doValidate(value, schema, null);
}
/**
@@ -87,14 +87,19 @@ public Status validate(final Object value, final Property schema) {
*
* @param value The value to validate
* @param schema The model 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 Model schema, SchemaValidatorsConfig config) {
+ return doValidate(value, schema, config);
+ }
+
public Status validate(final Object value, final Model schema) {
- return doValidate(value, schema);
+ return doValidate(value, schema, null);
}
- private Status doValidate(final Object value, final Object schema) {
+ private Status doValidate(final Object value, final Object schema, SchemaValidatorsConfig config) {
requireNonNull(schema, "A schema is required");
Status status = null;
@@ -109,7 +114,7 @@ private Status doValidate(final Object value, final Object schema) {
((ObjectNode)schemaObject).set(DEFINITIONS_FIELD, this.definitions);
}
- JsonSchema jsonSchema = JsonSchemaFactory.getInstance().getSchema(schemaObject);
+ JsonSchema jsonSchema = JsonSchemaFactory.getInstance().getSchema(schemaObject, config);
final JsonNode content = Json.mapper().valueToTree(value);
processingReport = jsonSchema.validate(content);
diff --git a/swagger-validator/src/test/java/com/networknt/validator/ValidatorHandlerTest.java b/swagger-validator/src/test/java/com/networknt/validator/ValidatorHandlerTest.java
index 15c2365b..91055e9b 100644
--- a/swagger-validator/src/test/java/com/networknt/validator/ValidatorHandlerTest.java
+++ b/swagger-validator/src/test/java/com/networknt/validator/ValidatorHandlerTest.java
@@ -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 com.networknt.swagger.SwaggerHandler;
import io.undertow.Handlers;
import io.undertow.Undertow;