8484 */
8585public class SpecPropertiesCustomizer implements GlobalOpenApiCustomizer {
8686
87+ /**
88+ * The constant DESCRIPTION.
89+ */
90+ private static final String DESCRIPTION = ".description" ;
91+
8792 /**
8893 * The Property resolver.
8994 */
@@ -100,9 +105,9 @@ public class SpecPropertiesCustomizer implements GlobalOpenApiCustomizer {
100105 * @param resolverUtils the resolver utils
101106 */
102107 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+ }
106111
107112 /**
108113 * Instantiates a new Spec properties customizer.
@@ -111,85 +116,85 @@ public SpecPropertiesCustomizer(PropertyResolver resolverUtils) {
111116 * @param groupName the group name
112117 */
113118 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+ }
117122
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+ }
124129
125130 /**
126131 * Sets operation info properties.
127132 *
128133 * @param openApi the open api
129134 */
130135 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+ }
140145
141146 /**
142147 * Sets paths properties.
143148 *
144149 * @param openApi the open api
145150 */
146151 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+ }
162167
163168 /**
164169 * Sets components properties.
165170 *
166171 * @param openApi the open api
167172 */
168173 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+ }
193198
194199 /**
195200 * Resolve string.
@@ -198,13 +203,13 @@ private void setComponentsProperties(OpenAPI openApi) {
198203 * @param node the node
199204 */
200205 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+ }
209214
210215}
0 commit comments