21
21
package org .springdoc .nativex .core ;
22
22
23
23
import java .io .IOException ;
24
+ import java .util .Optional ;
24
25
import java .util .Properties ;
25
26
26
27
import io .swagger .v3 .core .converter .ModelConverter ;
@@ -302,7 +303,7 @@ public class SpringDocHints implements InitializingBean {
302
303
/**
303
304
* The Swagger ui config properties.
304
305
*/
305
- private final SwaggerUiConfigProperties swaggerUiConfigProperties ;
306
+ private final Optional < SwaggerUiConfigProperties > optionalSwaggerUiConfigProperties ;
306
307
307
308
/**
308
309
* The constant SPRINGDOC_CONFIG_PROPERTIES.
@@ -312,29 +313,31 @@ public class SpringDocHints implements InitializingBean {
312
313
/**
313
314
* The constant SPRINGDOC_SWAGGERUI_VERSION.
314
315
*/
315
- private static final String SPRINGDOC_SWAGGERUI_VERSION = "springdoc.swagger-ui.version" ;
316
+ private static final String SPRINGDOC_SWAGGERUI_VERSION = "springdoc.swagger-ui.version" ;
316
317
317
318
/**
318
319
* Instantiates a new Spring doc hints.
319
320
*
320
- * @param swaggerUiConfigProperties the swagger ui config properties
321
+ * @param optionalSwaggerUiConfigProperties the swagger ui config properties
321
322
*/
322
- public SpringDocHints (SwaggerUiConfigProperties swaggerUiConfigProperties ) {
323
- this .swaggerUiConfigProperties = swaggerUiConfigProperties ;
323
+ public SpringDocHints (Optional < SwaggerUiConfigProperties > optionalSwaggerUiConfigProperties ) {
324
+ this .optionalSwaggerUiConfigProperties = optionalSwaggerUiConfigProperties ;
324
325
}
325
326
326
327
@ Override
327
328
public void afterPropertiesSet () {
328
- if (StringUtils .isEmpty (swaggerUiConfigProperties .getVersion ())) {
329
- try {
330
- Resource resource = new ClassPathResource (AntPathMatcher .DEFAULT_PATH_SEPARATOR + SPRINGDOC_CONFIG_PROPERTIES );
331
- Properties props = PropertiesLoaderUtils .loadProperties (resource );
332
- swaggerUiConfigProperties .setVersion (props .getProperty (SPRINGDOC_SWAGGERUI_VERSION ));
329
+ optionalSwaggerUiConfigProperties .ifPresent (swaggerUiConfigProperties -> {
330
+ if (StringUtils .isEmpty (swaggerUiConfigProperties .getVersion ())) {
331
+ try {
332
+ Resource resource = new ClassPathResource (AntPathMatcher .DEFAULT_PATH_SEPARATOR + SPRINGDOC_CONFIG_PROPERTIES );
333
+ Properties props = PropertiesLoaderUtils .loadProperties (resource );
334
+ swaggerUiConfigProperties .setVersion (props .getProperty (SPRINGDOC_SWAGGERUI_VERSION ));
335
+ }
336
+ catch (IOException e ) {
337
+ throw new RuntimeException (e );
338
+ }
333
339
}
334
- catch (IOException e ) {
335
- throw new RuntimeException (e );
336
- }
337
- }
340
+ });
338
341
}
339
342
}
340
343
0 commit comments