Skip to content

Commit b1e5942

Browse files
authored
Merge pull request #498 from tdevilleduc/apiresponse-property-resolver
add property resolver on @ApiResponse.description
2 parents 21f66d8 + 24392a5 commit b1e5942

File tree

7 files changed

+101
-6
lines changed

7 files changed

+101
-6
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ public class GenericResponseBuilder {
6666

6767
private final SpringDocConfigProperties springDocConfigProperties;
6868

69-
GenericResponseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers, SpringDocConfigProperties springDocConfigProperties) {
69+
private final PropertyResolverUtils propertyResolverUtils;
70+
71+
GenericResponseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers,
72+
SpringDocConfigProperties springDocConfigProperties, PropertyResolverUtils propertyResolverUtils) {
7073
super();
7174
this.operationBuilder = operationBuilder;
7275
this.returnTypeParsers = returnTypeParsers;
7376
this.springDocConfigProperties = springDocConfigProperties;
77+
this.propertyResolverUtils = propertyResolverUtils;
7478
}
7579

7680
public ApiResponses build(Components components, HandlerMethod handlerMethod, Operation operation,
@@ -135,7 +139,7 @@ private Map<String, ApiResponse> computeResponse(Components components, MethodPa
135139
apiResponsesOp.addApiResponse(apiResponseAnnotations.responseCode(), apiResponse);
136140
continue;
137141
}
138-
apiResponse.setDescription(apiResponseAnnotations.description());
142+
apiResponse.setDescription(propertyResolverUtils.resolve(apiResponseAnnotations.description()));
139143
io.swagger.v3.oas.annotations.media.Content[] contentdoc = apiResponseAnnotations.content();
140144
buildContentFromDoc(components, apiResponsesOp, methodAttributes,
141145
apiResponseAnnotations, apiResponse, contentdoc);

springdoc-openapi-webflux-core/src/main/java/org/springdoc/core/SpringDocWebFluxConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public RequestBuilder requestBuilder(GenericParameterBuilder parameterBuilder, R
6464

6565
@Bean
6666
@ConditionalOnMissingBean
67-
public GenericResponseBuilder responseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers, SpringDocConfigProperties springDocConfigProperties) {
68-
return new GenericResponseBuilder(operationBuilder, returnTypeParsers, springDocConfigProperties);
67+
public GenericResponseBuilder responseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers, SpringDocConfigProperties springDocConfigProperties, PropertyResolverUtils propertyResolverUtils) {
68+
return new GenericResponseBuilder(operationBuilder, returnTypeParsers, springDocConfigProperties, propertyResolverUtils);
6969
}
7070

7171
@Bean

springdoc-openapi-webmvc-core/src/main/java/org/springdoc/core/SpringDocWebMvcConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public RequestBuilder requestBuilder(GenericParameterBuilder parameterBuilder, R
7070

7171
@Bean
7272
@ConditionalOnMissingBean
73-
public GenericResponseBuilder responseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers, SpringDocConfigProperties springDocConfigProperties) {
74-
return new GenericResponseBuilder(operationBuilder, returnTypeParsers, springDocConfigProperties);
73+
public GenericResponseBuilder responseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers, SpringDocConfigProperties springDocConfigProperties, PropertyResolverUtils propertyResolverUtils) {
74+
return new GenericResponseBuilder(operationBuilder, returnTypeParsers, springDocConfigProperties, propertyResolverUtils);
7575
}
7676

7777
@Configuration
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package test.org.springdoc.api.app99;
2+
3+
import io.swagger.v3.oas.annotations.Operation;
4+
import io.swagger.v3.oas.annotations.Parameter;
5+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
6+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
@RestController
12+
@RequestMapping("/persons")
13+
public class HelloController {
14+
15+
@GetMapping
16+
@ApiResponses({
17+
@ApiResponse(responseCode = "202", description = "${test.app99.operation.persons.response.202.description}")
18+
})
19+
public void persons() {
20+
21+
}
22+
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.app99;
20+
21+
22+
import org.springframework.boot.autoconfigure.SpringBootApplication;
23+
import org.springframework.test.context.ActiveProfiles;
24+
import test.org.springdoc.api.AbstractSpringDocTest;
25+
26+
@ActiveProfiles("99")
27+
public class SpringDocApp99Test extends AbstractSpringDocTest {
28+
29+
@SpringBootApplication
30+
static class SpringDocTestApp {}
31+
32+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
test:
2+
app99:
3+
operation:
4+
persons:
5+
response:
6+
202:
7+
description: Description of api response 202
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
"/persons": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "persons",
20+
"responses": {
21+
"202": {
22+
"description": "Description of api response 202"
23+
}
24+
}
25+
}
26+
}
27+
},
28+
"components": {}
29+
}

0 commit comments

Comments
 (0)