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

Explicit Mapping for swagger-ui.html #2078

Closed
gborges0727 opened this issue Oct 26, 2017 · 7 comments
Closed

Explicit Mapping for swagger-ui.html #2078

gborges0727 opened this issue Oct 26, 2017 · 7 comments
Labels

Comments

@gborges0727
Copy link

I have a small issue. On my project, I have a route that expects a parameter in the path

Example: localhost.com/serverContext/{parameter}

This presents an issue when trying to access swagger-ui, as when I try to hit the swagger-ui URL, locahost.com/serverContext/swagger-ui.html, spring complains, saying it does not match the {parameter} specification. Is there a way to explicitly define a mapping for swagger-ui.html, so that spring knows when I put it in the URL to hit the page and not treat it as me putting the value in as a parameter?

I've tried changing the mapping to swagger-ui (i.e. putting it behind /documentation), as described in issue 1080, (#1080), however this presents a new issue with the serverContext being mapped to a different path, so I'm trying to avoid any complexities there.

Any help is appreciated. Thanks!

@dilipkrish
Copy link
Member

In your case you should simply point to locahost.com/swagger-ui.html for swagger ui

@gborges0727
Copy link
Author

gborges0727 commented Oct 26, 2017

How do I have swagger ignore the servercontext? This would also not work, as the same base URL is used to map to different APIs for my purpose.

@dilipkrish
Copy link
Member

I see... can't say without looking at the code. But the springfox-demo does exactly that. It creates a context path springfox instead of servercontext

@gborges0727
Copy link
Author

So in that example project you have server.contextPath=/springfox. In my project, I'm doing something very similar where my server.contextPath=/serverContext

@gborges0727
Copy link
Author

I found a way to solve the issue by making the path parameter more explicit so that it wouldn't try to include swagger-ui.html

@ghost ghost removed the current label Oct 26, 2017
@dilipkrish
Copy link
Member

@gborges0727 Would you mind sharing your way, just so it might help someone else with the same problem you had?

@gborges0727
Copy link
Author

Sure. So I know for my {parameter} I expect a number. I simply defined that path mapping explicitly with a regex to expect a number, by doing:
@RequestMapping(value="/{parameter:\\d+}", method=RequestMethod.GET)
In this way, spring doesn't complain when I try to hit swagger-ui.html. In theory, if this issue is faced by somebody, you could make your parameter definition explicit using a regex so that there is no conflict when trying to hit swagger-ui.html

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

2 participants