Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger ui stuck on unable to infer base url #1996

Closed
muudyguy opened this issue Aug 23, 2017 · 60 comments
Closed

Swagger ui stuck on unable to infer base url #1996

muudyguy opened this issue Aug 23, 2017 · 60 comments
Labels
Milestone

Comments

@muudyguy
Copy link

Hello,

I am trying to run swagger-ui via springfox. My service is behind an edge service, and from swagger I am constantly getting the error :
screen shot 2017-08-23 at 16 01 41

My docket config is as follows

return new Docket(DocumentationType.SWAGGER_2)
                .host("http://localhost:8999")
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();

I have tried different possibilities of host configuration, including not providing it at all.

I can access the docs json from http://localhost:8999/v2/api-docs just fine.
When I try to set the base url through this message, no matter what I enter, the dialog flickers and just stands there. I check the network and the browser makes a request to /configuration, which seems to return 200.

I have no idea what to do at this point. Does anyone have any idea ?

@dilipkrish
Copy link
Member

Couple of things to try...

  • Can you brining it up when you run it locally?
  • If you can, then its most likely your gateway is not setting the X-FORWARD... headers correctly
  • If you can't then you have some issues in your swagger-configuration.

In any case, you need to override the host name with caution. Its really only to facilitate tweaking if everything else doesnt work.

@muudyguy
Copy link
Author

muudyguy commented Sep 3, 2017

I cannot bring it up in local because even on local I run the environment with docker compose, hence the edge service is still in front of the main service.

@DexterYang1982
Copy link

i faced the same problem
make sure your swagger configuration is under your spring boot application which can be scanned.
and then it solved.

@danieldietrich
Copy link

I had the same problem using Spring Boot 2.0.0.M4 + Spring Security. This solved my issue:

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
class SecurityConfig extends WebSecurityConfigurerAdapter {

    private static final String[] AUTH_WHITELIST = {

            // -- swagger ui
            "/swagger-resources/**",
            "/swagger-ui.html",
            "/v2/api-docs",
            "/webjars/**"
    };
    
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers(AUTH_WHITELIST).permitAll()
                .antMatchers("/**/*").denyAll();
    }
}

I don't know, if the whitelist is complete or correct at all. But it solves the issue described above.

@muudyguy
Copy link
Author

muudyguy commented Oct 9, 2017

This is somewhat irrelevant now, but what you say has nothing to do with the issue

@danieldietrich
Copy link

@logicaleak Ok, thank you - it seems to be the same symptom for a different reason in my case. However, maybe it is useful for someone (like me) googling that error message.

Here is what I get if I remove "/swagger-resource/**" from the AUTH_WHITELIST described above:

screen shot 2017-10-09 at 15 32 50

@skozlovich
Copy link

@dilipkrish what should the X-FORWARD headers contain? I can bring it up locally just fine, but when deploying behind a load balancer in AWS I get that dreaded "Unable to infer base url" popup

@dilipkrish
Copy link
Member

@skozlovich Your X-FORWARD headers would contain your upstream url.

For e.g. if you're doing request path based routing in your api gateway

https://host/path -> https://upstream:port/

Then your X-Forward headers should reflect the upstream information

@igor-holly
Copy link

Try to clear the browser cache.

@pedorro
Copy link

pedorro commented Dec 18, 2017

I just like to chime in here that I'm seeing this exact same issue. Since the upgrade to Springfox v2.7.0 from v2.4.0 (which fixed #799 - thanks! 😃 ), I'm presented with the same response as in the screenshot above when attempting to view the Swagger UI page. I've tried refreshing cache, switching browsers, and adjusting permissions, even so far as just setting 'permitAll()' to all urls. No luck. I'll keep poking at it and post back here if I come up with anything.

FWIW - I've also tried upgrading to the latest Spring Boot (v1.5.9), Spring Security (v4.2.3), and Guava (v23.5-jre). Still getting the same issue

@dilipkrish
Copy link
Member

@pedorro You need to find out what path returns a valid json for the path http(s)://host:port/<your-mystery-path>/swagger-resources/configuration/security. Once you know what you-mystery-path is then your base path url is http(s)://host:port/<your-mystery-path>

@pedorro
Copy link

pedorro commented Dec 19, 2017

