Repository: springdoc/springdoc-openapi
Pull request #498 (2020-03-18 11:36:34)

add property resolver on @ApiResponse.description


Patch:
diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericResponseBuilder.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericResponseBuilder.java
index 4bd665f0c..b7303d3ab 100644
--- a/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericResponseBuilder.java
+++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericResponseBuilder.java
@@ -66,11 +66,15 @@ public class GenericResponseBuilder {
 
 	private final SpringDocConfigProperties springDocConfigProperties;
 
-	GenericResponseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers, SpringDocConfigProperties springDocConfigProperties) {
+	private final PropertyResolverUtils propertyResolverUtils;
+
+	GenericResponseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers,
+						   SpringDocConfigProperties springDocConfigProperties, PropertyResolverUtils propertyResolverUtils) {
 		super();
 		this.operationBuilder = operationBuilder;
 		this.returnTypeParsers = returnTypeParsers;
 		this.springDocConfigProperties = springDocConfigProperties;
+		this.propertyResolverUtils = propertyResolverUtils;
 	}
 
 	public ApiResponses build(Components components, HandlerMethod handlerMethod, Operation operation,
@@ -135,7 +139,7 @@ public class GenericResponseBuilder {
 					apiResponsesOp.addApiResponse(apiResponseAnnotations.responseCode(), apiResponse);
 					continue;
 				}
-				apiResponse.setDescription(apiResponseAnnotations.description());
+				apiResponse.setDescription(propertyResolverUtils.resolve(apiResponseAnnotations.description()));
 				io.swagger.v3.oas.annotations.media.Content[] contentdoc = apiResponseAnnotations.content();
 				buildContentFromDoc(components, apiResponsesOp, methodAttributes,
 						apiResponseAnnotations, apiResponse, contentdoc);
diff --git a/springdoc-openapi-webflux-core/src/main/java/org/springdoc/core/SpringDocWebFluxConfiguration.java b/springdoc-openapi-webflux-core/src/main/java/org/springdoc/core/SpringDocWebFluxConfiguration.java
index 53764fc29..d01bacbd0 100644
--- a/springdoc-openapi-webflux-core/src/main/java/org/springdoc/core/SpringDocWebFluxConfiguration.java
+++ b/springdoc-openapi-webflux-core/src/main/java/org/springdoc/core/SpringDocWebFluxConfiguration.java
@@ -64,8 +64,8 @@ public class SpringDocWebFluxConfiguration {
 
 	@Bean
 	@ConditionalOnMissingBean
-	public GenericResponseBuilder responseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers, SpringDocConfigProperties springDocConfigProperties) {
-		return new GenericResponseBuilder(operationBuilder, returnTypeParsers, springDocConfigProperties);
+	public GenericResponseBuilder responseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers, SpringDocConfigProperties springDocConfigProperties, PropertyResolverUtils propertyResolverUtils) {
+		return new GenericResponseBuilder(operationBuilder, returnTypeParsers, springDocConfigProperties, propertyResolverUtils);
 	}
 
 	@Bean
diff --git a/springdoc-openapi-webmvc-core/src/main/java/org/springdoc/core/SpringDocWebMvcConfiguration.java b/springdoc-openapi-webmvc-core/src/main/java/org/springdoc/core/SpringDocWebMvcConfiguration.java
index 3246682da..ec3a5fae1 100644
--- a/springdoc-openapi-webmvc-core/src/main/java/org/springdoc/core/SpringDocWebMvcConfiguration.java
+++ b/springdoc-openapi-webmvc-core/src/main/java/org/springdoc/core/SpringDocWebMvcConfiguration.java
@@ -70,8 +70,8 @@ public class SpringDocWebMvcConfiguration {
 
 	@Bean
 	@ConditionalOnMissingBean
-	public GenericResponseBuilder responseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers, SpringDocConfigProperties springDocConfigProperties) {
-		return new GenericResponseBuilder(operationBuilder, returnTypeParsers, springDocConfigProperties);
+	public GenericResponseBuilder responseBuilder(OperationBuilder operationBuilder, List<ReturnTypeParser> returnTypeParsers, SpringDocConfigProperties springDocConfigProperties, PropertyResolverUtils propertyResolverUtils) {
+		return new GenericResponseBuilder(operationBuilder, returnTypeParsers, springDocConfigProperties, propertyResolverUtils);
 	}
 
 	@Configuration


Test patch:
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app99/HelloController.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app99/HelloController.java
new file mode 100644
index 000000000..982962e58
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app99/HelloController.java
@@ -0,0 +1,23 @@
+package test.org.springdoc.api.app99;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/persons")
+public class HelloController {
+
+	@GetMapping
+	@ApiResponses({
+			@ApiResponse(responseCode = "202", description = "${test.app99.operation.persons.response.202.description}")
+	})
+	public void persons() {
+
+	}
+
+}
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app99/SpringDocApp99Test.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app99/SpringDocApp99Test.java
new file mode 100644
index 000000000..e6277c433
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app99/SpringDocApp99Test.java
@@ -0,0 +1,32 @@
+/*
+ *
+ *  * Copyright 2019-2020 the original author or authors.
+ *  *
+ *  * Licensed under the Apache License, Version 2.0 (the "License");
+ *  * you may not use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *      https://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.
+ *
+ */
+
+package test.org.springdoc.api.app99;
+
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.test.context.ActiveProfiles;
+import test.org.springdoc.api.AbstractSpringDocTest;
+
+@ActiveProfiles("99")
+public class SpringDocApp99Test extends AbstractSpringDocTest {
+
+    @SpringBootApplication
+    static class SpringDocTestApp {}
+
+}
\ No newline at end of file
diff --git a/springdoc-openapi-webmvc-core/src/test/resources/application-99.yml b/springdoc-openapi-webmvc-core/src/test/resources/application-99.yml
new file mode 100644
index 000000000..f3a2597fc
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/resources/application-99.yml
@@ -0,0 +1,7 @@
+test:
+  app99:
+    operation:
+      persons:
+        response:
+          202:
+            description: Description of api response 202
\ No newline at end of file
diff --git a/springdoc-openapi-webmvc-core/src/test/resources/results/app99.json b/springdoc-openapi-webmvc-core/src/test/resources/results/app99.json
new file mode 100644
index 000000000..d034ca3ee
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/resources/results/app99.json
@@ -0,0 +1,29 @@
+{
+  "openapi": "3.0.1",
+  "info": {
+    "title": "OpenAPI definition",
+    "version": "v0"
+  },
+  "servers": [
+    {
+      "url": "http://localhost",
+      "description": "Generated server url"
+    }
+  ],
+  "paths": {
+    "/persons": {
+      "get": {
+        "tags": [
+          "hello-controller"
+        ],
+        "operationId": "persons",
+        "responses": {
+          "202": {
+            "description": "Description of api response 202"
+          }
+        }
+      }
+    }
+  },
+  "components": {}
+}
\ No newline at end of file