Skip to content

Springfox swagger-ui.html not loading using version 3.0.0-SNAPSHOT #3362

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

Closed
satishpatro44 opened this issue Jul 2, 2020 · 26 comments
Closed

Comments

@satishpatro44
Copy link

In our project we are using 3.0.0-SNAPSHOT of swagger springfox.

Recently when we open swagger-ui.html, it is giving 404 Whilte Label Error.

I enabled logs at web level

`

logging.level.web=TRACE
logging.level.org.springframework.web=TRACE

`

It is loading "/swagger-resources", but not loading "/swagger-ui.html"

The addition of the resource handler is as per the document.

When loading "/swagger-ui.html", it's giving "Resource not found"

`

web.server.adapter.HttpWebHandlerAdapter.traceDebug - [74c4396b] HTTP GET "/swagger-resources/", headers={masked}
web.reactive.result.method.annotation.RequestMappingHandlerMapping.lambda$getHandler$1 - [74c4396b] Mapped to public org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> springfox.documentation.swagger.web.ApiResourceController.swaggerResources()
web.reactive.result.method.annotation.ResponseEntityResultHandler.selectMediaType - Using 'application/json;q=0.8' given [text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8] and supported [application/json]
web.reactive.result.method.annotation.ResponseEntityResultHandler.writeBody - [74c4396b] 0..1 [java.util.List<springfox.documentation.swagger.web.SwaggerResource>]
http.codec.json.Jackson2JsonEncoder.trace - [74c4396b] Encoding [[springfox.documentation.swagger.web.SwaggerResource@4903f26e, springfox.documentation.swagger.web.SwaggerResource@57b46085, springfox.documentation.swagger.web.SwaggerResource@4beb0f82, springfox.documentation.swagger.web.SwaggerResource@3a6db652, springfox.documentation.swagger.web.SwaggerResource@6caba3f3, springfox.documentation.swagger.web.SwaggerResource@18ef56ab, springfox.documentation.swagger.web.SwaggerResource@b6bcd2b, springfox.documentation.swagger.web.SwaggerResource@5ce32532, springfox.documentation.swagger.web.SwaggerResource@6d66b166, springfox.documentation.swagger.web.SwaggerResource@fdef86f, springfox.documentation.swagger.web.SwaggerResource@5a096e2a, springfox.documentation.swagger.web.SwaggerResource@1f060aec, springfox.documentation.swagger.web.SwaggerResource@473365eb, springfox.documentation.swagger.web.SwaggerResource@3fd6e0e2]]
web.server.adapter.HttpWebHandlerAdapter.traceDebug - [74c4396b] Completed 200 OK, headers={masked}
http.server.reactive.ReactorHttpHandlerAdapter.trace - [74c4396b] Handling completed

web.server.adapter.HttpWebHandlerAdapter.traceDebug - [74c4396b] HTTP GET "/swagger-ui.html", headers={masked}
web.reactive.handler.SimpleUrlHandlerMapping.lookupHandler - [74c4396b] Matching patterns [/swagger-ui.html**, /**]
web.reactive.handler.SimpleUrlHandlerMapping.lambda$getHandler$1 - [74c4396b] Mapped to ResourceWebHandler ["classpath:/META-INF/resources/"]
web.reactive.resource.ResourceWebHandler.lambda$handle$0 - [74c4396b] Resource not found
web.reactive.function.server.RouterFunctions.route - [74c4396b] Matched org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorWebExceptionHandler$$Lambda$1372/0x00000008008bb040@10209892
web.HttpLogging.debug - [74c4396b] Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /swagger-ui.html
core.codec.CharSequenceEncoder.trace - [74c4396b] Writing "<html><body><h1>Whitelabel Error Page</h1><p>This application has no configured error view, so you are seeing this as a fallback.</p><div id='created'>Thu Jul 02 22:15:45 IST 2020</div><div>There was an unexpected error (type=Not Found, status=404).</div></body></html>"
web.server.adapter.HttpWebHandlerAdapter.traceDebug - [74c4396b] Completed 404 NOT_FOUND, headers={masked}
http.server.reactive.ReactorHttpHandlerAdapter.trace - [74c4396b] Handling completed

`

I checked if path inside META-INF is changed or not as per documentation at https://springfox.github.io/springfox/docs/snapshot/#snapshot-3, it is same as V 2.10.5

Then, when I changed version from V 3 Snapshot to current stable 2.10.5, it worked.

Can you let me know what I am missing? And since I am a noobie, can you tell me is snapshot version is like beta version which should not be used in production?

@CamilYed
Copy link

CamilYed commented Jul 2, 2020

Duplicat #3360

@dilipkrish dilipkrish added this to the 3.0 milestone Jul 3, 2020
@andrew-property-xyz
Copy link

I must admit to being very confused. It seems that there are now multiple releases of 3.0.0-SNAPSHOT version - my .m2 repository has multiple 3.0.0-SNAPSHOT jars, one on 8th May, one on 5th July and one from earlier this morning. All I know is that my OpenAPI docs are now screwed and swagger-ui.html no longer works. I use Google Cloud Endpoints and this now rejects the OpenAPI v2 config doc which differs significantly from an earlier, working version and which is clearly 'odd'. I only switched to 3.0.0-SNAPSHOT because of its support for Spring WebFlux but it is clear that, at the moment, it is simply unusable for me. What is the plan for 3.0.0-SNAPSHOT? Should I switch to 2.10.5 but does that support Spring WebFlux. Sorry, not wanting to sound critical as it is a great product and it is clear to see the effort put it, but I am completely exasperated and wondering how to proceed. Any hints would be greatly appreciated.

@dilipkrish
Copy link
Member

@andrew-property-xyz again apologies as things are in a bit of a flux (as expected with snapshots) as I work on getting 3.0.0 released this week. I suspect there is a couple of things going on here. If you're unable to share a repo that demonstrates the problem, would you look at the the demos project especially the boot-webflux repo to see if you can modify it to reflect your problem.

@satishpatro44
Copy link
Author

@dilipkrish one doubt, what is the extra features are there in snapshot 3.0.0 that everyone is following the repo in dependency repo compared to 2.10.5 stable. For me, I just copied the version from a blog.

@dilipkrish
Copy link
Member

3.0.0 is the latest released version. Please see the release notes for details. 2.10.5 is an intermediate release and not meant for public consumption.

@fishjam
Copy link

fishjam commented Jul 23, 2020

I use 3.0.0 and find the new swagger ui is http://xxxx:port/swagger-ui/ ( please remember the last splash).
actually, you can add spring-boot-starter-actuator and confirm the swagger ui mapping by check http://xxx:port/actuator/mappings .
And my suggestion is restore the url to swagger-ui.html.

@pushkaraj20885
Copy link

pushkaraj20885 commented Jul 30, 2020

Hi @fishjam @dilipkrish
I am facing issues in all cases of url like http://xxxx:port/swagger-ui/ and getting
"message":"Invalid access token"

@dilipkrish
Copy link
Member

@pushkaraj20885 you need to allow access to the resources if you have authentication turned on

@pushkaraj20885
Copy link

pushkaraj20885 commented Aug 5, 2020

Hi @dilipkrish
I have added below mentioned code in class WebSecurityConfiguration extends WebSecurityConfigurerAdapter

