Skip to content
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
1 change: 1 addition & 0 deletions docs/generators/java-camel.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|x-content-type|Specify custom value for 'Content-Type' header for operation|OPERATION|null
|x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null
|x-field-extra-annotation|List of custom annotations to be added to property|FIELD|null
|x-operation-extra-annotation|List of custom annotations to be added to operation|OPERATION|null
|x-spring-paginated|Add org.springframework.data.domain.Pageable to controller method. Can be used to handle page & size query parameters|OPERATION|false
|x-version-param|Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false|OPERATION_PARAMETER|null
|x-pattern-message|Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable|FIELD|null
Expand Down
1 change: 1 addition & 0 deletions docs/generators/spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|x-content-type|Specify custom value for 'Content-Type' header for operation|OPERATION|null
|x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null
|x-field-extra-annotation|List of custom annotations to be added to property|FIELD|null
|x-operation-extra-annotation|List of custom annotations to be added to operation|OPERATION|null
|x-spring-paginated|Add org.springframework.data.domain.Pageable to controller method. Can be used to handle page & size query parameters|OPERATION|false
|x-version-param|Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false|OPERATION_PARAMETER|null
|x-pattern-message|Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable|FIELD|null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum VendorExtension {
X_CONTENT_TYPE("x-content-type", ExtensionLevel.OPERATION, "Specify custom value for 'Content-Type' header for operation", null),
X_CLASS_EXTRA_ANNOTATION("x-class-extra-annotation", ExtensionLevel.MODEL, "List of custom annotations to be added to model", null),
X_FIELD_EXTRA_ANNOTATION("x-field-extra-annotation", ExtensionLevel.FIELD, "List of custom annotations to be added to property", null),
X_OPERATION_EXTRA_ANNOTATION("x-operation-extra-annotation", ExtensionLevel.OPERATION, "List of custom annotations to be added to operation", null),
X_VERSION_PARAM("x-version-param", ExtensionLevel.OPERATION_PARAMETER, "Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false", null),
X_PATTERN_MESSAGE("x-pattern-message", ExtensionLevel.FIELD, "Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable", null),
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ public void setUseSwaggerUI(boolean useSwaggerUI) {
@Override
public List<VendorExtension> getSupportedVendorExtensions() {
List<VendorExtension> extensions = super.getSupportedVendorExtensions();
extensions.add(VendorExtension.X_OPERATION_EXTRA_ANNOTATION);
extensions.add(VendorExtension.X_SPRING_PAGINATED);
extensions.add(VendorExtension.X_VERSION_PARAM);
extensions.add(VendorExtension.X_PATTERN_MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ public interface {{classname}} {
{{^useResponseEntity}}
@ResponseStatus({{#springHttpStatus}}{{#responses.0}}{{{code}}}{{/responses.0}}{{/springHttpStatus}})
{{/useResponseEntity}}
{{#vendorExtensions.x-operation-extra-annotation}}
{{{.}}}
{{/vendorExtensions.x-operation-extra-annotation}}
{{#jdk8-default-interface}}default {{/jdk8-default-interface}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}{{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}}{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}(
{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}},
{{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2899,6 +2899,109 @@ public void testEnumCaseSensitive_issue8084() throws IOException {
}


@Test
public void testHasOperationExtraAnnotation_issue15822() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();

final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/issue15822.yaml");
final SpringCodegen codegen = new SpringCodegen();
codegen.setOpenAPI(openAPI);
codegen.setOutputDir(output.getAbsolutePath());

codegen.additionalProperties().put(SpringCodegen.DATE_LIBRARY, "java8-localdatetime");
codegen.additionalProperties().put(INTERFACE_ONLY, "true");
codegen.additionalProperties().put(USE_RESPONSE_ENTITY, "false");
codegen.additionalProperties().put(DELEGATE_PATTERN, "true");
codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "api_interface");
codegen.additionalProperties().put(SPRING_CONTROLLER, "true");

ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);

DefaultGenerator generator = new DefaultGenerator();

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

JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("TestApi.java"));
javaFileAssert
.assertMethod("_postToTest")
.assertMethodAnnotations()
.containsWithName("javax.annotation.security.RolesAllowed");
}

@Test
public void testHasOperationExtraAnnotation_issue12219() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();

final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/issue12219.yaml");
final SpringCodegen codegen = new SpringCodegen();
codegen.setOpenAPI(openAPI);
codegen.setOutputDir(output.getAbsolutePath());

codegen.additionalProperties().put(SpringCodegen.DATE_LIBRARY, "java8-localdatetime");
codegen.additionalProperties().put(INTERFACE_ONLY, "true");
codegen.additionalProperties().put(USE_RESPONSE_ENTITY, "false");
codegen.additionalProperties().put(DELEGATE_PATTERN, "true");
codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "api_interface");
codegen.additionalProperties().put(SPRING_CONTROLLER, "true");

ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);

DefaultGenerator generator = new DefaultGenerator();

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

JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("TestApi.java"));
javaFileAssert
.assertMethod("_postToTest")
.assertMethodAnnotations()
.containsWithName("javax.annotation.security.RolesAllowed")
.containsWithName("org.springframework.security.access.annotation.Secured")
.containsWithName("org.springframework.security.access.prepost.PreAuthorize");
}

@Test
public void testHasOperationExtraAnnotation_issue12219_array() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();

final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/issue12219_array.yaml");
final SpringCodegen codegen = new SpringCodegen();
codegen.setOpenAPI(openAPI);
codegen.setOutputDir(output.getAbsolutePath());

codegen.additionalProperties().put(SpringCodegen.DATE_LIBRARY, "java8-localdatetime");
codegen.additionalProperties().put(INTERFACE_ONLY, "true");
codegen.additionalProperties().put(USE_RESPONSE_ENTITY, "false");
codegen.additionalProperties().put(DELEGATE_PATTERN, "true");
codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "api_interface");
codegen.additionalProperties().put(SPRING_CONTROLLER, "true");

ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);

DefaultGenerator generator = new DefaultGenerator();

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

JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("TestApi.java"));
javaFileAssert
.assertMethod("_postToTest")
.assertMethodAnnotations()
.containsWithName("javax.annotation.security.RolesAllowed")
.containsWithName("org.springframework.security.access.annotation.Secured")
.containsWithName("org.springframework.security.access.prepost.PreAuthorize");
}


@Test
public void multiLineOperationDescription() throws IOException {
Expand Down
53 changes: 53 additions & 0 deletions modules/openapi-generator/src/test/resources/2_0/issue12219.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
swagger: '2.0'
info:
description: 'blah'
version: 1.0.0
title: sample spec
host: fake.site.com
tags:
- name: Test
schemes:
- https
paths:
/test:
post:
summary: Post to test
description: ''
operationId: postToTest
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: Obj to test
schema:
$ref: '#/definitions/ObjTest'
responses:
'201':
description: successful operation
schema:
$ref: '#/definitions/ObjTest'
x-operation-extra-annotation: '@javax.annotation.security.RolesAllowed({"ROLE_TEST"}) @org.springframework.security.access.annotation.Secured({"ROLE_TEST"}) @org.springframework.security.access.prepost.PreAuthorize("hasRole(''ROLE_TEST'') and hasRole(''ROLE_TEST_TWO'')")'
Comment thread
rodrigoma3 marked this conversation as resolved.
definitions:
ObjTest:
description: A model to return
type: object
properties:
field1:
type: integer
format: int64
field2:
type: string
pattern: "\\w"
x-pattern-message: "Only letters, numbers and underscore"
field3:
type: string
pattern: "\\w"
EnumTest:
title: An enum to test
type: string
enum:
- ONE
- Two
- three
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
swagger: '2.0'
info:
description: 'blah'
version: 1.0.0
title: sample spec
host: fake.site.com
tags:
- name: Test
schemes:
- https
paths:
/test:
post:
summary: Post to test
description: ''
operationId: postToTest
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: Obj to test
schema:
$ref: '#/definitions/ObjTest'
responses:
'201':
description: successful operation
schema:
$ref: '#/definitions/ObjTest'
x-operation-extra-annotation:
- '@javax.annotation.security.RolesAllowed({"ROLE_TEST"})'
- '@org.springframework.security.access.annotation.Secured({"ROLE_TEST"})'
- '@org.springframework.security.access.prepost.PreAuthorize("hasRole(''ROLE_TEST'') and hasRole(''ROLE_TEST_TWO'')")'
definitions:
ObjTest:
description: A model to return
type: object
properties:
field1:
type: integer
format: int64
field2:
type: string
pattern: "\\w"
x-pattern-message: "Only letters, numbers and underscore"
field3:
type: string
pattern: "\\w"
EnumTest:
title: An enum to test
type: string
enum:
- ONE
- Two
- three
53 changes: 53 additions & 0 deletions modules/openapi-generator/src/test/resources/2_0/issue15822.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
swagger: '2.0'
info:
description: 'blah'
version: 1.0.0
title: sample spec
host: fake.site.com
tags:
- name: Test
schemes:
- https
paths:
/test:
post:
summary: Post to test
description: ''
operationId: postToTest
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: Obj to test
schema:
$ref: '#/definitions/ObjTest'
responses:
'201':
description: successful operation
schema:
$ref: '#/definitions/ObjTest'
x-operation-extra-annotation: '@javax.annotation.security.RolesAllowed({"ROLE_TEST"})'
definitions:
ObjTest:
description: A model to return
type: object
properties:
field1:
type: integer
format: int64
field2:
type: string
pattern: "\\w"
x-pattern-message: "Only letters, numbers and underscore"
field3:
type: string
pattern: "\\w"
EnumTest:
title: An enum to test
type: string
enum:
- ONE
- Two
- three
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ default Mono<Client> call123testSpecialTags(Mono<Client> client,
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"client\" : \"client\" }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString);
result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,35 @@ default Mono<Void> testQueryParameterCollectionFormat(
}


/**
* GET /fake/response-with-example
* This endpoint defines an example value for its response schema.
*
* @return Success (status code 200)
*/
@ApiOperation(
tags = { "fake" },
value = "",
nickname = "testWithResultExample",
notes = "This endpoint defines an example value for its response schema.",
response = Integer.class
)
@ApiResponses({
@ApiResponse(code = 200, message = "Success", response = Integer.class)
})
@RequestMapping(
method = RequestMethod.GET,
value = "/fake/response-with-example",
produces = { "application/json" }
)
@ResponseStatus(HttpStatus.OK)
default Mono<Integer> testWithResultExample(
@ApiIgnore final ServerWebExchange exchange
) {
return getDelegate().testWithResultExample(exchange);
}


/**
* POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required)
*
Expand Down
Loading