|
| 1 | +/* |
| 2 | + * |
| 3 | + * * |
| 4 | + * * * Copyright 2019-2020 the original author or authors. |
| 5 | + * * * |
| 6 | + * * * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * * * you may not use this file except in compliance with the License. |
| 8 | + * * * You may obtain a copy of the License at |
| 9 | + * * * |
| 10 | + * * * https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * * * |
| 12 | + * * * Unless required by applicable law or agreed to in writing, software |
| 13 | + * * * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * * * See the License for the specific language governing permissions and |
| 16 | + * * * limitations under the License. |
| 17 | + * * |
| 18 | + * |
| 19 | + */ |
| 20 | + |
1 | 21 | package org.springdoc.nativex.core;
|
2 | 22 |
|
| 23 | +import java.io.IOException; |
| 24 | +import java.util.Properties; |
| 25 | + |
3 | 26 | import io.swagger.v3.core.converter.ModelConverter;
|
4 | 27 | import io.swagger.v3.core.converter.ModelConverters;
|
5 | 28 | import io.swagger.v3.core.filter.SpecFilter;
|
|
77 | 100 | import io.swagger.v3.oas.models.parameters.QueryParameter;
|
78 | 101 | import io.swagger.v3.oas.models.security.Scopes;
|
79 | 102 | import io.swagger.v3.oas.models.servers.ServerVariables;
|
| 103 | +import org.apache.commons.lang3.StringUtils; |
80 | 104 | import org.springdoc.api.AbstractOpenApiResource;
|
81 | 105 | import org.springdoc.api.mixins.SortedOpenAPIMixin;
|
82 | 106 | import org.springdoc.api.mixins.SortedSchemaMixin;
|
|
106 | 130 | import org.springdoc.core.converters.SchemaPropertyDeprecatingConverter;
|
107 | 131 | import org.springdoc.ui.AbstractSwaggerWelcome;
|
108 | 132 |
|
| 133 | +import org.springframework.beans.factory.InitializingBean; |
109 | 134 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
110 | 135 | import org.springframework.context.annotation.Configuration;
|
111 | 136 | import org.springframework.context.annotation.Lazy;
|
112 | 137 | import org.springframework.context.annotation.PropertySource;
|
| 138 | +import org.springframework.core.io.ClassPathResource; |
| 139 | +import org.springframework.core.io.Resource; |
| 140 | +import org.springframework.core.io.support.PropertiesLoaderUtils; |
113 | 141 | import org.springframework.nativex.hint.JdkProxyHint;
|
114 | 142 | import org.springframework.nativex.hint.ResourceHint;
|
115 | 143 | import org.springframework.nativex.hint.TypeAccess;
|
116 | 144 | import org.springframework.nativex.hint.TypeHint;
|
| 145 | +import org.springframework.util.AntPathMatcher; |
117 | 146 |
|
118 | 147 | import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;
|
119 | 148 |
|
| 149 | +/** |
| 150 | + * The type Spring doc hints. |
| 151 | + * @author bnasslahsen |
| 152 | + */ |
120 | 153 | @JdkProxyHint(typeNames = "javax.servlet.http.HttpServletRequest")
|
121 | 154 | @JdkProxyHint(typeNames = "org.springframework.web.context.request.NativeWebRequest")
|
122 | 155 |
|
|
263 | 296 | @Lazy(false)
|
264 | 297 | @Configuration(proxyBeanMethods = false)
|
265 | 298 | @ConditionalOnProperty(name = SPRINGDOC_ENABLED, matchIfMissing = true)
|
266 |
| -public class SpringDocHints {} |
| 299 | +public class SpringDocHints implements InitializingBean { |
| 300 | + |
| 301 | + /** |
| 302 | + * The Swagger ui config properties. |
| 303 | + */ |
| 304 | + private final SwaggerUiConfigProperties swaggerUiConfigProperties; |
| 305 | + |
| 306 | + /** |
| 307 | + * The constant SPRINGDOC_CONFIG_PROPERTIES. |
| 308 | + */ |
| 309 | + private static final String SPRINGDOC_CONFIG_PROPERTIES = "springdoc.config.properties"; |
| 310 | + |
| 311 | + /** |
| 312 | + * The constant SPRINGDOC_SWAGGERUI_VERSION. |
| 313 | + */ |
| 314 | + private static final String SPRINGDOC_SWAGGERUI_VERSION= "springdoc.swagger-ui.version"; |
| 315 | + |
| 316 | + /** |
| 317 | + * Instantiates a new Spring doc hints. |
| 318 | + * |
| 319 | + * @param swaggerUiConfigProperties the swagger ui config properties |
| 320 | + */ |
| 321 | + public SpringDocHints(SwaggerUiConfigProperties swaggerUiConfigProperties) { |
| 322 | + this.swaggerUiConfigProperties = swaggerUiConfigProperties; |
| 323 | + } |
| 324 | + |
| 325 | + @Override |
| 326 | + public void afterPropertiesSet() { |
| 327 | + if (StringUtils.isEmpty(swaggerUiConfigProperties.getVersion())) { |
| 328 | + try { |
| 329 | + Resource resource = new ClassPathResource(AntPathMatcher.DEFAULT_PATH_SEPARATOR + SPRINGDOC_CONFIG_PROPERTIES); |
| 330 | + Properties props = PropertiesLoaderUtils.loadProperties(resource); |
| 331 | + swaggerUiConfigProperties.setVersion(props.getProperty(SPRINGDOC_SWAGGERUI_VERSION)); |
| 332 | + } |
| 333 | + catch (IOException e) { |
| 334 | + throw new RuntimeException(e); |
| 335 | + } |
| 336 | + } |
| 337 | + } |
| 338 | +} |
267 | 339 |
|
0 commit comments