Skip to content

Commit

Permalink
added support for cookie parameters to jaxrs-spec generator (#8117)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfabetacain authored Dec 8, 2020
1 parent 7fae4ab commit 9e0badb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
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

0 comments on commit 9e0badb

Please sign in to comment.