void configure(final WebSecurity web) { web.ignoring().antMatchers('/v2/api-docs', '/swagger-resources/**', '/swagger-ui/**', '/swagger-ui/index.html**', '/webjars/**', '/actuator/health')

but still getting same error

@amathd777
Copy link

Please look at @fishjam post. To make it work .../swagger-ui/ NOT .html. That need to be fixed

@egch
Copy link

egch commented Oct 30, 2020

In spring boot it works by simply adding this, no other dependencies needed:
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency>
The url is /swagger-ui/ , mind the final slash.

@Prasannach123
Copy link

Thank you . It worked for me by adding the io.springfox springfox-boot-starter 3.0.0 and with the url http://localhost:8080/swagger-ui/

@saurabhks1
Copy link

Hi Guys,

I have to admit, the Swagger project is one of the most confusing library. I finally managed to get this working with springfox-boot-starter 3.0.0

My config:

gradle:
`
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}

group = 'com.curvecue'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}

ext {
set('springCloudVersion', "2020.0.1")
}

//configurations {
// // exclude Tomcat
//// compile.exclude module: 'spring-boot-starter-tomcat'
//}

dependencies {

implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'

// implementation 'org.springframework.boot:spring-boot-starter-undertow'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-webflux'

implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'

implementation 'org.flywaydb:flyway-core:7.5.2'

compile group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'

implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.1'

compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'

}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

test {
useJUnitPlatform()
}
`

@configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurerAdapter {
@bean
public Docket apiDocket() {
return new Docket( DocumentationType.SWAGGER_2 )
.select()
.apis( RequestHandlerSelectors.any() )
.paths( PathSelectors.any() )
.build();
}
}

Sample RestController
`
@RestController
@RequestMapping( "/stream-api/postgres" )
@requiredargsconstructor
@slf4j
public class PostgresController {

private final UserRepository userRepository;

@GetMapping( value = "/user", produces = MediaType.APPLICATION_NDJSON_VALUE )
public UserEntity getUser( @RequestParam( required = true ) String id ) {
	log.debug( "Looking up for user with id: {}", id );
	Optional<UserEntity> userEntityOptional = userRepository.findById( id );
	return userEntityOptional.orElse( null );
}

}
`

And now most importantly the url:
http://localhost:8080/swagger-ui/index.html <-- PLS NOTICE there is no context root specified here. I spent hours pointing to http://localhost:8080/stream-api/postgres/swagger-ui/index.html !

Hope this helps. I didn't have to make any Spring Security adjustments.

@kuchaguangjie
Copy link

new url is /swagger-ui/, and the / at end is necessary !!!

@bmithun
Copy link

bmithun commented May 11, 2021

new url is /swagger-ui/, and the / at end is necessary !!!

@kuchaguangjie Thank you so much. I spent an hour trying every possible approach only to figure out that I was missing a '/' at the end of the url.

@M1loseph
Copy link

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

Hello, I added this dependency to pom.xml (this is the only dependency pointing to sprinfox) and still getting error while accessing /swagger-ui/. On the other hand v2/api-docs works well. I didn't create any configuration classes. Does anyone know, what can be wrong here? Any pointers are appreciated!

@Paper-Folding
Copy link

new url is /swagger-ui/, and the / at end is necessary !!!

Thank you, finally works for me!!!

@ankit-singh-dungriyal
Copy link

While using the following dependencies, only http://localhost:8080/v2/api-docs is working not this http://localhost:8080/swagger-ui/

        <dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger2</artifactId>
		<version>3.0.0</version>
	</dependency>
	<dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger-ui</artifactId>
		<version>3.0.0</version>
	</dependency>

However, if you add the below dependency instead of the above one, both are working well

    <dependency>
          <groupId>io.springfox</groupId>
          <artifactId>springfox-boot-starter</artifactId>
          <version>3.0.0</version>
    </dependency>

@alexandreJavaDeveloper
Copy link

Incredible how a library is too confused!
I spent already 3 hours trying to fix my simple project, but nothing yet.

This works: http://localhost:8080/v2/api-docs
This does not work: http://localhost:8080/swagger-ui/, http://localhost:8080/stream-api/postgres/swagger-ui/index.html

Something missing?

@nishant-k1
Copy link

No solution worked for me yet

@lvmanasa
Copy link

io.springfox springfox-boot-starter 3.0.0

This worked for swagger version 3.0.0

@shabanali-faghani
Copy link

After spending several hours I found out in my case spring cloud config server caused the problem, see this and this. Since path conflict was the main reason of the problem, it's possible to happen in any other cases where path conflict exists, for example when base path of a rest service is / and there is a method with a @PathParam argument or when there is another tool like config server that hijacks url!

@subhanbee
Copy link

We are not using springboot application and but they are trying to update the swagger from 2.9.2 to 3.0.0 version and we are facing swagger.html issue 404.
I tried swagger-ui/index.html also but no luck.

Could you please help on this to work?

@NikhilAdsul
Copy link

NikhilAdsul commented Aug 24, 2022

currently i am using springfox 3.0.0 with spring-boot 2.7.1 version. below link solutions doesn't work for me.
i spend couples of days on it but no luck. can anyone help me for this its urgent, need to solve it ASAP.
(http://springfox.github.io/springfox/docs/current/#migrating-from-existing-2-x-version)
below issue i am getting
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Jul 06 21:19:55 AEST 2020
There was an unexpected error (type=Not Found, status=404).

while using swagger-ui urls.
http://localhost:8081/api-payroll-ng/docs/swagger-ui
http://localhost:8081/api-payroll-ng/docs/swagger-ui/index.html

@tntsoft
Copy link

tntsoft commented Sep 25, 2022

currently i am using springfox 3.0.0 with spring-boot 2.7.1 version. below link solutions doesn't work for me. i spend couples of days on it but no luck. can anyone help me for this its urgent, need to solve it ASAP. (http://springfox.github.io/springfox/docs/current/#migrating-from-existing-2-x-version) below issue i am getting Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Mon Jul 06 21:19:55 AEST 2020 There was an unexpected error (type=Not Found, status=404).

while using swagger-ui urls. http://localhost:8081/api-payroll-ng/docs/swagger-ui http://localhost:8081/api-payroll-ng/docs/swagger-ui/index.html

Have you manage to sort this?

g0tmi1k added a commit to danielmiessler/SecLists that referenced this issue Mar 9, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
add **swagger-ui/ path (springfox)

Source: springfox/springfox#3362 (comment)
@adityadhiman12
Copy link

none of the mentioned solutions are working for me, following is my configuration:

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.1.8'
	id 'io.spring.dependency-management' version '1.1.4'
	id("io.swagger.core.v3.swagger-gradle-plugin") version "2.2.19"
}
Screenshot 2024-01-31 at 1 52 52 PM

Any help would be appreciated

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

No branches or pull requests