daveshanley / vacuum

vacuum is the worlds fastest OpenAPI 3, OpenAPI 2 / Swagger linter and quality analysis tool. Built in go, it tears through API specs faster than you can think. vacuum is compatible with Spectral rulesets and generates compatible reports.
https://quobix.com/vacuum
MIT License
580 stars 48 forks source link

Ensure `path-params` rules finds missing parameters #436

Closed mehdi-sol closed 8 months ago

mehdi-sol commented 8 months ago

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

Example 1

```yaml 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

```yaml 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.