Skip to content

Commit

Permalink
Getting 404 when trying to access swagger-ui of a native spring-boot …
Browse files Browse the repository at this point in the history
…app. Fixes #1394.
  • Loading branch information
bnasslahsen committed Dec 18, 2021
1 parent dde8f90 commit b2f298a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
/*
*
* *
* * * Copyright 2019-2020 the original author or authors.
* * *
* * * Licensed under the Apache License, Version 2.0 (the "License");
* * * you may not use this file except in compliance with the License.
* * * You may obtain a copy of the License at
* * *
* * * https://www.apache.org/licenses/LICENSE-2.0
* * *
* * * Unless required by applicable law or agreed to in writing, software
* * * distributed under the License is distributed on an "AS IS" BASIS,
* * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * See the License for the specific language governing permissions and
* * * limitations under the License.
* *
*
*/

package org.springdoc.nativex.core;

import java.io.IOException;
import java.util.Properties;

import io.swagger.v3.core.converter.ModelConverter;
import io.swagger.v3.core.converter.ModelConverters;
import io.swagger.v3.core.filter.SpecFilter;
Expand Down Expand Up @@ -77,6 +100,7 @@
import io.swagger.v3.oas.models.parameters.QueryParameter;
import io.swagger.v3.oas.models.security.Scopes;
import io.swagger.v3.oas.models.servers.ServerVariables;
import org.apache.commons.lang3.StringUtils;
import org.springdoc.api.AbstractOpenApiResource;
import org.springdoc.api.mixins.SortedOpenAPIMixin;
import org.springdoc.api.mixins.SortedSchemaMixin;
Expand Down Expand Up @@ -106,17 +130,26 @@
import org.springdoc.core.converters.SchemaPropertyDeprecatingConverter;
import org.springdoc.ui.AbstractSwaggerWelcome;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.nativex.hint.JdkProxyHint;
import org.springframework.nativex.hint.ResourceHint;
import org.springframework.nativex.hint.TypeAccess;
import org.springframework.nativex.hint.TypeHint;
import org.springframework.util.AntPathMatcher;

import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;

/**
* The type Spring doc hints.
* @author bnasslahsen
*/
@JdkProxyHint(typeNames = "javax.servlet.http.HttpServletRequest")
@JdkProxyHint(typeNames = "org.springframework.web.context.request.NativeWebRequest")

Expand Down Expand Up @@ -263,5 +296,44 @@
@Lazy(false)
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(name = SPRINGDOC_ENABLED, matchIfMissing = true)
public class SpringDocHints {}
public class SpringDocHints implements InitializingBean {

/**
* The Swagger ui config properties.
*/
private final SwaggerUiConfigProperties swaggerUiConfigProperties;

/**
* The constant SPRINGDOC_CONFIG_PROPERTIES.
*/
private static final String SPRINGDOC_CONFIG_PROPERTIES = "springdoc.config.properties";

/**
* The constant SPRINGDOC_SWAGGERUI_VERSION.
*/
private static final String SPRINGDOC_SWAGGERUI_VERSION= "springdoc.swagger-ui.version";

/**
* Instantiates a new Spring doc hints.
*
* @param swaggerUiConfigProperties the swagger ui config properties
*/
public SpringDocHints(SwaggerUiConfigProperties swaggerUiConfigProperties) {
this.swaggerUiConfigProperties = swaggerUiConfigProperties;
}

@Override
public void afterPropertiesSet() {
if (StringUtils.isEmpty(swaggerUiConfigProperties.getVersion())) {
try {
Resource resource = new ClassPathResource(AntPathMatcher.DEFAULT_PATH_SEPARATOR + SPRINGDOC_CONFIG_PROPERTIES);
Properties props = PropertiesLoaderUtils.loadProperties(resource);
swaggerUiConfigProperties.setVersion(props.getProperty(SPRINGDOC_SWAGGERUI_VERSION));
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}

0 comments on commit b2f298a

Please sign in to comment.