84
84
*/
85
85
public class SpecPropertiesCustomizer implements GlobalOpenApiCustomizer {
86
86
87
+ /**
88
+ * The constant DESCRIPTION.
89
+ */
90
+ private static final String DESCRIPTION = ".description" ;
91
+
87
92
/**
88
93
* The Property resolver.
89
94
*/
@@ -100,9 +105,9 @@ public class SpecPropertiesCustomizer implements GlobalOpenApiCustomizer {
100
105
* @param resolverUtils the resolver utils
101
106
*/
102
107
public SpecPropertiesCustomizer (PropertyResolver resolverUtils ) {
103
- this .propertyResolver = resolverUtils ;
104
- this .propertyPrefix = SPRINGDOC_SPEC_PROPERTIES_PREFIX ;
105
- }
108
+ this .propertyResolver = resolverUtils ;
109
+ this .propertyPrefix = SPRINGDOC_SPEC_PROPERTIES_PREFIX ;
110
+ }
106
111
107
112
/**
108
113
* Instantiates a new Spec properties customizer.
@@ -111,85 +116,85 @@ public SpecPropertiesCustomizer(PropertyResolver resolverUtils) {
111
116
* @param groupName the group name
112
117
*/
113
118
public SpecPropertiesCustomizer (PropertyResolver propertyResolver , String groupName ) {
114
- this .propertyResolver = propertyResolver ;
115
- this .propertyPrefix = SPRINGDOC_SPEC_PROPERTIES_PREFIX + groupName + "." ;
116
- }
119
+ this .propertyResolver = propertyResolver ;
120
+ this .propertyPrefix = SPRINGDOC_SPEC_PROPERTIES_PREFIX + groupName + "." ;
121
+ }
117
122
118
- @ Override
119
- public void customise (OpenAPI openApi ) {
120
- setOperationInfoProperties (openApi );
121
- setComponentsProperties (openApi );
122
- setPathsProperties (openApi );
123
- }
123
+ @ Override
124
+ public void customise (OpenAPI openApi ) {
125
+ setOperationInfoProperties (openApi );
126
+ setComponentsProperties (openApi );
127
+ setPathsProperties (openApi );
128
+ }
124
129
125
130
/**
126
131
* Sets operation info properties.
127
132
*
128
133
* @param openApi the open api
129
134
*/
130
135
private void setOperationInfoProperties (OpenAPI openApi ) {
131
- if (openApi .getInfo () == null ) {
132
- openApi .setInfo (new Info ());
133
- }
134
- Info info = openApi .getInfo ();
135
- resolveString (info ::setTitle , "info.title" );
136
- resolveString (info ::setDescription , "info.description" );
137
- resolveString (info ::setVersion , "info.version" );
138
- resolveString (info ::setTermsOfService , "info.termsOfService" );
139
- }
136
+ if (openApi .getInfo () == null ) {
137
+ openApi .setInfo (new Info ());
138
+ }
139
+ Info info = openApi .getInfo ();
140
+ resolveString (info ::setTitle , "info.title" );
141
+ resolveString (info ::setDescription , "info.description" );
142
+ resolveString (info ::setVersion , "info.version" );
143
+ resolveString (info ::setTermsOfService , "info.termsOfService" );
144
+ }
140
145
141
146
/**
142
147
* Sets paths properties.
143
148
*
144
149
* @param openApi the open api
145
150
*/
146
151
private void setPathsProperties (OpenAPI openApi ) {
147
- Paths paths = openApi .getPaths ();
148
- if (CollectionUtils .isEmpty (paths .values ())) {
149
- return ;
150
- }
151
- for (PathItem pathItem : paths .values ()) {
152
- List <Operation > operations = pathItem .readOperations ();
153
- for (Operation operation : operations ) {
154
- String operationId = operation .getOperationId ();
155
- String operationNode = MessageFormat .format ("paths.{0}" , operationId );
156
- resolveString (operation ::setDescription , operationNode + ".description" );
157
-
158
- resolveString (operation ::setSummary , operationNode + ".summary" );
159
- }
160
- }
161
- }
152
+ Paths paths = openApi .getPaths ();
153
+ if (CollectionUtils .isEmpty (paths .values ())) {
154
+ return ;
155
+ }
156
+ for (PathItem pathItem : paths .values ()) {
157
+ List <Operation > operations = pathItem .readOperations ();
158
+ for (Operation operation : operations ) {
159
+ String operationId = operation .getOperationId ();
160
+ String operationNode = MessageFormat .format ("paths.{0}" , operationId );
161
+ resolveString (operation ::setDescription , operationNode + DESCRIPTION );
162
+
163
+ resolveString (operation ::setSummary , operationNode + ".summary" );
164
+ }
165
+ }
166
+ }
162
167
163
168
/**
164
169
* Sets components properties.
165
170
*
166
171
* @param openApi the open api
167
172
*/
168
173
private void setComponentsProperties (OpenAPI openApi ) {
169
- Components components = openApi .getComponents ();
170
- if (components == null || CollectionUtils .isEmpty (components .getSchemas ())) {
171
- return ;
172
- }
173
-
174
- for (Schema componentSchema : components .getSchemas ().values ()) {
175
- // set component description
176
- String schemaPropertyPrefix = MessageFormat .format ("components.schemas.{0}" , componentSchema .getName ());
177
- resolveString (componentSchema ::setDescription , schemaPropertyPrefix + ".description" );
178
- Map <String , Schema > properties = componentSchema .getProperties ();
179
-
180
- if (CollectionUtils .isEmpty (properties )) {
181
- continue ;
182
- }
183
-
184
- for (Schema propSchema : properties .values ()) {
185
- String propertyNode = MessageFormat .format ("components.schemas.{0}.properties.{1}" ,
186
- componentSchema .getName (), propSchema .getName ());
187
-
188
- resolveString (propSchema ::setDescription , propertyNode + ".description" );
189
- resolveString (propSchema ::setExample , propertyNode + ".example" );
190
- }
191
- }
192
- }
174
+ Components components = openApi .getComponents ();
175
+ if (components == null || CollectionUtils .isEmpty (components .getSchemas ())) {
176
+ return ;
177
+ }
178
+
179
+ for (Schema componentSchema : components .getSchemas ().values ()) {
180
+ // set component description
181
+ String schemaPropertyPrefix = MessageFormat .format ("components.schemas.{0}" , componentSchema .getName ());
182
+ resolveString (componentSchema ::setDescription , schemaPropertyPrefix + ".description" );
183
+ Map <String , Schema > properties = componentSchema .getProperties ();
184
+
185
+ if (CollectionUtils .isEmpty (properties )) {
186
+ continue ;
187
+ }
188
+
189
+ for (Schema propSchema : properties .values ()) {
190
+ String propertyNode = MessageFormat .format ("components.schemas.{0}.properties.{1}" ,
191
+ componentSchema .getName (), propSchema .getName ());
192
+
193
+ resolveString (propSchema ::setDescription , propertyNode + ".description" );
194
+ resolveString (propSchema ::setExample , propertyNode + ".example" );
195
+ }
196
+ }
197
+ }
193
198
194
199
/**
195
200
* Resolve string.
@@ -198,13 +203,13 @@ private void setComponentsProperties(OpenAPI openApi) {
198
203
* @param node the node
199
204
*/
200
205
private void resolveString (
201
- Consumer <String > setter , String node
202
- ) {
203
- String nodeWithPrefix = propertyPrefix + node ;
204
- String value = propertyResolver .getProperty (nodeWithPrefix );
205
- if (StringUtils .isNotBlank (value )) {
206
- setter .accept (value );
207
- }
208
- }
206
+ Consumer <String > setter , String node
207
+ ) {
208
+ String nodeWithPrefix = propertyPrefix + node ;
209
+ String value = propertyResolver .getProperty (nodeWithPrefix );
210
+ if (StringUtils .isNotBlank (value )) {
211
+ setter .accept (value );
212
+ }
213
+ }
209
214
210
215
}
0 commit comments