Skip to content
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

Duplicated header values when an endpoint can be called with different headers #1801

Closed
didjoman opened this issue Aug 18, 2022 · 0 comments
Closed

Comments

@didjoman
Copy link

Describe the bug

If a controller has an endpoint that can be called with different possible headers (key + value), then in the doc generated, in the parameters, the possible values for the headers appear twice.

How to reproduce

(Using Java 11, SpringBoot 2.7.2, springdoc-openapi-webmvc-core 1.6.10 based on Swagger-core 2.2.2)
git clone https://github.com/didjoman/springdoc-double-headers-issue
Run the application (spring boot).
Run curl --location --request GET 'http://localhost:8080/doc' --header 'Content-Type: application/json'

Expected behavior

We should obtain a schema like this, without duplication of the enum values of the parameters.

{
    "openapi": "3.0.1",
    "info": {
        "title": "OpenAPI definition",
        "version": "v0"
    },
    "servers": [
        {
            "url": "http://localh",
            "description": "Generated server url"
        }
    ],
    "paths": {
        "/": {
            "get": {
                "tags": [
                    "basic-controller"
                ],
                "operationId": "get1_1_1",
                "parameters": [
                    {
                        "name": "foo",
                        "in": "header",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "bar"
                            ]
                        }
                    },
                    {
                        "name": "fi",
                        "in": "header",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "ri"
                            ]
                        }
                    },
                    {
                        "name": "User-Agent",
                        "in": "header",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "MyUserAgent"
                            ]
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "*/*": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {}
}

Actual behavior

Today, the possible values of the headers other than the first one get duplicated.

{
    "openapi": "3.0.1",
    "info": {
        "title": "OpenAPI definition",
        "version": "v0"
    },
    "servers": [
        {
            "url": "http://localh",
            "description": "Generated server url"
        }
    ],
    "paths": {
        "/": {
            "get": {
                "tags": [
                    "basic-controller"
                ],
                "operationId": "get1_1_1",
                "parameters": [
                    {
                        "name": "foo",
                        "in": "header",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "bar"
                            ]
                        }
                    },
                    {
                        "name": "fi",
                        "in": "header",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "ri",
                                "ri"
                            ]
                        }
                    },
                    {
                        "name": "User-Agent",
                        "in": "header",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "MyUserAgent",
                                "MyUserAgent"
                            ]
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "*/*": {
                                "schema": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {}
}

Additional context

/

bnasslahsen added a commit that referenced this issue Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant