mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
Added support for Cookie parameters (#20729)
Co-authored-by: Michael Munch <mmu@bankdata.dk>
This commit is contained in:
parent
c529b16600
commit
57b1c91d17
@ -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;
|
||||
@ -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;
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
{{#required}} @NotNull{{/required}}{{>beanValidationCore}}
|
@ -0,0 +1 @@
|
||||
{{#isCookieParam}}@CookieParam("{{baseName}}") {{#useBeanValidation}}{{>beanValidationCookieParams}}{{/useBeanValidation}} {{{dataType}}} {{paramName}}{{/isCookieParam}}
|
@ -0,0 +1 @@
|
||||
{{#isCookieParam}}{{{dataType}}} {{paramName}}{{/isCookieParam}}
|
@ -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<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");
|
||||
}
|
||||
}
|
@ -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…
x
Reference in New Issue
Block a user