From 91d56d101c7426d221d7ca541a7ecfe08343b7bb Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Sat, 4 Feb 2017 14:07:15 -0800 Subject: [PATCH] test for #393 --- .../io/swagger/parser/SwaggerParserTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerParserTest.java b/modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerParserTest.java index 9ea2d02289..3388f0d186 100644 --- a/modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerParserTest.java +++ b/modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerParserTest.java @@ -676,4 +676,76 @@ public void testCodegenPetstore() { assertEquals(formParam.getMinimum().toString(), "32.1"); } + + @Test + public void testCodegenIssue4555() throws Exception { + SwaggerParser parser = new SwaggerParser(); + String yaml = "swagger: '2.0'\n" + + "\n" + + "info:\n" + + " title: test\n" + + " version: \"0.0.1\"\n" + + "\n" + + "schemes:\n" + + " - http\n" + + "produces:\n" + + " - application/json\n" + + "\n" + + "paths:\n" + + " /contents/{id}:\n" + + " parameters:\n" + + " - name: id\n" + + " in: path\n" + + " description: test\n" + + " required: true\n" + + " type: integer\n" + + "\n" + + " get:\n" + + " description: test\n" + + " responses:\n" + + " 200:\n" + + " description: OK\n" + + " schema:\n" + + " $ref: '#/definitions/Content'\n" + + "\n" + + "definitions:\n" + + " Content:\n" + + " type: object\n" + + " title: \t\ttest"; + final SwaggerDeserializationResult result = parser.readWithInfo(yaml); + + // can't parse with tabs! + assertNull(result.getSwagger()); + } + + @Test + public void testIssue393() { + SwaggerParser parser = new SwaggerParser(); + + String yaml = + "swagger: '2.0'\n" + + "info:\n" + + " title: x\n" + + " version: 1.0.0\n" + + "paths:\n" + + " /test:\n" + + " get:\n" + + " parameters: []\n" + + " responses:\n" + + " '400':\n" + + " description: |\n" + + " The account could not be created because a credential didn't meet the complexity requirements.\n" + + " x-error-refs:\n" + + " - '$ref': '#/x-error-defs/credentialTooShort'\n" + + " - '$ref': '#/x-error-defs/credentialTooLong'\n" + + "x-error-defs:\n" + + " credentialTooShort:\n" + + " errorID: credentialTooShort"; + final SwaggerDeserializationResult result = parser.readWithInfo(yaml); + + assertNotNull(result.getSwagger()); + Swagger swagger = result.getSwagger(); + + assertNotNull(swagger.getVendorExtensions().get("x-error-defs")); + } }