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

Operation query parameter descriptions should override path item query parameter descriptions, and not be validated in addition to them #626

Closed
cd-rite opened this issue Jun 22, 2021 · 1 comment

Comments

@cd-rite
Copy link
Contributor

cd-rite commented Jun 22, 2021

Describe the bug
When an Operation parameter is defined with the same name as an applicable Path item parameter, parameters in requests are being validated against BOTH parameter schemas. According to the OpenAPI spec, the Operation level parameter should override the path item parameter, not be in addition to.

https://swagger.io/docs/specification/describing-parameters/
https://spec.openapis.org/oas/v3.1.0#operation-object

To Reproduce
Create a spec with a parameter defined at the path level, and a parameter with the same name for an operation under that path.

Actual behavior
Requests are validated against BOTH definitions of the parameter, rather than just the operation one.

Expected behavior
Requests will be validated against just the operation level schema, as by my reading of the openAPI Spec it should override the path level definition.

Examples and context

This seems to be an issue with the way the applicable parameter validation schema arrays are accumulated during preprocessing.

I think the preprocessPathLevelParameters function in the schema.preprocessor parser should only add path level parameters to the v.parameters array if there is not already an existing parameter definition by that name in the array.

I get the behavior I expect if I change this loop to this:

for (const param of parameters) {
    //skip adding path param if operation param already exists.
    if (!(v.parameters.some(vparam => vparam.name === param.name))){
        v.parameters.push(param);
    }
}

(Not sure if that's valid typescript.... I made my change in the node module)

@cd-rite
Copy link
Contributor Author

cd-rite commented Jun 23, 2021

Also, just to be clear, I am talking about Query parameters specified at the path and operation levels, not parameters actually IN the path.

@cd-rite cd-rite changed the title Operation parameters should override path item parameters, not be in addition to them Operation query parameter descriptions should override path item query parameter descriptions, and not be validated in addition to them Jul 6, 2021
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