@dilipkrish thanks for the quick response. I've got a base url path (I think?) by defining the property springfox.documentation.swagger.v2.path. That seems to set the path for what would otherwise be /v2/api-docs, and also the base path for swagger-ui.html. That does not seem to change the base path for /swagger-resources/configuration/security though. That is still mapping to the root url, as is everything at the /swagger-resources path.

I think I've gotten everything working by adding a number of explicit redirects for urls that it's unable to find because they are not mapped to that base path. The explicit redirects I've added are:

  • <base-path>/swagger-resources -> /swagger-resources
  • <base-path>/swagger-resources/configuration/security -> /swagger-resources/configuration/security
  • <base-path>/swagger-resources/configuration/ui -> /swagger-resources/configuration/ui
  • <base-path>/<base-path> -> <base-path> (this is a weird one)

I discovered this list of required redirects by watching the requests made by swagger-ui.html and seeing which were coming back as 404s. One particularly weird one is that it's looking for the /v2/api-docs json at <base-path>/<base-path>, instead of just <base-path>.

Anyway, I think I have it working now.

Thanks for your help! And for supporting this library! It really is invaluable.

@dilipkrish dilipkrish added this to the 2.8.0 milestone Jan 14, 2018
@ghost ghost removed the current label Jan 14, 2018
@palossyl
Copy link

Do you have the

@EnableSwagger2

annotation on your SpringApplication?
If missing, causes popping up the above message box!

@jagatrsingh
Copy link

The message is promoted in a catch block which does not determine or throw actual http error code which is confusing for many. In short any problem in invoking and the url or getting the response output will throw this error which could be due to URL context/base path issue, permission issue, spring web container not returning json values etc. ( In my case web container was returning xml and also initially i did not have protected urls )

Best solution from framework point of view will be to catch different exceptions and give appropriate message to users.

@codernonkey
Copy link

