Skip to content

Duplicated operation parameters generated for endpoints with multiple consuming media types  #708

Closed
@valentinabojan

Description

@valentinabojan

Hi,

I have 2 endpoints that differ only by the media type they consume. From #71 I understand that this kind of scenario is well supported by springdoc-openapi. I use the latest 1.4.0 version on springdoc-openapi.

@PostMapping(value = "/search", consumes = APPLICATION_JSON_VALUE)
public ResponseDto search(@RequestBody RequestDto searchRequestDto) {
    ...
}

@PostMapping(value = "/search", consumes = MULTIPART_FORM_DATA_VALUE)
public ResponseDto searchByFile(@RequestParam(value = "file") MultipartFile file) {
    ...
}

Indeed, looking in the generated swagger-ui I see the /search operation with a select box containing the 2 media types, which is what I wanted to get.

However, because I have a configuration that adds 2 header parameters to every operation, for the above /search endpoint I will have the 2 header parameters duplicated in the generated docs.

@Bean
public OperationCustomizer customize() {
    return (operation, handlerMethod) -> operation
        .addParametersItem(
            new Parameter()
                .in("header")
                .required(true)
                .name("My header param 1")
                .schema(new Schema<String>().type("string")))
        .addParametersItem(
            new Parameter()
                .in("header")
                .required(false)
                .name("My header param 2")
                .schema(new Schema<String>().type("string")));
}

This is how the generated json looks like:

{
  "paths": {
    "/search": {
      "post": {
        "operationId": "search_1",
        "parameters": [
          {
            "name": "My header param 1",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "My header param 2",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "My header param 1",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "My header param 2",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
        }
      }
    }
  }
}

Is this a known issue? Am I missing something?
Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions