2121package org .springdoc .nativex .core ;
2222
2323import java .io .IOException ;
24+ import java .util .Optional ;
2425import java .util .Properties ;
2526
2627import io .swagger .v3 .core .converter .ModelConverter ;
@@ -302,7 +303,7 @@ public class SpringDocHints implements InitializingBean {
302303 /**
303304 * The Swagger ui config properties.
304305 */
305- private final SwaggerUiConfigProperties swaggerUiConfigProperties ;
306+ private final Optional < SwaggerUiConfigProperties > optionalSwaggerUiConfigProperties ;
306307
307308 /**
308309 * The constant SPRINGDOC_CONFIG_PROPERTIES.
@@ -312,29 +313,31 @@ public class SpringDocHints implements InitializingBean {
312313 /**
313314 * The constant SPRINGDOC_SWAGGERUI_VERSION.
314315 */
315- private static final String SPRINGDOC_SWAGGERUI_VERSION = "springdoc.swagger-ui.version" ;
316+ private static final String SPRINGDOC_SWAGGERUI_VERSION = "springdoc.swagger-ui.version" ;
316317
317318 /**
318319 * Instantiates a new Spring doc hints.
319320 *
320- * @param swaggerUiConfigProperties the swagger ui config properties
321+ * @param optionalSwaggerUiConfigProperties the swagger ui config properties
321322 */
322- public SpringDocHints (SwaggerUiConfigProperties swaggerUiConfigProperties ) {
323- this .swaggerUiConfigProperties = swaggerUiConfigProperties ;
323+ public SpringDocHints (Optional < SwaggerUiConfigProperties > optionalSwaggerUiConfigProperties ) {
324+ this .optionalSwaggerUiConfigProperties = optionalSwaggerUiConfigProperties ;
324325 }
325326
326327 @ Override
327328 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+ }
333339 }
334- catch (IOException e ) {
335- throw new RuntimeException (e );
336- }
337- }
340+ });
338341 }
339342}
340343
0 commit comments