-
-
Notifications
You must be signed in to change notification settings - Fork 500
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
Cannot override servers
in api-docs.yaml
using OpenApiCustomiser
#1188
Comments
Given that
I would like to know if there is a workaround that could do the reverse as is requested in the issue, i.e., when I am setting servers in the main |
Version 1.5.10 @bnasslahsen I still cannot override the auto-generated server URLs section in the YAML file using customizer, if the server URL is NOT specified in However, strangely enough, when this happens, the auto generated JSON file contains the overriding URL (i.e., this is what I want), but the YAML file contains the auto-generated server URL. |
Not reproducible. Working in both json and yaml. And if you believe you are facing an issue, make sure you provide a Minimal, Reproducible Example - with HelloController that reproduces the problem |
@bnasslahsen https://github.com/vchen8761/spring-doc-server-field-test |
@bnasslahsen Please have a look at the reprex above from my coworker. It seems that the first time when the doc is loaded, it has the intended behavior (custom URL in customizer). However, after a refresh, it rolls back to the randomly generated one. It turns out that both JSON and YAML are inconsistent after a refresh, so when I downloaded both programmatically, the first downloaded got the custom URL and the second got the randomly generated one. |
Describe the bug
I cannot override the
servers
field inapi-docs.yaml
using aOpenApiCustomiser
@Bean
, while other fields likeinfo.version
seem to work well with this approach, theservers
remains the auto generated value.To Reproduce
Spring Boot 2.4.5
'org.springdoc:springdoc-openapi-ui:1.5.9'
I have a class in
src/main
annotated with@OpenAPIDefinition
,servers
parameter is not set in this annotation. I cannot paste all the codes here, but it is basically like this:In my integration test, there is such a config class:
In the generated YAML file,
version
is "v1" butservers
:Expected behavior
Screenshots
No.
Additional context
The main codes will serve the Swagger UI, documentation, etc. at runtime so I do not want to mess up with its own config. However, during the integration test, I'd like to "download" the YAML file so I can publish it somewhere using the build pipeline. I do not want this file to contain the random port server URL in the integration test.
So far as I am aware of, there are 3 ways that I can set this
servers
field in the YAML file:@OpenAPIDefinition
.@Bean OpenAPI
.@Bean OpenApiCustomiser
.And I have two different source sets (
main
and integration tests). I want my application to use the generated URL when serving the Swagger UI, but let it use a fixed, hard-coded server URL in the YAML file when running integration tests so I can "download" the YAML file that does not contain a random server URL.Other things I tried:
@Bean OpenAPI
in themain
config class, instead of using@OpenAPIDefinition
, then use the same customizers (in bothmain
and integration tests). This does NOT work.info
,tags
,servers
, etc.) in a single@Bean OpenAPI
in the integration test config class (i.e., without using any customizer). This works as expected. However, this requires me to use two different@Bean OpenAPI
, one inmain
and one in integration tests, which can cause some additional confusions.servers
in the main@OpenAPIDefinition
to contain oneServer
, then the customizer in integration tests works as expected (i.e., it can override the settings I put in@OpenApiDefinition
). However, just an experiment: This makes the server URL hardcoded. Even if I setservers
toList.of()
(empty list) later in a customizer, there is no generated URL in the YAML file.Some of my guesses, no need to take it serious -- It seems that at some point
@Bean OpenAPI
or@OpenAPIDefinition
(whichever is used) takes effect,@Bean OpenApiCustomiser
customisers take effect,It tries to detect if
servers
is empty -- if it is not, then it is serving the YAML file containing theservers
. However, if it is empty, it is serving the YAML file withservers
set to the generated URL, IGNORINGservers
in theOpenAPI
object permanently, which makes it impossible to change the behavior by modifyingOpenAPI.servers
later in the customisers.The text was updated successfully, but these errors were encountered: