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

[JAXRS-spec] Added support for cookie parameters #8117

Merged
merged 1 commit into from
Dec 8, 2020
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 @@ -11,6 +11,6 @@
@ApiResponses(value = { {{#responses}}
@ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{baseType}}}.class{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}}
}){{/useSwaggerAnnotations}}
public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}) {
public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}) {
return Response.ok().entity("magic!").build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#isCookieParam}}@CookieParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{^isContainer}}{{#defaultValue}} @DefaultValue({{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{description}}"){{/description}}{{/useSwaggerAnnotations}} {{{dataType}}} {{paramName}}{{/isCookieParam}}
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,33 @@ public void testGenerateApiWithPreceedingPathParameter_issue1347() throws Except
output.deleteOnExit();
}

@Test
public void testGenerateApiWithCookieParameter_issue2908() throws Exception {
Map<String, Object> properties = new HashMap<>();
properties.put(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION, "openapi.yml");

File output = Files.createTempDirectory("test").toFile();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("jaxrs-spec")
.setAdditionalProperties(properties)
.setInputSpec("src/test/resources/3_0/issue_2908.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

final ClientOptInput clientOptInput = configurator.toClientOptInput();
DefaultGenerator generator = new DefaultGenerator(false);
List<File> files = generator.opts(clientOptInput).generate();

validateJavaSourceFiles(files);

TestUtils.ensureContainsFile(files, output, "openapi.yml");
files.stream().forEach(System.out::println);
TestUtils.ensureContainsFile(files, output, "src/gen/java/org/openapitools/api/SomethingApi.java");
TestUtils.assertFileContains(output.toPath().resolve("src/gen/java/org/openapitools/api/SomethingApi.java"), "@CookieParam");

output.deleteOnExit();
}

@Test
public void addsImportForSetArgument() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
Expand Down
20 changes: 20 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/issue_2908.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
openapi: 3.0.1
info:
title: Issue 2908 - Cookie parameters
description: "Cookie parameters for JAX-RS Spec generator"
version: 0.0.1

paths:
/something:
post:
operationId: withCookieParam
parameters:
- name: myCookieParam
in: cookie
required: true
description: cookie param
schema:
type: string
responses:
200:
description: success