Skip to content

Commit 6003432

Browse files
author
springdoc
committed
Added support using properties from application.yml for description on operation. Fixes #231
1 parent 7fb0192 commit 6003432

File tree

6 files changed

+46
-41
lines changed

6 files changed

+46
-41
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ public class OperationBuilder {
2929
private final RequestBodyBuilder requestBodyBuilder;
3030
private final SecurityParser securityParser;
3131
private final OpenAPIBuilder openAPIBuilder;
32+
private final PropertyResolverUtils propertyResolverUtils;
3233

3334
public OperationBuilder(AbstractParameterBuilder parameterBuilder, RequestBodyBuilder requestBodyBuilder,
34-
SecurityParser securityParser, OpenAPIBuilder openAPIBuilder) {
35+
SecurityParser securityParser, OpenAPIBuilder openAPIBuilder, PropertyResolverUtils propertyResolverUtils) {
3536
super();
3637
this.parameterBuilder = parameterBuilder;
3738
this.requestBodyBuilder = requestBodyBuilder;
3839
this.securityParser = securityParser;
3940
this.openAPIBuilder = openAPIBuilder;
41+
this.propertyResolverUtils=propertyResolverUtils;
4042
}
4143

4244
public OpenAPI parse(Components components, io.swagger.v3.oas.annotations.Operation apiOperation,
@@ -45,7 +47,7 @@ public OpenAPI parse(Components components, io.swagger.v3.oas.annotations.Operat
4547
operation.setSummary(apiOperation.summary());
4648
}
4749
if (StringUtils.isNotBlank(apiOperation.description())) {
48-
operation.setDescription(apiOperation.description());
50+
operation.setDescription(propertyResolverUtils.resolve(apiOperation.description()));
4951
}
5052
if (StringUtils.isNotBlank(apiOperation.operationId())) {
5153
operation.setOperationId(getOperationId(apiOperation.operationId(), openAPI));

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public OpenAPIBuilder openAPIBuilder(Optional<OpenAPI> openAPI, ApplicationConte
3737

3838
@Bean
3939
public OperationBuilder operationBuilder(AbstractParameterBuilder parameterBuilder, RequestBodyBuilder requestBodyBuilder,
40-
SecurityParser securityParser, OpenAPIBuilder openAPIBuilder) {
40+
SecurityParser securityParser, OpenAPIBuilder openAPIBuilder, PropertyResolverUtils propertyResolverUtils) {
4141
return new OperationBuilder(parameterBuilder, requestBodyBuilder,
42-
securityParser, openAPIBuilder);
42+
securityParser, openAPIBuilder,propertyResolverUtils);
4343
}
4444

4545
@Bean

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app15/HelloController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public class HelloController {
1313

1414
@GetMapping(value = "/persons")
15-
@Operation(responses = @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(hidden = true))))
15+
@Operation(description = "${springdoc.operation-descriptions.myOperation}", responses = @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(hidden = true))))
1616
public JSONObject persons() {
1717
return new JSONObject();
1818
}

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app15/SpringDocApp15Test.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package test.org.springdoc.api.app15;
22

3+
import org.springframework.test.context.TestPropertySource;
34
import test.org.springdoc.api.AbstractSpringDocTest;
45

6+
@TestPropertySource(properties = "springdoc.operation-descriptions.myOperation=My Desc")
57
public class SpringDocApp15Test extends AbstractSpringDocTest {
68

79

springdoc-openapi-webmvc-core/src/test/resources/results/app15.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"tags": [
1717
"hello-controller"
1818
],
19+
"description": "My Desc",
1920
"operationId": "persons",
2021
"responses": {
2122
"200": {

springdoc-openapi-webmvc-core/src/test/resources/results/app67.json

+36-36
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
}
1212
],
1313
"paths": {
14-
"/demo/operation2": {
14+
"/demo/operation4": {
1515
"get": {
1616
"tags": [
1717
"hello-controller"
1818
],
19-
"summary": "Operation 2 (expected result - 3 parameters)",
20-
"operationId": "operation2",
19+
"summary": "Operation 4 (expected result - 3 parameters)",
20+
"operationId": "operation4",
2121
"parameters": [
2222
{
2323
"name": "pageNumber",
@@ -63,6 +63,32 @@
6363
}
6464
}
6565
},
66+
"/demo/operation1": {
67+
"get": {
68+
"tags": [
69+
"hello-controller"
70+
],
71+
"summary": "Operation 1 (expected result - no parameters)",
72+
"operationId": "operation1",
73+
"responses": {
74+
"200": {
75+
"description": "default response",
76+
"content": {
77+
"*/*": {
78+
"schema": {
79+
"type": "string"
80+
}
81+
},
82+
"text/plain": {
83+
"schema": {
84+
"type": "string"
85+
}
86+
}
87+
}
88+
}
89+
}
90+
}
91+
},
6692
"/demo/operation3": {
6793
"get": {
6894
"tags": [
@@ -115,52 +141,26 @@
115141
}
116142
}
117143
},
118-
"/demo/operation1": {
119-
"get": {
120-
"tags": [
121-
"hello-controller"
122-
],
123-
"summary": "Operation 1 (expected result - no parameters)",
124-
"operationId": "operation1",
125-
"responses": {
126-
"200": {
127-
"description": "default response",
128-
"content": {
129-
"*/*": {
130-
"schema": {
131-
"type": "string"
132-
}
133-
},
134-
"text/plain": {
135-
"schema": {
136-
"type": "string"
137-
}
138-
}
139-
}
140-
}
141-
}
142-
}
143-
},
144-
"/demo/operation4": {
144+
"/demo/operation2": {
145145
"get": {
146146
"tags": [
147147
"hello-controller"
148148
],
149-
"summary": "Operation 4 (expected result - 3 parameters)",
150-
"operationId": "operation4",
149+
"summary": "Operation 2 (expected result - 3 parameters)",
150+
"operationId": "operation2",
151151
"parameters": [
152152
{
153-
"name": "pageSize",
153+
"name": "pageNumber",
154154
"in": "query",
155-
"description": "page size",
155+
"description": "page number",
156156
"schema": {
157157
"type": "integer"
158158
}
159159
},
160160
{
161-
"name": "pageNumber",
161+
"name": "pageSize",
162162
"in": "query",
163-
"description": "page number",
163+
"description": "page size",
164164
"schema": {
165165
"type": "integer"
166166
}

0 commit comments

Comments
 (0)