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

path-params rule incorrectly flags parameter override definitions as duplicate #1416

Closed
wjwilkie opened this issue Dec 8, 2020 · 1 comment · Fixed by #1417
Closed

path-params rule incorrectly flags parameter override definitions as duplicate #1416

wjwilkie opened this issue Dec 8, 2020 · 1 comment · Fixed by #1417
Assignees
Labels
t/bug Something isn't working

Comments

@wjwilkie
Copy link

wjwilkie commented Dec 8, 2020

Describe the bug
According to the OpenAPI Specification regarding Operation Parameters:
"A list of parameters that are applicable for this operation. If a parameter is already defined at the Path Item, the new definition will override it but can never remove it. The list MUST NOT include duplicated parameters."

However the "path-params" rule incorrectly identifies the scenario where the parameter definition exists both at the path and the operation level as a duplicate instead of a valid override.

Disabling the "path-params" rule is not a suitable long-term workaround because the rule does provide valuable validation to identify duplication scenarios where the same path parameter name is defined twice within the same parameter list at either the path or operation level.

To Reproduce
The following test could be added to oasPathParam.test.ts to demonstrate the failure.

  test('No error if path parameter definition has override at the operation level', async () => {
    const results = await s.run({
      paths: {
        '/foo/{bar}': {
          parameters: [
            {
              name: 'bar',
              in: 'path',
              required: true,
              description: 'Shared common parameter.'
            },
          ],
          get: {
            parameters: [
              {
                name: 'bar',
                in: 'path',
                required: true,
                description: 'Operation level parameter.'
              },
            ],
          },
        },
      },
    });

    expect(results).toHaveLength(0);
  });

Expected behavior
Spectral should not produce a lint error when a valid parameter override exists in the API definition.

@wjwilkie wjwilkie added the t/bug Something isn't working label Dec 8, 2020
@P0lip P0lip self-assigned this Dec 9, 2020
@P0lip
Copy link
Contributor

P0lip commented Dec 9, 2020

Hey!
Thanks a whole lot for a detailed report and the provided test case.
I agree it's an issue on our side and will fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants