From 80b75eea1b9640bdfd2cfda6c7a92aca48d361b2 Mon Sep 17 00:00:00 2001 From: gracekarina Date: Sat, 30 Dec 2017 16:22:44 -0500 Subject: [PATCH 1/2] adding not schema to spec - refs ticket #215 --- src/test/swagger/oas3.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/swagger/oas3.yaml b/src/test/swagger/oas3.yaml index c5d19dfc..987d2c2a 100644 --- a/src/test/swagger/oas3.yaml +++ b/src/test/swagger/oas3.yaml @@ -64,6 +64,16 @@ tags: description: Find out more about our store url: http://swagger.io paths: + /pets: + patch: + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/PetByType' + responses: + '200': + description: Updated /mockResponses/objectMultipleExamples: get: responses: @@ -1052,6 +1062,14 @@ externalDocs: url: http://swagger.io components: schemas: + PetByType: + type: object + properties: + pet_type: + not: + type: integer + required: + - pet_type Water: properties: clear: From 5215b684c1f430ed9678173b9004cc4dd36489d3 Mon Sep 17 00:00:00 2001 From: gracekarina Date: Sat, 30 Dec 2017 17:03:25 -0500 Subject: [PATCH 2/2] adding tests to not schema support - refs ticket #215 --- .../sample/controllers/TestController.java | 6 +++++ .../oas/test/integration/RequestTestIT.java | 24 +++++++++++++++++++ src/test/swagger/oas3.yaml | 4 +++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/swagger/oas/sample/controllers/TestController.java b/src/test/java/io/swagger/oas/sample/controllers/TestController.java index 1e5a53ac..b2608581 100644 --- a/src/test/java/io/swagger/oas/sample/controllers/TestController.java +++ b/src/test/java/io/swagger/oas/sample/controllers/TestController.java @@ -48,6 +48,12 @@ public ResponseContext inlineRequiredBody(RequestContext request, com.fasterxml. .entity("success!"); } + public ResponseContext updatePet(RequestContext request, com.fasterxml.jackson.databind.JsonNode petType) { + return new ResponseContext() + .status(200) + .entity("OK!"); + } + public ResponseContext formTest(RequestContext request, String user) { return new ResponseContext() .status(Status.OK) diff --git a/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java b/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java index aaf9f8a5..a7252747 100644 --- a/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java +++ b/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java @@ -63,6 +63,30 @@ public void verifyModelMappingFromExtensions() throws Exception { assertEquals(str, "{\"street\":\"3 street\"}"); } + @Test + public void verifyNotSupport() throws Exception { + Map body = new HashMap<>(); + body.put("pet_type","Cat"); + + String path = "/pets"; + String str = client.invokeAPI(path, "POST", new HashMap(), body, new HashMap(), null, "application/json", null, new String[0]); + assertEquals(str, "OK!"); + } + + @Test + public void verifyNotSupportByFailling() throws Exception { + Map body = new HashMap<>(); + body.put("pet_type",31); + + String path = "/pets"; + try { + client.invokeAPI(path, "POST", new HashMap(), body, new HashMap(), null, "application/json", null, new String[0]); + Assert.fail("No exception was thrown"); + } catch (ApiException e) { + Assert.assertEquals(e.getCode(), HttpURLConnection.HTTP_BAD_REQUEST); + } + } + @Test public void verifyArrayModelMapping() throws Exception { final Address first = new Address(); diff --git a/src/test/swagger/oas3.yaml b/src/test/swagger/oas3.yaml index 987d2c2a..7595e518 100644 --- a/src/test/swagger/oas3.yaml +++ b/src/test/swagger/oas3.yaml @@ -65,7 +65,9 @@ tags: url: http://swagger.io paths: /pets: - patch: + post: + x-swagger-router-controller: TestController + operationId: updatePet requestBody: content: application/json: