36
36
import java .util .Map ;
37
37
import java .util .function .Consumer ;
38
38
39
+ import static org .springdoc .core .utils .Constants .SPRINGDOC_SPEC_PROPERTIES_PREFIX ;
40
+
39
41
/**
40
42
* Allows externalizing strings in generated openapi schema via properties that follow
41
43
* conventional naming similar or identical to <a href="https://swagger.io/docs/specification/basic-structure/">openapi schema</a>
42
44
* <p>
43
45
* To set value of a string in schema, define an application property that matches the target node
44
- * with springdoc.specification-strings prefix.
46
+ * with springdoc.spec-properties prefix.
45
47
* <p>
46
48
* Sample supported properties for api-info customization:
47
49
* <ul>
48
- * <li>springdoc.specification-strings .info.title - to set title of api-info</li>
49
- * <li>springdoc.specification-strings .info.description - to set description of api-info</li>
50
- * <li>springdoc.specification-strings .info.version - to set version of api-info</li>
51
- * <li>springdoc.specification-strings .info.termsOfService - to set terms of service of api-info</li>
50
+ * <li>springdoc.spec-properties .info.title - to set title of api-info</li>
51
+ * <li>springdoc.spec-properties .info.description - to set description of api-info</li>
52
+ * <li>springdoc.spec-properties .info.version - to set version of api-info</li>
53
+ * <li>springdoc.spec-properties .info.termsOfService - to set terms of service of api-info</li>
52
54
* </ul>
53
55
* <p>
54
56
* Sample supported properties for components customization:
55
57
* <ul>
56
- * <li>springdoc.specification-strings .components.User.description - to set description of User model</li>
57
- * <li>springdoc.specification-strings .components.User.properties.name.description - to set description of 'name' property</li>
58
- * <li>springdoc.specification-strings .components.User.properties.name.example - to set example of 'name' property</li>
58
+ * <li>springdoc.spec-properties .components.User.description - to set description of User model</li>
59
+ * <li>springdoc.spec-properties .components.User.properties.name.description - to set description of 'name' property</li>
60
+ * <li>springdoc.spec-properties .components.User.properties.name.example - to set example of 'name' property</li>
59
61
* </ul>
60
62
* <p>
61
63
* Sample supported properties for paths/operationIds customization:
62
64
* <ul>
63
- * <li>springdoc.specification-strings .paths.{operationId}.description - to set description of {operationId}</li>
64
- * <li>springdoc.specification-strings .paths.{operationId}.summary - to set summary of {operationId}</li>
65
+ * <li>springdoc.spec-properties .paths.{operationId}.description - to set description of {operationId}</li>
66
+ * <li>springdoc.spec-properties .paths.{operationId}.summary - to set summary of {operationId}</li>
65
67
* </ul>
66
68
* <p>
67
69
* Support for groped openapi customization is similar to the above, but with a group name prefix.
68
70
* E.g.
69
71
* <ul>
70
- * <li>springdoc.specification-strings .{group-name}.info.title - to set title of api-info</li>
71
- * <li>springdoc.specification-strings .{group-name}.components.User.description - to set description of User model</li>
72
- * <li>springdoc.specification-strings .{group-name}.paths.{operationId}.description - to set description of {operationId}</li>
72
+ * <li>springdoc.spec-properties .{group-name}.info.title - to set title of api-info</li>
73
+ * <li>springdoc.spec-properties .{group-name}.components.User.description - to set description of User model</li>
74
+ * <li>springdoc.spec-properties .{group-name}.paths.{operationId}.description - to set description of {operationId}</li>
73
75
* </ul>
74
76
*
75
77
* @author Anton Tkachenko [email protected]
78
+ * @author bnasslahsen
76
79
*/
77
- public class SpecificationStringPropertiesCustomizer implements GlobalOpenApiCustomizer {
78
-
79
- private static final String SPECIFICATION_STRINGS_PREFIX = "springdoc.specification-strings." ;
80
-
81
- private final PropertyResolver propertyResolver ;
82
- private final String propertyPrefix ;
83
-
84
- public SpecificationStringPropertiesCustomizer (PropertyResolver resolverUtils ) {
80
+ public class SpecPropertiesCustomizer implements GlobalOpenApiCustomizer {
81
+
82
+ /**
83
+ * The Property resolver.
84
+ */
85
+ private final PropertyResolver propertyResolver ;
86
+
87
+ /**
88
+ * The Property prefix.
89
+ */
90
+ private final String propertyPrefix ;
91
+
92
+ /**
93
+ * Instantiates a new Spec properties customizer.
94
+ *
95
+ * @param resolverUtils the resolver utils
96
+ */
97
+ public SpecPropertiesCustomizer (PropertyResolver resolverUtils ) {
85
98
this .propertyResolver = resolverUtils ;
86
- this .propertyPrefix = SPECIFICATION_STRINGS_PREFIX ;
99
+ this .propertyPrefix = SPRINGDOC_SPEC_PROPERTIES_PREFIX ;
87
100
}
88
101
89
- public SpecificationStringPropertiesCustomizer (PropertyResolver propertyResolver , String groupName ) {
102
+ /**
103
+ * Instantiates a new Spec properties customizer.
104
+ *
105
+ * @param propertyResolver the property resolver
106
+ * @param groupName the group name
107
+ */
108
+ public SpecPropertiesCustomizer (PropertyResolver propertyResolver , String groupName ) {
90
109
this .propertyResolver = propertyResolver ;
91
- this .propertyPrefix = SPECIFICATION_STRINGS_PREFIX + groupName + "." ;
110
+ this .propertyPrefix = SPRINGDOC_SPEC_PROPERTIES_PREFIX + groupName + "." ;
92
111
}
93
112
94
113
@ Override
@@ -98,7 +117,12 @@ public void customise(OpenAPI openApi) {
98
117
setPathsProperties (openApi );
99
118
}
100
119
101
- private void setOperationInfoProperties (OpenAPI openApi ) {
120
+ /**
121
+ * Sets operation info properties.
122
+ *
123
+ * @param openApi the open api
124
+ */
125
+ private void setOperationInfoProperties (OpenAPI openApi ) {
102
126
if (openApi .getInfo () == null ) {
103
127
openApi .setInfo (new Info ());
104
128
}
@@ -109,7 +133,12 @@ private void setOperationInfoProperties(OpenAPI openApi) {
109
133
resolveString (info ::setTermsOfService , "info.termsOfService" );
110
134
}
111
135
112
- private void setPathsProperties (OpenAPI openApi ) {
136
+ /**
137
+ * Sets paths properties.
138
+ *
139
+ * @param openApi the open api
140
+ */
141
+ private void setPathsProperties (OpenAPI openApi ) {
113
142
Paths paths = openApi .getPaths ();
114
143
if (CollectionUtils .isEmpty (paths .values ())) {
115
144
return ;
@@ -126,7 +155,12 @@ private void setPathsProperties(OpenAPI openApi) {
126
155
}
127
156
}
128
157
129
- private void setComponentsProperties (OpenAPI openApi ) {
158
+ /**
159
+ * Sets components properties.
160
+ *
161
+ * @param openApi the open api
162
+ */
163
+ private void setComponentsProperties (OpenAPI openApi ) {
130
164
Components components = openApi .getComponents ();
131
165
if (components == null || CollectionUtils .isEmpty (components .getSchemas ())) {
132
166
return ;
@@ -152,7 +186,13 @@ private void setComponentsProperties(OpenAPI openApi) {
152
186
}
153
187
}
154
188
155
- private void resolveString (
189
+ /**
190
+ * Resolve string.
191
+ *
192
+ * @param setter the setter
193
+ * @param node the node
194
+ */
195
+ private void resolveString (
156
196
Consumer <String > setter , String node
157
197
) {
158
198
String nodeWithPrefix = propertyPrefix + node ;
0 commit comments