I was running into the same issue. Once I allowed all access to /swagger-resources/** I could access the API as normal.
Looking with the dev-console of the browser, I realized that the swagger is NOT sending the Session/Credentials Information to the server, which causes the Server to return a 401. As swagger then misses the required information, it shows the "unable to infer baseurl" screen. However, as the correct base url again gives a 401, you end up in an endless loop.

Interestingly, for all other resources, the browser is sending the session/credential information. So I assume the bug is not on server side but swagger fails to send the (XMLHttp)Request to swagger-resources without the withCredentials flag set (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials).

So for me the fix was to not require authentication/authorization for /swagger-resources/** resources.

@dilipkrish
Copy link
Member

@codernonkey thanks for your suggestion. I believe it was fixed in 2.9.0, so I just wanted to check if that was the version you're using.

@jagatrsingh thanks for your input, in this case, since its the browser, you should be able to inspect the console to find out what happened.

@jonathannaguin
Copy link

@dilipkrish I just upgraded to 2.9.0 and I am still getting this problem. Does Swagger work at all with Spring Security?

@dilipkrish
Copy link
Member

You mean swagger-ui? Yes it does, but you need to configure it correctly for it to work. The simplest option is to permit anonymous access to

  • /swagger-ui.html
  • /swagger-resources/**
  • /v2/api-docs
  • /webjars/**
    as shown here.

If thats not an option you'd need to protect some of those resources via basic authentication, typically an authentication mechanism (may be different from the one protecting the APIs themselves).

@codernonkey
Copy link

@dilipkrish I was and am using version 2.8.0 from https://mvnrepository.com/artifact/io.springfox but am not sure if this is the right source as there is no 2.9.0 available?

@dilipkrish
Copy link
Member

@codernonkey its available in jcenter.

@shuchitaprasad
Copy link

The solution suggested by @danieldietrich worked for me :-)

@ropherpanama
Copy link

Same problem here.
Swagger 2.9.2, adding my SpringFoxConfigclass to getRootConfigClasses solve the problem.

public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer  {
@Override
protected Class<?>[] getRootConfigClasses() {
	return new Class[] { ApplicationConfiguration.class, SpringFoxConfig.class };
}

@Override
protected Class<?>[] getServletConfigClasses() {
	return null;
}

@Override
protected String[] getServletMappings() {
	return new String[] { "/" };
}
}

@dilipkrish
Copy link
Member

@ropherpanama thanks for sharing your tip

@timvl
Copy link

timvl commented Jul 10, 2018

Adding @EnableSwagger2 did the trick for me

@waqas64
Copy link

waqas64 commented Nov 8, 2018

I am facing the same issue on localhost. I am trying to connect swagger-ui to an existing swagger.json (not auto-generated). Followed this project here but with version 2.9.2
''https://github.com/indrabasak/springfox-ui-from-json-example''
I can see the swagger JSON on /v2/api-docs but calling http://localhost:8080/swagger-ui.html#/ gives me the "unable to infer base url" error.
Tried most of the proposed solutions, no success yet!

@oeresundsgruppen
Copy link

Available on https://github.com/oeresundsgruppen/swaggerTest

@dilipkrish
Copy link
Member

@oeresundsgruppen Thats an old repo that I submitted a PR for to fix your setup. Nothing has changed since. Do you have some commits you haven't pushed perhaps?

@oeresundsgruppen
Copy link

The example works under spring-run/java -jar, but not under plain simple tomcat - and hence demonstrates the problems to be resolved. This is unfortunately still open

@copperfield-dev
Copy link

Do you have the

@EnableSwagger2

annotation on your SpringApplication?
If missing, causes popping up the above message box!

I add this annotation, and fix the problem

@oeresundsgruppen
Copy link

Indeed I did, are you deploying under tomcat ?

@Noodles-Buddy
Copy link

Noodles-Buddy commented Dec 28, 2018

my project is not for springboot . but for spring-mvc 's swagger config class like this:
`@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig {
@bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any()) //显示所有类
//.apis(RequestHandlerSelectors.withClassAnnotation(Api.class)) //只显示添加@Api注解的类
.build()
.apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
            .title("**订单api")  //粗标题
            .description("controller层接口描述")   //描述
            .version("1.2.3")   //api version
            .termsOfServiceUrl("http://abc.com")
            .license("http://abc.com")   //链接名称
            .licenseUrl("http://abc.com")   //链接地址
            .build();
}

}
`
i can't get solution to solve my problem. who can help me?
Addition: i can run it locally.

@pravgcet
Copy link

pravgcet commented Jan 9, 2019

I got it working by adding @Configuration along with @EnableSwagger2

@ljrjain
Copy link

ljrjain commented Mar 20, 2019

Version 2.9.2 is not working on AWS ALB, it has same issue as mentioned by oeresundsgruppen commented on 5 Nov 2018.
/api/null/swagger-resources/configuration/ui is being accessed. not sure why null is being added.

At local it works OK though with localhost.

This is the config I have .../swagger-resources/configuration/ui" is being redirected to /api/null/swagger-resources/configuration/ui.

/**
* {@inheritdoc}
*/
@OverRide
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/api/customer-api/api-docs",
"/api/api-docs").setKeepQueryParams(true);
registry.addRedirectViewController("/api/swagger-resources/configuration/ui",
"/swagger-resources/configuration/ui");
registry.addRedirectViewController("/api/swagger-resources/configuration/security",
"/swagger-resources/configuration/security");
registry.addRedirectViewController("/api/swagger-resources", "/swagger-resources");
}

