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.html is not found - HTTP404 #402

Closed
vilmosnagy opened this issue Feb 4, 2020 · 6 comments
Closed

swagger-ui.html is not found - HTTP404 #402

vilmosnagy opened this issue Feb 4, 2020 · 6 comments
Labels
question Further information is requested

Comments

@vilmosnagy
Copy link

TLDR: this is the duplicate of the issue #361, but:

  • the solution there (start the app differently from IntelliJ) did not solve my issue
  • I was able to create an MCVE

Describe the bug
I do run spring-boot 2.2.2-RELEASE with springdoc-openapi-webflux-ui 1.2.29.

The following requests give me the following statuses:

[vilmosnagy@vnagy-dell hkir-trip-planner]$ curl -sD - http://localhost:8080/v3/api-docs/swagger-config  && echo 
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 119

{"configUrl":"/v3/api-docs/swagger-config","oauth2RedirectUrl":"/swagger-ui/oauth2-redirect.html","url":"/v3/api-docs"}
[vilmosnagy@vnagy-dell hkir-trip-planner]$ curl -sD - http://localhost:8080/v3/api-docs   && echo 
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 719

{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers":[{"url":"http://localhost:8080","description":"Generated server url"}],"paths":{"/v1/test":{"post":{"tags":["example-controller"],"operationId":"getPlanForParameter","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExampleRequest"}}}},"responses":{"200":{"description":"default response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExampleResponse"}}}}}}}},"components":{"schemas":{"ExampleRequest":{"type":"object","properties":{"id":{"type":"string"}}},"ExampleResponse":{"type":"object","properties":{"id":{"type":"string"},"count":{"type":"integer","format":"int32"}}}}}}
[vilmosnagy@vnagy-dell hkir-trip-planner]$ curl -sD - http://localhost:8080/swagger-ui.html  && echo 
HTTP/1.1 307 Temporary Redirect
Location: /webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config
content-length: 0


[vilmosnagy@vnagy-dell hkir-trip-planner]$ curl -sD - http://localhost:8080/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config  && echo 
HTTP/1.1 404 Not Found
Content-Type: application/json
Content-Length: 155

{"timestamp":1580836491212,"path":"/webjars/swagger-ui/index.html","status":404,"error":"Not Found","message":"No matching handler","requestId":"ed2cc66d"}
[vilmosnagy@vnagy-dell hkir-trip-planner]$ 

(TLDR: it's the same as in the mentioned issue, the swagger-ui.html redirects me somewhere, and that page does not load)

To Reproduce
Steps to reproduce the behavior:

Expected behavior

  • I shall see the swagger IO at that location

Screenshots
Nothing extraordinary, the standard Spirng-Boot error page.
image

Additional context
My problem is the same as in #361, but I was able to create an MVCE.

@bnasslahsen
Copy link
Contributor

Hi @vilmosnagy,

As stated in the Spring Boot reference documentation, when you use @EnableWebFlux, you tell Spring Boot that you wish to take full control over the WebFlux configuration and disable all auto-configuration for this (including static resources):

You have two solutions:

  • Remove @EnableWebFlux
  • If you really want take control of Bean creation and you want absolutely to use @EnableWebFlux, then you need to add an implementation of WebFluxConfigurer.
    Here is a sample code:
@Configuration
public class WebConfig  implements WebFluxConfigurer {
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/webjars/**")
				.addResourceLocations(CLASSPATH_RESOURCE_LOCATION+"/webjars/")
				.resourceChain(true)
				.addResolver(new WebJarsResourceResolver());
	}
}

@vilmosnagy
Copy link
Author

Thanks for the quick reply.

@kanai0618
Copy link

Hi @bnasslahsen , i used
@configuration
public class WebConfig implements WebFluxConfigurer {
@OverRide
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/webjars/**")
.addResourceLocations(CLASSPATH_RESOURCE_LOCATION+"/webjars/")
.resourceChain(true)
.addResolver(new WebJarsResourceResolver());
}
}
still i am getting 404. and in my spring boot , in pattern o.s.c.g.h.p.RoutePredicateFactory : Pattern, it doesnot find any swagger path. can you help ?

@bnasslahsen
Copy link
Contributor

@kanai0618,

I don't know the context of your question, which is not clear and the code is not even formatted.
Unfortunately, i cannot help you without any relevant information.

Please follow the contribution guidelines.
You have guidance and demos for spring-weblfux.
And if you are not able to make it, please help us speed up problem diagnosis by providing as much information as described in the guidelines.

@kanai0618
Copy link

kanai0618 commented Dec 30, 2020

Hi @bnasslahsen , sorry for the typing issue.

So i am using spring cloud gateway in my code. and i have included

  <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-webflux-ui</artifactId>
            <version>1.5.2</version>
        </dependency>

and i am able to load this

http://localhost:8080/webjars/swagger-ui/index.html - ( by default https://petstore.swagger.io/v2/swagger.json)

but when i actually try to load my swagger endpoint (v3/api-docs), it gives me error. ( http://localhost:8080/v3/api-docs) 404. not found.
image

hope you understand the issue.

@bnasslahsen
Copy link
Contributor

bnasslahsen commented Dec 30, 2020

@kanai0618,

You have here a fully working sample of spring cloud gateway.
You can see the Piotrminkowski Blog for detailed instructions

And if you are still struggling, please make sure you Provide a Minimal, Reproducible Example - with HelloController that reproduces the problem

@bnasslahsen bnasslahsen added the question Further information is requested label Jan 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants