-
-
Notifications
You must be signed in to change notification settings - Fork 548

Description
Describe the bug
When OpenApiCustomiser is in use for adding some common header fields to all endpoints, these fields get duplicated in swagger ui and open-api json after browser refresh. This bug is present in versions 1.6.10 and 1.6.11.
To Reproduce
Steps to reproduce the behavior:
-
What version of spring-boot you are using?
2.7.3 -
What modules and versions of springdoc-openapi are you using?
org.springdoc:springdoc-openapi-ui:1.6.11
org.springdoc:springdoc-openapi-data-rest:1.6.11 -
What is the actual and the expected result using OpenAPI Description (yml or json)?
Actual (tested with 1.6.10 and 1.6.11):
"/foo/bar":{"get":{"tags":["Foo"],"operationId":"getBar","parameters":[{"name":"barId","in":"path","required":true,"schema":{"type":"string"}},{"name":"foo","in":"header","description":"foo","required":true,"example":"foo"},{"name":"bar","in":"header","description":"bar","required":true,"example":"bar"},{"name":"foo","in":"header","description":"foo","required":true,"example":"foo"},{"name":"bar","in":"header","description":"bar","required":true,"example":"bar"}},{"name":"foo","in":"header","description":"foo","required":true,"example":"foo"},{"name":"bar","in":"header","description":"bar","required":true,"example":"bar"},{"name":"foo","in":"header","description":"foo","required":true,"example":"foo"},{"name":"bar","in":"header","description":"bar","required":true,"example":"bar"}],"responses"
..
Expected (this is from version 1.6.9):
"/foo/bar":{"get":{"tags":["Foo"],"operationId":"getBar","parameters":[{"name":"barId","in":"path","required":true,"schema":{"type":"string"}},{"name":"foo","in":"header","description":"foo","required":true,"example":"foo"},{"name":"bar","in":"header","description":"bar","required":true,"example":"bar"}],"responses":
..
- Provide with a sample code (HelloController) or Test that reproduces the problem
Unfortunately, I don't have HelloController at hand right now, so if it's needed please ask. However, there's an example Configuration code:
@Bean
public OpenAPI fooOpenAPI() {
return new OpenAPI()
.info(new Info().title("Foo API Documentation").version("v1.0.0"));
}
@Bean
public OpenApiCustomiser headerOpenApiCustomiser() {
return openApi -> openApi.getPaths().values().stream()
.flatMap(pathItem -> pathItem.readOperations().stream())
.forEach(operation -> {
operation.addParametersItem(
new HeaderParameter().required(true).description("foo").name("foo")
.example("foo"));
operation.addParametersItem(
new HeaderParameter().required(true).description("bar").name("bar")
.example("bar"));
});
}
@Bean
public GroupedOpenApi commonApi() {
return GroupedOpenApi.builder()
.group("common")
.addOpenApiCustomiser(headerOpenApiCustomiser())
.packagesToScan("org.common")
.build();
}
@Bean
public GroupedOpenApi adminApi() {
return GroupedOpenApi.builder()
.group("admin")
.addOpenApiCustomiser(headerOpenApiCustomiser())
.packagesToScan("org.admin")
.build();
}
To reproduce with similar configuration than above:
- go to swagger-ui with browser
- open some api-path and check that customised headers are visibile
- refresh page i.e. press +
- go back to same path and then there's duplicates
- by repeating this, you get one new pair of headers on every cycle
Expected behavior
Headers added by customiser are visibile only once all the time