diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/api.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/api.mustache index 3d2864d3e7b..0b0a7c4badd 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/api.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/api.mustache @@ -72,7 +72,7 @@ public interface {{classname}} { @Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }) {{/hasProduces}} {{^singleRequestParameter}} - {{^vendorExtensions.x-java-is-response-void}}{{#microprofileServer}}{{> server_operation}}{{/microprofileServer}}{{^microprofileServer}}{{> client_operation}}{{/microprofileServer}}{{/vendorExtensions.x-java-is-response-void}}{{#vendorExtensions.x-java-is-response-void}}{{#microprofileMutiny}}Uni{{/microprofileMutiny}}{{^microprofileMutiny}}void{{/microprofileMutiny}}{{/vendorExtensions.x-java-is-response-void}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}) throws ApiException, ProcessingException; + {{^vendorExtensions.x-java-is-response-void}}{{#microprofileServer}}{{> server_operation}}{{/microprofileServer}}{{^microprofileServer}}{{> client_operation}}{{/microprofileServer}}{{/vendorExtensions.x-java-is-response-void}}{{#vendorExtensions.x-java-is-response-void}}{{#microprofileMutiny}}Uni{{/microprofileMutiny}}{{^microprofileMutiny}}void{{/microprofileMutiny}}{{/vendorExtensions.x-java-is-response-void}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}}, {{/-last}}{{/allParams}}) throws ApiException, ProcessingException; {{/singleRequestParameter}} {{#singleRequestParameter}} {{^vendorExtensions.x-java-is-response-void}}{{#microprofileMutiny}}Uni<{{{returnType}}}>{{/microprofileMutiny}}{{^microprofileMutiny}}{{{returnType}}}{{/microprofileMutiny}}{{/vendorExtensions.x-java-is-response-void}}{{#vendorExtensions.x-java-is-response-void}}{{#microprofileMutiny}}Uni{{/microprofileMutiny}}{{^microprofileMutiny}}void{{/microprofileMutiny}}{{/vendorExtensions.x-java-is-response-void}} {{nickname}}({{#hasNonBodyParams}}@BeanParam {{operationIdCamelCase}}Request request{{/hasNonBodyParams}}{{#bodyParams}}{{#hasNonBodyParams}}, {{/hasNonBodyParams}}{{>bodyParams}}{{/bodyParams}}) throws ApiException, ProcessingException; @@ -91,6 +91,9 @@ public interface {{classname}} { {{#formParams}} private {{>formParams}}; {{/formParams}} + {{#cookieParams}} + private {{>cookieParams}}; + {{/cookieParams}} private {{operationIdCamelCase}}Request() { } @@ -106,7 +109,7 @@ public interface {{classname}} { * @param {{paramName}}{{>formParamsNameSuffix}} {{description}} ({{^required}}optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}{{/isContainer}}{{/required}}{{#required}}required{{/required}}) * @return {{operationIdCamelCase}}Request */ - public {{operationIdCamelCase}}Request {{paramName}}{{>formParamsNameSuffix}}({{>queryParamsImpl}}{{>pathParamsImpl}}{{>headerParamsImpl}}{{>formParamsImpl}}) { + public {{operationIdCamelCase}}Request {{paramName}}{{>formParamsNameSuffix}}({{>queryParamsImpl}}{{>pathParamsImpl}}{{>headerParamsImpl}}{{>formParamsImpl}}{{>cookieParamsImpl}}) { this.{{paramName}}{{>formParamsNameSuffix}} = {{paramName}}{{>formParamsNameSuffix}}; return this; } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/beanValidationCookieParams.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/beanValidationCookieParams.mustache new file mode 100644 index 00000000000..c4ff01d7e55 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/beanValidationCookieParams.mustache @@ -0,0 +1 @@ +{{#required}} @NotNull{{/required}}{{>beanValidationCore}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/cookieParams.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/cookieParams.mustache new file mode 100644 index 00000000000..4cca907c6b4 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/cookieParams.mustache @@ -0,0 +1 @@ +{{#isCookieParam}}@CookieParam("{{baseName}}") {{#useBeanValidation}}{{>beanValidationCookieParams}}{{/useBeanValidation}} {{{dataType}}} {{paramName}}{{/isCookieParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/cookieParamsImpl.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/cookieParamsImpl.mustache new file mode 100644 index 00000000000..70871f0f8cb --- /dev/null +++ b/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/cookieParamsImpl.mustache @@ -0,0 +1 @@ +{{#isCookieParam}}{{{dataType}}} {{paramName}}{{/isCookieParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/microprofile/JavaMicroprofileServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/microprofile/JavaMicroprofileServerCodegenTest.java index 41ae57b52bb..a90546f7cdb 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/microprofile/JavaMicroprofileServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/microprofile/JavaMicroprofileServerCodegenTest.java @@ -13,10 +13,13 @@ import org.testng.annotations.Test; import java.io.File; import java.nio.file.Files; +import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; +import static org.openapitools.codegen.TestUtils.validateJavaSourceFiles; + public class JavaMicroprofileServerCodegenTest { protected JavaMicroprofileServerCodegen codegen; @@ -72,4 +75,56 @@ public class JavaMicroprofileServerCodegenTest { .assertMethod("fromValue").bodyContainsLines("throw new IllegalArgumentException(\"Unexpected value '\" + text + \"'\");"); } + + @Test + public void testMicroprofileCanHandleCookieParams() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/bugs/microprofile_cookie.yaml", null, new ParseOptions()).getOpenAPI(); + + codegen.setOutputDir(output.getAbsolutePath()); + + ClientOptInput input = new ClientOptInput() + .openAPI(openAPI) + .config(codegen); + + List files = new DefaultGenerator().opts(input).generate(); + + Map filesMap = files.stream() + .collect(Collectors.toMap(File::getName, Function.identity())); + + validateJavaSourceFiles(files); + + JavaFileAssert.assertThat(filesMap.get("DefaultApi.java")) + .assertMethod("getCustomer").assertParameter("cookieParameter"); + } + + @Test + public void testMicroprofileCanHandleCookieParamsSingleRequest() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/bugs/microprofile_cookie.yaml", null, new ParseOptions()).getOpenAPI(); + + codegen.setOutputDir(output.getAbsolutePath()); + codegen.additionalProperties().put(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER, "true"); + + ClientOptInput input = new ClientOptInput() + .openAPI(openAPI) + .config(codegen); + + List files = new DefaultGenerator().opts(input).generate(); + + Map filesMap = files.stream() + .collect(Collectors.toMap(File::getName, Function.identity())); + + validateJavaSourceFiles(files); + + JavaFileAssert.assertThat(filesMap.get("DefaultApi.java")) + .assertInnerClass("GetCustomerRequest") + .assertMethod("cookieParameter"); + } } \ No newline at end of file diff --git a/modules/openapi-generator/src/test/resources/bugs/microprofile_cookie.yaml b/modules/openapi-generator/src/test/resources/bugs/microprofile_cookie.yaml new file mode 100644 index 00000000000..9bebfb8991d --- /dev/null +++ b/modules/openapi-generator/src/test/resources/bugs/microprofile_cookie.yaml @@ -0,0 +1,21 @@ +openapi: "3.0.0" +info: + version: 2.0.0 + title: test +paths: + /pets: + get: + summary: bla + operationId: getCustomer + parameters: + - name: first + in: header + schema: + type: string + - name: cookieParameter + in: cookie + schema: + type: string + responses: + '200': + description: OK \ No newline at end of file