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

Optional query parameters are added three times to OpenAPI spec #92

Open
duharound opened this issue Oct 4, 2024 · 1 comment
Open

Comments

@duharound
Copy link

When annotating an optional query parameter like

ENDPOINT_INFO(getEndpoint)
  {
    info->queryParams.add<String>("param").description =
        "(optional) Query parameter";
    info->queryParams.add<String>("param").required        = false;
    info->queryParams.add<String>("param").allowEmptyValue = true;
  }
  ENDPOINT("GET", "/test", getEndpoint, QUERIES(QueryParams, queryParams))

the parameter gets added three times to the OpenAPI spec at /api-docs/oas-3.0.0.json:

        "parameters": [
          {
            "name": "param",
            "description": "(optional) Query parameter",
            "in": "query",
            "required": false,
            "deprecated": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "param",
            "description": "(optional) Query parameter",
            "in": "query",
            "required": false,
            "deprecated": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "param",
            "description": "(optional) Query parameter",
            "in": "query",
            "required": false,
            "deprecated": false,
            "schema": {
              "type": "string"
            }
          }
        ]

This interferes with some automated schema checks as for example used in https://github.com/openapi-generators/openapi-python-client, such that two of the three parameters need to be manually removed.

@i96751414
Copy link

i96751414 commented Nov 8, 2024

That happens because you are calling info->queryParams.add<String>("param") three times. Try using operator [] for editing the param instead, that is, info->queryParams["param"].

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

2 participants