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

Reverse proxy context path aware support for manually provided files #1453

Closed
JSimo opened this issue Jan 20, 2022 · 5 comments
Closed

Reverse proxy context path aware support for manually provided files #1453

JSimo opened this issue Jan 20, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@JSimo
Copy link

JSimo commented Jan 20, 2022

Is your feature request related to a problem? Please describe.

  • Trying to configure springdoc to serve a custom openapi.json file behind a reverse proxy. Where the default page should have that file be selected in a context path aware manner.
  • When the property springdoc.swagger-ui.url is set to /openapi.json I expect the path to be context path aware. Similar to how the normal api-docs is handled.

Describe the solution you'd like

  • When defining a local url / file in the springdoc.swagger-ui.url i expect it to handle being served behind a reverse proxy.
    (of course given that the reverse proxies sets the correct headers X-Forwarded-Prefix / similar.)
  • Expanding on it; When defining a local file/url in springdoc.swagger-ui.url it is expected that such a url is handled in a context path aware manner.

Describe alternatives you've considered
I've considered hacks around it, such as defining the static file with the prefix of the reverse proxy in it. But that means any local testing will not work.

Looking into the code I have considered changing the following method somehow as that is where the url is being modified. And from what I can see it might be possible to do something around String swaggerUiUrl = swaggerUiConfig.getUrl(); line to handle it in a similar way as done in buildApiDocUrl().

AbstractSwaggerWelcome.java

protected void buildConfigUrl(UriComponentsBuilder uriComponentsBuilder) {
		if (StringUtils.isEmpty(swaggerUiConfig.getConfigUrl())) {
			apiDocsUrl = buildApiDocUrl();
			swaggerConfigUrl = buildSwaggerConfigUrl();
			swaggerUiConfigParameters.setConfigUrl(swaggerConfigUrl);
			if (CollectionUtils.isEmpty(swaggerUiConfigParameters.getUrls())) {
				String swaggerUiUrl = swaggerUiConfig.getUrl();
				if (StringUtils.isEmpty(swaggerUiUrl))
					swaggerUiConfigParameters.setUrl(apiDocsUrl);
				else
					swaggerUiConfigParameters.setUrl(swaggerUiUrl);
			}
			else
				swaggerUiConfigParameters.addUrl(apiDocsUrl);
		}
		calculateOauth2RedirectUrl(uriComponentsBuilder);
	}

Additional context
Also would be fine with any other possibilities such as a flag to make ``springdoc.swagger-ui.url` context aware or any suggestions!

@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 20, 2022
@bnasslahsen
Copy link
Contributor

@JSimo,

Please feel free to validate this enhancement using the latest SNAPSHOT.

@JSimo
Copy link
Author

JSimo commented Jan 21, 2022

@JSimo,

Please feel free to validate this enhancement using the latest SNAPSHOT.

Awesome!
I can confirm in my local testing it works. Nginx + local testing. Very impressed by your speed for this. ❤️

How often do you do releases? :)

@bnasslahsen
Copy link
Contributor

@JSimo ,

Ideally, by the end of this week!

@JSimo
Copy link
Author

JSimo commented Jan 25, 2022

@JSimo ,

Ideally, by the end of this week!

Got a new estimate for a release? :)
edit: to be clear, in no hurry. Just trying to close projects I'm working on.

@bnasslahsen
Copy link
Contributor

@JSimo,

It's done !

@springdoc springdoc locked as resolved and limited conversation to collaborators Jan 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants