Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java][microprofile] Added support for Cookie parameters #20729

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>{{/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<Void>{{/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<Void>{{/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;
Expand All @@ -91,6 +91,9 @@ public interface {{classname}} {
{{#formParams}}
private {{>formParams}};
{{/formParams}}
{{#cookieParams}}
private {{>cookieParams}};
{{/cookieParams}}

private {{operationIdCamelCase}}Request() {
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#required}} @NotNull{{/required}}{{>beanValidationCore}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#isCookieParam}}@CookieParam("{{baseName}}") {{#useBeanValidation}}{{>beanValidationCookieParams}}{{/useBeanValidation}} {{{dataType}}} {{paramName}}{{/isCookieParam}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#isCookieParam}}{{{dataType}}} {{paramName}}{{/isCookieParam}}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@

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;
Expand Down Expand Up @@ -72,4 +75,56 @@ public void testEnumUnknownDefaultCaseDeserializationNotSet_issue19674() throws
.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<File> files = new DefaultGenerator().opts(input).generate();

Map<String, File> 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<File> files = new DefaultGenerator().opts(input).generate();

Map<String, File> filesMap = files.stream()
.collect(Collectors.toMap(File::getName, Function.identity()));

validateJavaSourceFiles(files);

JavaFileAssert.assertThat(filesMap.get("DefaultApi.java"))
.assertInnerClass("GetCustomerRequest")
.assertMethod("cookieParameter");
}
}
Original file line number Diff line number Diff line change
@@ -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
Loading