From 9362c6f141571a3139b0b52a5fbc0f8d0a75b8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20C=C3=B4t=C3=A9?= Date: Mon, 9 Oct 2017 10:51:32 -0400 Subject: [PATCH] Fix for regression in issue: https://github.com/swagger-api/swagger-codegen/issues/6472 (#6480) --- .../languages/AbstractJavaCodegen.java | 22 +++++++++++++++++-- .../public/swagger.json | 4 ++-- .../public/swagger.json | 4 ++-- .../public/swagger.json | 4 ++-- .../public/swagger.json | 4 ++-- .../public/swagger.json | 4 ++-- .../java-play-framework/public/swagger.json | 4 ++-- 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java index e9b6394be007..7c0dd01be583 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java @@ -656,7 +656,16 @@ public String toDefaultValue(Property p) { return null; } - return String.format(pattern, getTypeDeclaration(ap.getItems())); + String typeDeclaration = getTypeDeclaration(ap.getItems()); + Object java8obj = additionalProperties.get("java8"); + if (java8obj != null) { + Boolean java8 = Boolean.valueOf(java8obj.toString()); + if (java8 != null && java8) { + typeDeclaration = ""; + } + } + + return String.format(pattern, typeDeclaration); } else if (p instanceof MapProperty) { final MapProperty ap = (MapProperty) p; final String pattern; @@ -669,7 +678,16 @@ public String toDefaultValue(Property p) { return null; } - return String.format(pattern, String.format("String, %s", getTypeDeclaration(ap.getAdditionalProperties()))); + String typeDeclaration = String.format("String, %s", getTypeDeclaration(ap.getAdditionalProperties())); + Object java8obj = additionalProperties.get("java8"); + if (java8obj != null) { + Boolean java8 = Boolean.valueOf(java8obj.toString()); + if (java8 != null && java8) { + typeDeclaration = ""; + } + } + + return String.format(pattern, typeDeclaration); } else if (p instanceof IntegerProperty) { IntegerProperty dp = (IntegerProperty) p; if (dp.getDefault() != null) { diff --git a/samples/server/petstore/java-play-framework-controller-only/public/swagger.json b/samples/server/petstore/java-play-framework-controller-only/public/swagger.json index 1c7b9a12eba6..bf0a7a265454 100644 --- a/samples/server/petstore/java-play-framework-controller-only/public/swagger.json +++ b/samples/server/petstore/java-play-framework-controller-only/public/swagger.json @@ -112,8 +112,8 @@ "type" : "array", "items" : { "type" : "string", - "enum" : [ "available", "pending", "sold" ], - "default" : "available" + "default" : "available", + "enum" : [ "available", "pending", "sold" ] }, "collectionFormat" : "csv" } ], diff --git a/samples/server/petstore/java-play-framework-no-bean-validation/public/swagger.json b/samples/server/petstore/java-play-framework-no-bean-validation/public/swagger.json index 1c7b9a12eba6..bf0a7a265454 100644 --- a/samples/server/petstore/java-play-framework-no-bean-validation/public/swagger.json +++ b/samples/server/petstore/java-play-framework-no-bean-validation/public/swagger.json @@ -112,8 +112,8 @@ "type" : "array", "items" : { "type" : "string", - "enum" : [ "available", "pending", "sold" ], - "default" : "available" + "default" : "available", + "enum" : [ "available", "pending", "sold" ] }, "collectionFormat" : "csv" } ], diff --git a/samples/server/petstore/java-play-framework-no-exception-handling/public/swagger.json b/samples/server/petstore/java-play-framework-no-exception-handling/public/swagger.json index 1c7b9a12eba6..bf0a7a265454 100644 --- a/samples/server/petstore/java-play-framework-no-exception-handling/public/swagger.json +++ b/samples/server/petstore/java-play-framework-no-exception-handling/public/swagger.json @@ -112,8 +112,8 @@ "type" : "array", "items" : { "type" : "string", - "enum" : [ "available", "pending", "sold" ], - "default" : "available" + "default" : "available", + "enum" : [ "available", "pending", "sold" ] }, "collectionFormat" : "csv" } ], diff --git a/samples/server/petstore/java-play-framework-no-interface/public/swagger.json b/samples/server/petstore/java-play-framework-no-interface/public/swagger.json index 1c7b9a12eba6..bf0a7a265454 100644 --- a/samples/server/petstore/java-play-framework-no-interface/public/swagger.json +++ b/samples/server/petstore/java-play-framework-no-interface/public/swagger.json @@ -112,8 +112,8 @@ "type" : "array", "items" : { "type" : "string", - "enum" : [ "available", "pending", "sold" ], - "default" : "available" + "default" : "available", + "enum" : [ "available", "pending", "sold" ] }, "collectionFormat" : "csv" } ], diff --git a/samples/server/petstore/java-play-framework-no-wrap-calls/public/swagger.json b/samples/server/petstore/java-play-framework-no-wrap-calls/public/swagger.json index 1c7b9a12eba6..bf0a7a265454 100644 --- a/samples/server/petstore/java-play-framework-no-wrap-calls/public/swagger.json +++ b/samples/server/petstore/java-play-framework-no-wrap-calls/public/swagger.json @@ -112,8 +112,8 @@ "type" : "array", "items" : { "type" : "string", - "enum" : [ "available", "pending", "sold" ], - "default" : "available" + "default" : "available", + "enum" : [ "available", "pending", "sold" ] }, "collectionFormat" : "csv" } ], diff --git a/samples/server/petstore/java-play-framework/public/swagger.json b/samples/server/petstore/java-play-framework/public/swagger.json index 1c7b9a12eba6..bf0a7a265454 100644 --- a/samples/server/petstore/java-play-framework/public/swagger.json +++ b/samples/server/petstore/java-play-framework/public/swagger.json @@ -112,8 +112,8 @@ "type" : "array", "items" : { "type" : "string", - "enum" : [ "available", "pending", "sold" ], - "default" : "available" + "default" : "available", + "enum" : [ "available", "pending", "sold" ] }, "collectionFormat" : "csv" } ],