Description
I have an OpenAPI customizer that appends a special path suffix to server URLs. It works fine and shows proper values in UI in "Servers" dropdown. Upon page refresh, dropdown values reset to un-customized ones.
Spring Boot 2.5.7
SpringDoc 1.5.12
The problem is in AbstractOpenApiResource.getOpenApi()
function. When it loads for the first time, there's no cached OpenAPI
instance so full initialization goes through and runs
openApiCustomisers.ifPresent(apiCustomisers ->
apiCustomisers.forEach(openApiCustomiser ->
openApiCustomiser.customise(openApi)));
On a subsequent reload however, there's a cached version and the code goes straight into
openApi = openAPIService.updateServers(openAPIService.getCachedOpenAPI());
that overrides correct, customized servers with a new "generated" version and does not run any customization.
I don't know why would it be needed to overwrite servers in cached OpenAPI but if that's indeed required, I'd expect customization to be applied again. Otherwise /api-docs
returns different responses on the first vs further calls.
Workaround: disable cache but load times increase depending on the complexity of your project.