3636import java .util .Map ;
3737import java .util .function .Consumer ;
3838
39+ import static org .springdoc .core .utils .Constants .SPRINGDOC_SPEC_PROPERTIES_PREFIX ;
40+
3941/**
4042 * Allows externalizing strings in generated openapi schema via properties that follow
4143 * conventional naming similar or identical to <a href="https://swagger.io/docs/specification/basic-structure/">openapi schema</a>
4244 * <p>
4345 * 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.
4547 * <p>
4648 * Sample supported properties for api-info customization:
4749 * <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>
5254 * </ul>
5355 * <p>
5456 * Sample supported properties for components customization:
5557 * <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>
5961 * </ul>
6062 * <p>
6163 * Sample supported properties for paths/operationIds customization:
6264 * <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>
6567 * </ul>
6668 * <p>
6769 * Support for groped openapi customization is similar to the above, but with a group name prefix.
6870 * E.g.
6971 * <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>
7375 * </ul>
7476 *
7577 * @author Anton Tkachenko tkachenkoas@gmail.com
78+ * @author bnasslahsen
7679 */
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 ) {
8598 this .propertyResolver = resolverUtils ;
86- this .propertyPrefix = SPECIFICATION_STRINGS_PREFIX ;
99+ this .propertyPrefix = SPRINGDOC_SPEC_PROPERTIES_PREFIX ;
87100 }
88101
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 ) {
90109 this .propertyResolver = propertyResolver ;
91- this .propertyPrefix = SPECIFICATION_STRINGS_PREFIX + groupName + "." ;
110+ this .propertyPrefix = SPRINGDOC_SPEC_PROPERTIES_PREFIX + groupName + "." ;
92111 }
93112
94113 @ Override
@@ -98,7 +117,12 @@ public void customise(OpenAPI openApi) {
98117 setPathsProperties (openApi );
99118 }
100119
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 ) {
102126 if (openApi .getInfo () == null ) {
103127 openApi .setInfo (new Info ());
104128 }
@@ -109,7 +133,12 @@ private void setOperationInfoProperties(OpenAPI openApi) {
109133 resolveString (info ::setTermsOfService , "info.termsOfService" );
110134 }
111135
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 ) {
113142 Paths paths = openApi .getPaths ();
114143 if (CollectionUtils .isEmpty (paths .values ())) {
115144 return ;
@@ -126,7 +155,12 @@ private void setPathsProperties(OpenAPI openApi) {
126155 }
127156 }
128157
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 ) {
130164 Components components = openApi .getComponents ();
131165 if (components == null || CollectionUtils .isEmpty (components .getSchemas ())) {
132166 return ;
@@ -152,7 +186,13 @@ private void setComponentsProperties(OpenAPI openApi) {
152186 }
153187 }
154188
155- private void resolveString (
189+ /**
190+ * Resolve string.
191+ *
192+ * @param setter the setter
193+ * @param node the node
194+ */
195+ private void resolveString (
156196 Consumer <String > setter , String node
157197 ) {
158198 String nodeWithPrefix = propertyPrefix + node ;
0 commit comments