Skip to content

Allow OpenAPI customizers to run even for cached OpenAPI documents #2171

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
emilchitas opened this issue Mar 27, 2023 · 2 comments
Closed

Allow OpenAPI customizers to run even for cached OpenAPI documents #2171

emilchitas opened this issue Mar 27, 2023 · 2 comments
Labels
question Further information is requested

Comments

@emilchitas
Copy link

emilchitas commented Mar 27, 2023

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

We have a service which is accessible through a wildcard domain (*.example.com), and users can access this system with some specific prefixes (e.g. prefixA.example.com, prefixB.example.com).
When serving the OpenAPI document, we make use of the OpenAPICustomizer(s) to customize the server URL to also include the common path of the APIs present in that document.
image
This was possible, until the logic to be able to customize also cached OpenAPI documents was reverted with this PR.
Now, even if a client would access the document with the https://prefixB.example.com, it would be served the cached OpenAPI with the https://prefixA.example.com/my/foo server URL, which was generated when it was first accessed.

Describe the solution you'd like

  • We would like to have the possibility to register some customizer which would run also for cached OpenAPI's.

Describe alternatives you've considered

  • This can be worked around by disabling the cache, but generating the whole OpenAPI on each request gets pretty expensive, the more this grows.
@bnasslahsen
Copy link
Collaborator

@emilchitas,

You can use ServerBaseUrlCustomizer.
Cache is not applied to it.

This is a sample code:

	@Bean
	ServerBaseUrlCustomizer serverBaseUrlCustomizer(){
		return serverBaseUrl -> serverBaseUrl.replace(serverBaseUrl,  UUID.randomUUID().toString());
	}

@bnasslahsen bnasslahsen added the question Further information is requested label Mar 28, 2023
@emilchitas
Copy link
Author

Thanks.
This fits well for our use case.

@springdoc springdoc locked as resolved and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants