Skip to content

Commit 4fad109

Browse files
author
bnasslahsen
committed
Added support for extensions on @apiresponse. Fixes #368
1 parent 84b3bca commit 4fad109

File tree

6 files changed

+163
-1
lines changed

6 files changed

+163
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [UnReleased] -
8+
## Added
9+
- Added ability to disable security for one operation using @SecurityRequirements #259
10+
- Support for extensions on @ApiResponse #368
811

912
## [1.2.28] -
1013
## Changed

springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractResponseBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ private Map<String, ApiResponse> computeResponse(Components components, Method m
152152
io.swagger.v3.oas.annotations.media.Content[] contentdoc = apiResponseAnnotations.content();
153153
buildContentFromDoc(components, apiResponsesOp, methodAttributes,
154154
apiResponseAnnotations, apiResponse, contentdoc);
155+
Map<String, Object> extensions = AnnotationsUtils.getExtensions(apiResponseAnnotations.extensions());
156+
if (!CollectionUtils.isEmpty(extensions))
157+
apiResponse.extensions(extensions);
155158
AnnotationsUtils.getHeaders(apiResponseAnnotations.headers(), methodAttributes.getJsonViewAnnotation())
156159
.ifPresent(apiResponse::headers);
157160
apiResponsesOp.addApiResponse(apiResponseAnnotations.responseCode(), apiResponse);

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocAnnotationsUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ private static void addEncodingToMediaType(JsonView jsonViewAnnotation, MediaTyp
123123

124124
private static void addExtension(io.swagger.v3.oas.annotations.media.Content annotationContent,
125125
MediaType mediaType) {
126-
annotationContent.extensions();
127126
if (annotationContent.extensions().length > 0) {
128127
Map<String, Object> extensions = AnnotationsUtils.getExtensions(annotationContent.extensions());
129128
extensions.forEach(mediaType::addExtension);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app77;
20+
21+
import javax.validation.Valid;
22+
23+
import io.swagger.v3.oas.annotations.Operation;
24+
import io.swagger.v3.oas.annotations.extensions.Extension;
25+
import io.swagger.v3.oas.annotations.extensions.ExtensionProperty;
26+
import io.swagger.v3.oas.annotations.media.Content;
27+
import io.swagger.v3.oas.annotations.media.Schema;
28+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
29+
import org.hibernate.validator.constraints.NotBlank;
30+
31+
import org.springframework.web.bind.annotation.GetMapping;
32+
import org.springframework.web.bind.annotation.RestController;
33+
34+
35+
@RestController
36+
public class HelloController {
37+
38+
@ApiResponse(content = @Content(schema = @Schema(type = "string")), extensions = @Extension(properties = @ExtensionProperty(name = "x-is-file", value = "true")))
39+
@GetMapping(value = "/persons")
40+
public void persons(@Valid @NotBlank String name) {
41+
42+
}
43+
44+
45+
@Operation(responses = @ApiResponse(content = @Content(schema = @Schema(type = "string")), extensions = @Extension(properties = @ExtensionProperty(name = "x-is-file", value = "true")))) @GetMapping(value = "/persons2")
46+
public void persons2(@Valid @NotBlank String name) {
47+
48+
}
49+
50+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app77;
20+
21+
import test.org.springdoc.api.AbstractSpringDocTest;
22+
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
25+
public class SpringDocApp77Test extends AbstractSpringDocTest {
26+
27+
@SpringBootApplication
28+
static class SpringDocTestApp {}
29+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/persons2": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "persons2",
20+
"parameters": [
21+
{
22+
"name": "name",
23+
"in": "query",
24+
"required": true,
25+
"schema": {
26+
"type": "string"
27+
}
28+
}
29+
],
30+
"responses": {
31+
"default": {
32+
"description": "default response",
33+
"content": {
34+
"*/*": {
35+
"schema": {
36+
"type": "string"
37+
}
38+
}
39+
},
40+
"x-is-file": "true"
41+
}
42+
}
43+
}
44+
},
45+
"/persons": {
46+
"get": {
47+
"tags": [
48+
"hello-controller"
49+
],
50+
"operationId": "persons",
51+
"parameters": [
52+
{
53+
"name": "name",
54+
"in": "query",
55+
"required": true,
56+
"schema": {
57+
"type": "string"
58+
}
59+
}
60+
],
61+
"responses": {
62+
"default": {
63+
"description": "default response",
64+
"content": {
65+
"*/*": {
66+
"schema": {
67+
"type": "string"
68+
}
69+
}
70+
},
71+
"x-is-file": "true"
72+
}
73+
}
74+
}
75+
}
76+
},
77+
"components": {}
78+
}

0 commit comments

Comments
 (0)