Repository: springdoc/springdoc-openapi
Pull request #464 (2020-03-02 12:24:46)

add property resolver 
Issue https://github.com/springdoc/springdoc-openapi/issues/463


Patch:
diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericParameterBuilder.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericParameterBuilder.java
index 482aa22f3..a77d3324a 100644
--- a/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericParameterBuilder.java
+++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/GenericParameterBuilder.java
@@ -61,15 +61,19 @@ public class GenericParameterBuilder {
 
 	private final LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer;
 	private final IgnoredParameterAnnotations ignoredParameterAnnotations;
+	private final PropertyResolverUtils propertyResolverUtils;
 	private static final List<Class<?>> FILE_TYPES = new ArrayList<>();
 
 	static {
 		FILE_TYPES.add(MultipartFile.class);
 	}
 
-	public GenericParameterBuilder(LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer, IgnoredParameterAnnotations ignoredParameterAnnotations) {
+	public GenericParameterBuilder(LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer,
+								   IgnoredParameterAnnotations ignoredParameterAnnotations,
+								   PropertyResolverUtils propertyResolverUtils) {
 		this.localSpringDocParameterNameDiscoverer = localSpringDocParameterNameDiscoverer;
 		this.ignoredParameterAnnotations = ignoredParameterAnnotations;
+		this.propertyResolverUtils = propertyResolverUtils;
 	}
 
 	Parameter mergeParameter(List<Parameter> existingParamDoc, Parameter paramCalcul) {
@@ -132,10 +136,10 @@ public class GenericParameterBuilder {
 			Components components, JsonView jsonView) {
 		Parameter parameter = new Parameter();
 		if (StringUtils.isNotBlank(parameterDoc.description())) {
-			parameter.setDescription(parameterDoc.description());
+			parameter.setDescription(propertyResolverUtils.resolve(parameterDoc.description()));
 		}
 		if (StringUtils.isNotBlank(parameterDoc.name())) {
-			parameter.setName(parameterDoc.name());
+			parameter.setName(propertyResolverUtils.resolve(parameterDoc.name()));
 		}
 		if (StringUtils.isNotBlank(parameterDoc.in().toString())) {
 			parameter.setIn(parameterDoc.in().toString());
diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/OperationBuilder.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/OperationBuilder.java
index 04005bab2..3739f39f7 100644
--- a/springdoc-openapi-common/src/main/java/org/springdoc/core/OperationBuilder.java
+++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/OperationBuilder.java
@@ -79,7 +79,7 @@ public class OperationBuilder {
 	public OpenAPI parse(Components components, io.swagger.v3.oas.annotations.Operation apiOperation,
 			Operation operation, OpenAPI openAPI, MethodAttributes methodAttributes) {
 		if (StringUtils.isNotBlank(apiOperation.summary())) {
-			operation.setSummary(apiOperation.summary());
+			operation.setSummary(propertyResolverUtils.resolve(apiOperation.summary()));
 		}
 		if (StringUtils.isNotBlank(apiOperation.description())) {
 			operation.setDescription(propertyResolverUtils.resolve(apiOperation.description()));
diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfiguration.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfiguration.java
index 422098754..987d63a5b 100644
--- a/springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfiguration.java
+++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfiguration.java
@@ -124,8 +124,10 @@ public class SpringDocConfiguration {
 	}
 
 	@Bean
-	public GenericParameterBuilder parameterBuilder(LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer, IgnoredParameterAnnotations ignoredParameterAnnotations) {
-		return new GenericParameterBuilder(localSpringDocParameterNameDiscoverer, ignoredParameterAnnotations);
+	public GenericParameterBuilder parameterBuilder(LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer,
+													IgnoredParameterAnnotations ignoredParameterAnnotations,
+													PropertyResolverUtils propertyResolverUtils) {
+		return new GenericParameterBuilder(localSpringDocParameterNameDiscoverer, ignoredParameterAnnotations, propertyResolverUtils);
 	}
 
 	static class ConditionOnCacheOrGroupedOpenApi extends AnyNestedCondition {


Test patch:
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app95/HelloController.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app95/HelloController.java
new file mode 100644
index 000000000..21e3d4329
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app95/HelloController.java
@@ -0,0 +1,20 @@
+package test.org.springdoc.api.app95;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+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
+	@Operation(summary = "${test.app95.operation.persons.summary}",
+			description = "${test.app95.operation.persons.description}")
+	public void persons(@Parameter(description = "${test.app95.param.name.description}") String name) {
+
+	}
+
+}
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app95/SpringDocApp95Test.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app95/SpringDocApp95Test.java
new file mode 100644
index 000000000..44f1fb2c3
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app95/SpringDocApp95Test.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.app95;
+
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.test.context.ActiveProfiles;
+import test.org.springdoc.api.AbstractSpringDocTest;
+
+@ActiveProfiles("95")
+public class SpringDocApp95Test extends AbstractSpringDocTest {
+
+    @SpringBootApplication
+    static class SpringDocTestApp {}
+
+}
\ No newline at end of file
diff --git a/springdoc-openapi-webmvc-core/src/test/resources/application-95.yml b/springdoc-openapi-webmvc-core/src/test/resources/application-95.yml
new file mode 100644
index 000000000..d8d7d68e3
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/resources/application-95.yml
@@ -0,0 +1,9 @@
+test:
+  app95:
+    operation:
+      persons:
+        summary: Summary of operation persons
+        description: Description of operation persons
+    param:
+      name:
+        description: Description of parameter name
\ No newline at end of file
diff --git a/springdoc-openapi-webmvc-core/src/test/resources/results/app95.json b/springdoc-openapi-webmvc-core/src/test/resources/results/app95.json
new file mode 100644
index 000000000..575285b5b
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/resources/results/app95.json
@@ -0,0 +1,42 @@
+{
+  "openapi": "3.0.1",
+  "info": {
+    "title": "OpenAPI definition",
+    "version": "v0"
+  },
+  "servers": [
+    {
+      "url": "http://localhost",
+      "description": "Generated server url"
+    }
+  ],
+  "paths": {
+    "/persons": {
+      "get": {
+        "tags": [
+          "hello-controller"
+        ],
+        "summary": "Summary of operation persons",
+        "description": "Description of operation persons",
+        "operationId": "persons",
+        "parameters": [
+          {
+            "name": "name",
+            "in": "query",
+            "description": "Description of parameter name",
+            "required": true,
+            "schema": {
+              "type": "string"
+            }
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "default response"
+          }
+        }
+      }
+    }
+  },
+  "components": {}
+}
\ No newline at end of file