Skip to content

OpenApiCustomiser duplicates header fields after browser refresh in springdoc-open-api version >1.6.9 #1837

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
ghost opened this issue Sep 7, 2022 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@ghost
Copy link

ghost commented Sep 7, 2022

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:

  1. go to swagger-ui with browser
  2. open some api-path and check that customised headers are visibile
  3. refresh page i.e. press +
  4. go back to same path and then there's duplicates
  5. 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

@bnasslahsen
Copy link
Collaborator

@alpertti,

This is a duplicate of #1820
You can test the fix with the latest SNAPSHOT

@bnasslahsen bnasslahsen added the duplicate This issue or pull request already exists label Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

1 participant