Skip to content

Commit fc1a91d

Browse files
author
Caleb Marble
committed
Add Spring Boot metadata for config properties.
1 parent 8ea132e commit fc1a91d

File tree

4 files changed

+172
-32
lines changed

4 files changed

+172
-32
lines changed

springdoc-openapi-common/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<groupId>org.springframework.boot</groupId>
1313
<artifactId>spring-boot-autoconfigure</artifactId>
1414
</dependency>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-configuration-processor</artifactId>
18+
<optional>true</optional>
19+
</dependency>
1520
<dependency>
1621
<groupId>org.springframework</groupId>
1722
<artifactId>spring-web</artifactId>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package org.springdoc.config;
22

3+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
34
import org.springframework.context.annotation.Bean;
45
import org.springframework.context.annotation.ComponentScan;
56
import org.springframework.context.annotation.Configuration;
67
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
78

89
@Configuration
10+
@EnableConfigurationProperties
911
@ComponentScan(basePackages = {"org.springdoc"})
1012
public class SpringDocConfiguration {
1113

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.springdoc.core;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
@ConfigurationProperties(prefix = "springdoc")
8+
public class SpringDocConfigProperties {
9+
10+
private Boolean showActuator = false;
11+
private Webjars webjars = new Webjars();
12+
private ApiDocs apiDocs = new ApiDocs();
13+
14+
public static class Webjars {
15+
private String prefix = "/webjars";
16+
17+
public String getPrefix() {
18+
return prefix;
19+
}
20+
21+
public void setPrefix(String prefix) {
22+
this.prefix = prefix;
23+
}
24+
}
25+
26+
public static class ApiDocs {
27+
/**
28+
* Path to the generated OpenAPI documentation. For a yaml file, append ".yaml" to the path.
29+
*/
30+
private String path = "/v3/api-docs";
31+
/**
32+
* Weather to generate and serve a OpenAPI document.
33+
*/
34+
private Boolean enabled = true;
35+
36+
public String getPath() {
37+
return path;
38+
}
39+
40+
public void setPath(String path) {
41+
this.path = path;
42+
}
43+
44+
public Boolean getEnabled() {
45+
return enabled;
46+
}
47+
48+
public void setEnabled(Boolean enabled) {
49+
this.enabled = enabled;
50+
}
51+
}
52+
53+
public Boolean getShowActuator() {
54+
return showActuator;
55+
}
56+
57+
public void setShowActuator(Boolean showActuator) {
58+
this.showActuator = showActuator;
59+
}
60+
61+
public Webjars getWebjars() {
62+
return webjars;
63+
}
64+
65+
public void setWebjars(Webjars webjars) {
66+
this.webjars = webjars;
67+
}
68+
69+
public ApiDocs getApiDocs() {
70+
return apiDocs;
71+
}
72+
73+
public void setApiDocs(ApiDocs apiDocs) {
74+
this.apiDocs = apiDocs;
75+
}
76+
}

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

Lines changed: 89 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,88 @@
99
import java.util.TreeMap;
1010

1111
/**
12-
* Please refer to https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md
12+
* Please refer to the swagger
13+
* <a href="https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md">configuration.md</a>
1314
* to get the idea what each parameter does.
1415
*/
1516
@Configuration
1617
@ConfigurationProperties(prefix = "springdoc.swagger-ui")
1718
public class SwaggerUiConfigProperties {
18-
// URL to fetch external configuration document from.
19+
/**
20+
* The path for the Swagger UI pages to load. Will redirect to the springdoc.webjars.prefix property.
21+
*/
22+
private String path = "/swagger-ui.html";
23+
24+
/**
25+
* The name of a component available via the plugin system to use as the top-level layout for Swagger UI.
26+
*/
27+
private String layout;
28+
/**
29+
* URL to fetch external configuration document from.
30+
*/
1931
private String configUrl;
20-
// If set, enables filtering. The top bar will show an edit box that
21-
// could be used to filter the tagged operations that are shown.
32+
/**
33+
* If set, enables filtering. The top bar will show an edit box that
34+
* could be used to filter the tagged operations that are shown.
35+
*/
2236
private String filter;
2337

24-
// Apply a sort to the operation list of each API
38+
/**
39+
* Apply a sort to the operation list of each API
40+
*/
2541
private String operationsSorter;
26-
// Apply a sort to the tag list of each API
42+
/**
43+
* Apply a sort to the tag list of each API
44+
*/
2745
private String tagsSorter;
2846

29-
// Enables or disables deep linking for tags and operations.
47+
/**
48+
* Enables or disables deep linking for tags and operations.
49+
*
50+
* @see <a href="https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/deep-linking.md">deep-linking.md</a>
51+
*/
3052
private Boolean deepLinking;
31-
// Controls the display of operationId in operations list.
53+
/**
54+
* Controls the display of operationId in operations list.
55+
*/
3256
private Boolean displayOperationId;
33-
// The default expansion depth for models (set to -1 completely hide the models).
57+
/**
58+
* The default expansion depth for models (set to -1 completely hide the models).
59+
*/
3460
private Integer defaultModelsExpandDepth;
35-
// The default expansion depth for the model on the model-example section.
61+
/**
62+
* The default expansion depth for the model on the model-example section.
63+
*/
3664
private Integer defaultModelExpandDepth;
3765

38-
// Controls how the model is shown when the API is first rendered.
66+
/**
67+
* Controls how the model is shown when the API is first rendered.
68+
*/
3969
private String defaultModelRendering;
40-
// Controls the display of the request duration (in milliseconds) for Try-It-Out requests.
70+
/**
71+
* Controls the display of the request duration (in milliseconds) for Try-It-Out requests.
72+
*/
4173
private Boolean displayRequestDuration;
42-
// Controls the default expansion setting for the operations and tags.
74+
/**
75+
* Controls the default expansion setting for the operations and tags.
76+
*/
4377
private String docExpansion;
44-
// If set, limits the number of tagged operations displayed to at most this many.
78+
/**
79+
* If set, limits the number of tagged operations displayed to at most this many.
80+
*/
4581
private Integer maxDisplayedTags;
46-
// Controls the display of vendor extension (x-) fields and values.
82+
/**
83+
* Controls the display of vendor extension (x-) fields and values.
84+
*/
4785
private Boolean showExtensions;
48-
// Controls the display of extensions
86+
/**
87+
* Controls the display of extensions
88+
*/
4989
private Boolean showCommonExtensions;
5090

5191
public Map<String, String> getConfigParameters() {
5292
final Map<String, String> params = new TreeMap<>();
93+
put("layout", layout, params);
5394
put("configUrl", configUrl, params);
5495
put("filter", filter, params);
5596
put("deepLinking", this.deepLinking, params);
@@ -85,6 +126,22 @@ protected void put(final String name, final String value, final Map<String, Stri
85126
}
86127
}
87128

129+
public String getPath() {
130+
return path;
131+
}
132+
133+
public void setPath(String path) {
134+
this.path = path;
135+
}
136+
137+
public String getLayout() {
138+
return layout;
139+
}
140+
141+
public void setLayout(String layout) {
142+
this.layout = layout;
143+
}
144+
88145
public String getConfigUrl() {
89146
return configUrl;
90147
}
@@ -101,6 +158,22 @@ public void setFilter(String filter) {
101158
this.filter = filter;
102159
}
103160

161+
public String getOperationsSorter() {
162+
return operationsSorter;
163+
}
164+
165+
public void setOperationsSorter(String operationsSorter) {
166+
this.operationsSorter = operationsSorter;
167+
}
168+
169+
public String getTagsSorter() {
170+
return tagsSorter;
171+
}
172+
173+
public void setTagsSorter(String tagsSorter) {
174+
this.tagsSorter = tagsSorter;
175+
}
176+
104177
public Boolean getDeepLinking() {
105178
return deepLinking;
106179
}
@@ -180,20 +253,4 @@ public Boolean getShowCommonExtensions() {
180253
public void setShowCommonExtensions(Boolean showCommonExtensions) {
181254
this.showCommonExtensions = showCommonExtensions;
182255
}
183-
184-
public String getOperationsSorter() {
185-
return operationsSorter;
186-
}
187-
188-
public void setOperationsSorter(String operationsSorter) {
189-
this.operationsSorter = operationsSorter;
190-
}
191-
192-
public String getTagsSorter() {
193-
return tagsSorter;
194-
}
195-
196-
public void setTagsSorter(String tagsSorter) {
197-
this.tagsSorter = tagsSorter;
198-
}
199256
}

0 commit comments

Comments
 (0)