/**
 * {@inheritDoc}
 */
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/api/**").addResourceLocations("classpath:/META-INF/resources/");
}

@nurettin
Copy link

Tried all of this until I realized that my swagger config (which I copied from another project) was in the wrong package.

@bakoontz
Copy link

Strangely, mine works fine in the local environment but not in bluemix using the same identical properties.yml file.

/v2/api-docs works fine.

It does look like springfox tries to return something cryptic:

<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Swagger UI</title>
  <link rel="stylesheet" type="text/css" href="webjars/springfox-swagger-ui/springfox.css?v=2.9.2" >
  <link rel="stylesheet" type="text/css" href="webjars/springfox-swagger-ui/swagger-ui.css?v=2.9.2" >
  <link rel="icon" type="image/png" href="webjars/springfox-swagger-ui/favicon-32x32.png?v=2.9.2" sizes="32x32" />
  <link rel="icon" type="image/png" href="webjars/springfox-swagger-ui/favicon-16x16.png?v=2.9.2" sizes="16x16" />
  <style>
    html
    {
      box-sizing: border-box;
      overflow: -moz-scrollbars-vertical;
      overflow-y: scroll;
    }
    *,
    *:before,
    *:after
    {
      box-sizing: inherit;
    }

    body {
      margin:0;
      background: #fafafa;
    }
  </style>
</head>

<body>

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
  <defs>
    <symbol viewBox="0 0 20 20" id="unlocked">
      <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
    </symbol>

    <symbol viewBox="0 0 20 20" id="locked">
      <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
    </symbol>

    <symbol viewBox="0 0 20 20" id="close">
      <path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
    </symbol>

    <symbol viewBox="0 0 20 20" id="large-arrow">
      <path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
    </symbol>

    <symbol viewBox="0 0 20 20" id="large-arrow-down">
      <path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
    </symbol>


    <symbol viewBox="0 0 24 24" id="jump-to">
      <path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
    </symbol>

    <symbol viewBox="0 0 24 24" id="expand">
      <path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
    </symbol>

  </defs>
</svg>

<div id="swagger-ui"></div>

@jayasvision
Copy link

I resolved it by adding the config package name "com.companyname.api.config" where I have kept my SwaggerConfiguration file in component scan
@componentscan(value = { "com.companyname.api.config"})

@bakoontz
Copy link

bakoontz commented May 21, 2019

@jayasvision: Appreciate the suggestion, tried it but no luck. Most likely because all my packages are subpackages of my Application package, so @componentscan has no effect.

Update: So it turns out IBM/Cloud Foundry can't figure out how to completely clear out the routes cache when pushing a new app to the cloud. Springfox serves up the content correctly, but one of the link elements doesn't get resolved correctly. Since there are not HTTP error codes returned, I can only assume the request is never received by the app.

Although not directly a Springfox issue, that "Unable to infer base URL" popup is misleading and obnoxious and should probably be better handled.

@tdaskhatri
Copy link

In spring boot application after making these changes in objectMapper swagger stops working changes done are below:
@bean
public Jackson2ObjectMapperBuilder jacksonBuilder() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.featuresToEnable(DeserializationFeature.UNWRAP_ROOT_VALUE);
builder.featuresToEnable(SerializationFeature.WRAP_ROOT_VALUE);
return builder;
}

If I remove these above changes swagger starts working.

@divStar
Copy link

divStar commented Jul 13, 2019

When externalizing swagger invocation into its own class, one should remember to always annotate that class not just with @EnableSwagger2, but also with @org.springframework.context.annotation.Configuration. This is what solved my issue.

@ktprezes
Copy link

Hi!
I've encountered the same error...
In my case it was because of missing '@configuration' annotation in 'SwaggerConfig.java' file.
I've labelled the 'public class SwaggerConfig' in this file only with '@EnableSwagger2',
but have forgotten to add '@configuration' too...
Just after adding that everything started to be OK :)

@Kakau-preto
Copy link

thanks @ktprezes ...... with your solution, i resolved my problem..

@bhagi965
Copy link

bhagi965 commented Apr 7, 2020

For me adding a bypass (/path/swagger-resources) to return true on token validation worked. Also needed to upgrade my spring version from 4.1.0.RELEASE to 4.2.0.RELEASE to solve internal server error on loading swagger ui.

@tatharoy
Copy link

I had the same issue because of my objectmapper config as mentioned by @tdaskhatri . Once i removed that, it started working fine

@cpuell
Copy link

cpuell commented Jul 15, 2020

Check your Java Version, i had used 11 and it doesn't work, downgraded to Java 8 and it works.

@dilipkrish
Copy link
Member

dilipkrish commented Jul 15, 2020

@cpuell I dont think that is true.. check the demo project with java 11. If you have a specific issue you're running into please create a new issue, would love to fix it.

@benht-nps
Copy link

In case helpful to someone, with a Spring Boot application I get this same error without a server.servlet.context-path entry in my application.properties file.

@whybeyoung
Copy link

whybeyoung commented Dec 27, 2020

image
myconfig:

import com.fasterxml.classmate.TypeResolver;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.builders.ResponseBuilder;
import springfox.documentation.schema.ScalarType;
import springfox.documentation.schema.WildcardType;

import java.time.LocalDate;
import java.util.List;

import static java.util.Collections.singletonList;
import static springfox.documentation.schema.AlternateTypeRules.newRule;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    public SwaggerConfig(TypeResolver typeResolver) {
        this.typeResolver = typeResolver;
    }

    @Bean
    public Docket createRestApi() {

        return new Docket(DocumentationType.OAS_30)

                .apiInfo(apiInfo())

                .select()

                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))

                .paths(PathSelectors.any())

                .build()
                .pathMapping("/")
                .directModelSubstitute(LocalDate.class, String.class)
                .genericModelSubstitutes(ResponseEntity.class)
                .alternateTypeRules(
                        newRule(typeResolver.resolve(DeferredResult.class,
                                typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
                                typeResolver.resolve(WildcardType.class)))
                .useDefaultResponseMessages(false)
                .globalResponses(HttpMethod.GET,
                        singletonList(new ResponseBuilder()
                                .code("500")
                                .description("500 message")
                                .representation(MediaType.TEXT_XML)
                                .apply(r ->
                                        r.model(m ->
                                                m.referenceModel(ref ->
                                                        ref.key(k ->
                                                                k.qualifiedModelName(q ->
                                                                        q.namespace("some:namespace")
                                                                                .name("ERROR"))))))
                                .build()))
                .enableUrlTemplating(true)
                .globalRequestParameters(
                        singletonList(new springfox.documentation.builders.RequestParameterBuilder()
                                .name("someGlobalParameter")
                                .description("Description of someGlobalParameter")
                                .in(ParameterType.QUERY)
                                .required(true)
                                .query(q -> q.model(m -> m.scalarModel(ScalarType.STRING)))
                                .build()));

    }
    private ApiInfo apiInfo() {

        return new ApiInfoBuilder()

                .title("Swagger3接口文档")

                .description("更多请咨询服务开发者XXX")

                .contact(new Contact("作者", "作者地址", "作者邮箱"))

                .version("1.0")

                .build();

    }

    @Autowired
    private TypeResolver typeResolver;
    List<SecurityReference> defaultAuth() {
        AuthorizationScope authorizationScope
                = new AuthorizationScope("global", "accessEverything");
        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
        authorizationScopes[0] = authorizationScope;
        return singletonList(
                new SecurityReference("mykey", authorizationScopes));
    }
    private SecurityContext securityContext() {
        return SecurityContext.builder()
                .securityReferences(defaultAuth())
                .forPaths(PathSelectors.regex("/anyPath.*"))
                .build();
    }
    @Bean
    UiConfiguration uiConfig() {
        return UiConfigurationBuilder.builder()
                .deepLinking(true)
                .displayOperationId(false)
                .defaultModelsExpandDepth(1)
                .defaultModelExpandDepth(1)
                .defaultModelRendering(ModelRendering.EXAMPLE)
                .displayRequestDuration(false)
                .docExpansion(DocExpansion.NONE)
                .filter(false)
                .maxDisplayedTags(null)
                .operationsSorter(OperationsSorter.ALPHA)
                .showExtensions(false)
                .showCommonExtensions(false)
                .tagsSorter(TagsSorter.ALPHA)
                .supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS)
                .validatorUrl(null)
                .build();
    }

}

@helderhernandez
Copy link

In my case I made the mistake of placing Swagger config class outside of main application package, moved it to main package of my application and it worked:

Bad

src/main/java
│    
│   
└───myproyec
│   │   MyPriyectApplication.class
│   │
│   └───models
│   │
│   └───controllers
│   
└───config
    │   SwaggerConfig.class ❌ 

Ok

src/main/java
│    
│   
└───myproyec
│   │   MyPriyectApplication.class
│   │
│   └───config
│   │   SwaggerConfig.class ✔️  
│   │
│   └───models
│   │
│   └───controllers

@1472rr
Copy link

1472rr commented Jun 10, 2021

In my case, i added a global custom json msg converter and this converter converts the response of 'http://localhost:8089/v2/api-docs' to my custom json format.
when i remove the global custom json msg converter, it works fine!
image
image

image

@rboughani
Copy link

rboughani commented Nov 25, 2021

i have the same issue locally, and i don't use spring security or others, all ressource are public !
only /info and /health which is working.
but when i generate the jar, and i install it in my server, it work fine !!

@Janardan0017
Copy link

Janardan0017 commented Dec 27, 2021

I resolved the same problem by just adding the version name like: /v1 in my api paths.

`@RestController
@RequestMapping("/v1/company")
public class CompanyController {

private final CompanyService companyService;

@Autowired
public CompanyController(CompanyService companyService) {
    this.companyService = companyService;
    }
}`

@hasitha3rd
Copy link

I was stuck for a day with this issue. My issue was incorrect port configuration. Check your application.yml/application.properties file for port configuration. There I had mistakenly added both
server.port , management.server.port with different values 🤣 .

@Shekhartelaverge
Copy link

getting the same issue

@liuyan1001
Copy link

I have the same issue, stuck 1 day, not resoved yet. Questions about this issue are all over the search engines for yeas. Is it neccesary to be like this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests