Skip to content

Ensure path-params rules finds missing parameters#436

Merged
daveshanley merged 1 commit intodaveshanley:mainfrom
mehdi-sol:issue-435-fix
Jan 30, 2024
Merged

Ensure path-params rules finds missing parameters#436
daveshanley merged 1 commit intodaveshanley:mainfrom
mehdi-sol:issue-435-fix

Conversation

@mehdi-sol
Copy link
Copy Markdown

This PR should solve Issue #435.
Currently, vacuum does not find pick up errors with the two following examples.

Example 1

Details
openapi: 3.0.3
info:
  description: Pizza
  title: Pizza API
  version: 1.0.0
paths:
  /pizza/{type}/{topping}:
    parameters:
      - name: type
        description: Pizza type.
        in: path
        required: true
        schema:
          type: string
    get:
      operationId: get_pizza
      summary: summary
      description: description
      responses:
        '204':
          description: no description

Example 2

Details
openapi: 3.0.3
info:
  description: Pizza
  title: Pizza API
  version: 1.0.0
paths:
  /pizza/{type}/{topping}:
    parameters:
      - name: type
        description: Pizza type.
        in: path
        required: true
        schema:
          type: string
    post:
      parameters:
        - name: topping
          description: Pizza topping.
          in: path
          required: true
          schema:
            type: string
      operationId: make_pizza
      summary: summary
      description: description
      responses:
        '204':
          description: no description

    get:
      operationId: get_pizza
      summary: summary
      description: description
      responses:
        '204':
          description: no description
The first example is failing because `ensureAllExpectedParamsInPathAreDefined` is skipping over `top`. The second example fails because `ensureAllExpectedParamsInPathAreDefined` doesn't take `verb` into account when checking for parameters.

This PR makes sure ensureAllExpectedParamsInPathAreDefined goes over all the expected path parameters and checks both the top-level and the verb-level parameters. I've also added test cases for these scenarios.

Copy link
Copy Markdown
Owner

@daveshanley daveshanley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for your contribution.

@daveshanley daveshanley merged commit 6e6e034 into daveshanley:main Jan 30, 2024
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

Successfully merging this pull request may close these issues.

2 participants