From 4417bb6b32634298cbcadd555036c4e01966ded2 Mon Sep 17 00:00:00 2001 From: Harald Walker Date: Thu, 18 May 2017 09:12:53 +0200 Subject: [PATCH 1/3] #5649 Fix FileAlreadyExistsException when downloading file using jersey2 (#5654) * #5649 Fix download file copy * Include generated pet store samples and fix indentation * Regenerate petstore sample to fix indentation --- .../main/resources/Java/libraries/jersey2/ApiClient.mustache | 3 ++- .../petstore/java/jersey2-java6/.swagger-codegen/VERSION | 1 + .../src/main/java/io/swagger/client/model/OuterComposite.java | 1 + samples/client/petstore/java/jersey2/.swagger-codegen/VERSION | 1 + .../jersey2/src/main/java/io/swagger/client/ApiClient.java | 3 ++- .../src/main/java/io/swagger/client/model/OuterComposite.java | 1 + 6 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 samples/client/petstore/java/jersey2-java6/.swagger-codegen/VERSION create mode 100644 samples/client/petstore/java/jersey2/.swagger-codegen/VERSION diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index d44d724454e..759e6708aa1 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -25,6 +25,7 @@ import java.io.InputStream; {{^supportJava6}} import java.nio.file.Files; +import java.nio.file.StandardCopyOption; {{/supportJava6}} {{#supportJava6}} import org.apache.commons.io.FileUtils; @@ -581,7 +582,7 @@ public class ApiClient { try { File file = prepareDownloadFile(response); {{^supportJava6}} - Files.copy(response.readEntity(InputStream.class), file.toPath()); + Files.copy(response.readEntity(InputStream.class), file.toPath(), StandardCopyOption.REPLACE_EXISTING); {{/supportJava6}} {{#supportJava6}} // Java6 falls back to commons.io for file copying diff --git a/samples/client/petstore/java/jersey2-java6/.swagger-codegen/VERSION b/samples/client/petstore/java/jersey2-java6/.swagger-codegen/VERSION new file mode 100644 index 00000000000..7fea99011a6 --- /dev/null +++ b/samples/client/petstore/java/jersey2-java6/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/OuterComposite.java b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/OuterComposite.java index 51d9a3c47ef..0b80c71974a 100644 --- a/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/OuterComposite.java +++ b/samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/OuterComposite.java @@ -16,6 +16,7 @@ package io.swagger.client.model; import org.apache.commons.lang3.ObjectUtils; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import java.math.BigDecimal; diff --git a/samples/client/petstore/java/jersey2/.swagger-codegen/VERSION b/samples/client/petstore/java/jersey2/.swagger-codegen/VERSION new file mode 100644 index 00000000000..7fea99011a6 --- /dev/null +++ b/samples/client/petstore/java/jersey2/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java index 2878363c980..d3e9924e8eb 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -575,7 +576,7 @@ public class ApiClient { public File downloadFileFromResponse(Response response) throws ApiException { try { File file = prepareDownloadFile(response); - Files.copy(response.readEntity(InputStream.class), file.toPath()); + Files.copy(response.readEntity(InputStream.class), file.toPath(), StandardCopyOption.REPLACE_EXISTING); return file; } catch (IOException e) { throw new ApiException(e); diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/OuterComposite.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/OuterComposite.java index 65d370c72f2..7b1786ea96d 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/OuterComposite.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/OuterComposite.java @@ -16,6 +16,7 @@ package io.swagger.client.model; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import java.math.BigDecimal; From 632a2e394987b7463aef7bfda528e9675f255efa Mon Sep 17 00:00:00 2001 From: David Biesack Date: Thu, 18 May 2017 03:16:42 -0400 Subject: [PATCH 2/3] Fix #5653 so body parameter schema link matches model anchor (#5655) * Sync with upstream/master * Fix for issue #5653 Override the toModelName(String name) [from DefaultCodegen] in StaticHtmlGenerator to return `name` unmodified so that the anchors for models and the href for body parameters match case (do not convert model names to TitleCase. * Revert "Fix for issue #5653" This reverts commit 5472aa10a3101ea5dd417bc509c5d9c5351a3d66. * Fix for issue #5653 Override the toModelName(String name) [from DefaultCodegen] in StaticHtmlGenerator to return `name` unmodified so that the anchors for models and the href for body parameters match case (do not convert model names to TitleCase. --- .../io/swagger/codegen/languages/StaticHtmlGenerator.java | 8 ++++++++ samples/html/.swagger-codegen/VERSION | 1 + 2 files changed, 9 insertions(+) create mode 100644 samples/html/.swagger-codegen/VERSION diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/StaticHtmlGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/StaticHtmlGenerator.java index a22010e51fb..6942b3b2996 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/StaticHtmlGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/StaticHtmlGenerator.java @@ -170,6 +170,14 @@ public class StaticHtmlGenerator extends DefaultCodegen implements CodegenConfig return markdownConverter.toHtml(input); } + // DefaultCodegen converts model names to UpperCamelCase + // but for static HTML, we want the names to be preserved as coded in the OpenApi + // so HTML links work + @Override + public String toModelName(final String name) { + return name; + } + public void preprocessSwagger(Swagger swagger) { Info info = swagger.getInfo(); info.setDescription(toHtml(info.getDescription())); diff --git a/samples/html/.swagger-codegen/VERSION b/samples/html/.swagger-codegen/VERSION new file mode 100644 index 00000000000..7fea99011a6 --- /dev/null +++ b/samples/html/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.2.3-SNAPSHOT \ No newline at end of file From 4479382ced52f37cc62e5245230e5d9d508bc790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20C=C3=B4t=C3=A9?= Date: Thu, 18 May 2017 04:19:48 -0400 Subject: [PATCH 3/3] [Java Play Framework] Fix conversions (#5604) * First commit of the Java Play Framework server generator. It is highly based on Spring so there might me a couple of things that don't make sense (like options or parameters) for the Play Framework. * Fix suggestions in the PR discussion + add .bat and .sh file as requested. * Updated Readme.md file * Remove unused mustache file + fix baseName vs paramName in all the mustache files. * Fix the compilation error when we have a body which is a list or map. Doesn't fix the problem with the annotation itself. * Fix the problem with the Http.MultipartFormData.FilePart * Fix the conversion of boolean type * Add samples for the fix with the boolean * Fix bugs introduced by polci related to the bean validation. * Refactor to use the "beanValidationCore". Asked by @wing328 --- .../resources/JavaPlayFramework/beanValidationCore.mustache | 1 + .../JavaPlayFramework/beanValidationPathParams.mustache | 2 +- .../JavaPlayFramework/beanValidationQueryParams.mustache | 2 +- .../main/resources/JavaPlayFramework/conversionBegin.mustache | 2 +- .../petstore/java-play-framework/.swagger-codegen/VERSION | 1 + 5 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationCore.mustache create mode 100644 samples/server/petstore/java-play-framework/.swagger-codegen/VERSION diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationCore.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationCore.mustache new file mode 100644 index 00000000000..66c52583212 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationCore.mustache @@ -0,0 +1 @@ +{{#pattern}} @Pattern(regexp="{{{pattern}}}"){{/pattern}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationPathParams.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationPathParams.mustache index 0b4d31b4bf1..051bd53c0a5 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationPathParams.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationPathParams.mustache @@ -1 +1 @@ -{{! PathParam is always required, no @NotNull necessary }}{{#pattern}} @Pattern(regexp="{{{pattern}}}"){{/pattern}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}} \ No newline at end of file +{{! PathParam is always required, no @NotNull necessary }}{{>beanValidationCore}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationQueryParams.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationQueryParams.mustache index 4bad1be6368..0f99bffde09 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationQueryParams.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/beanValidationQueryParams.mustache @@ -1 +1 @@ -{{#required}} @NotNull{{/required}}{{#pattern}} @Pattern(regexp="{{{pattern}}}"){{/pattern}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}} \ No newline at end of file +{{#required}} @NotNull {{/required}}{{>beanValidationCore}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionBegin.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionBegin.mustache index a931bc896f8..1f030198921 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionBegin.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/conversionBegin.mustache @@ -1 +1 @@ -{{#isBoolean}}Boolean.getBoolean({{/isBoolean}}{{#isInteger}}Integer.parseInt({{/isInteger}}{{#isDouble}}Double.parseDouble({{/isDouble}}{{#isLong}}Long.parseLong({{/isLong}}{{#isFloat}}Float.parseFloat({{/isFloat}}{{#isString}}(String){{/isString}} \ No newline at end of file +{{#isBoolean}}Boolean.valueOf({{/isBoolean}}{{#isInteger}}Integer.parseInt({{/isInteger}}{{#isDouble}}Double.parseDouble({{/isDouble}}{{#isLong}}Long.parseLong({{/isLong}}{{#isFloat}}Float.parseFloat({{/isFloat}}{{#isString}}(String){{/isString}} \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework/.swagger-codegen/VERSION b/samples/server/petstore/java-play-framework/.swagger-codegen/VERSION new file mode 100644 index 00000000000..7fea99011a6 --- /dev/null +++ b/samples/server/petstore/java-play-framework/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.2.3-SNAPSHOT \ No newline at end of file