fix: refactor toOperations to read path level parameter definitions #301
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We noticed that the docs don't always display a box with the required path params for an operation. v1 operations don't display it while v2 do:


Diving a little deeper we realize that it's just a difference between on where the path params are defined between versions. The
toOperationsfunction currently expects all parameters, query and path, to be included in theparametersfield of the operation. Meaning:{ "paths": { "/packages/{package_slug_perm}/vulnerabilities/osv/": { "get": { "parameters": [ { "in": "path", "name": "package_slug_perm", "schema": { "type": "string", "pattern": "^[a-zA-Z0-9]+$" }, "required": true } ] } } } }Which is true for the V2 schema definition, but not for the V1. V1 seems to only include query params at that level, while path params are defined at the path level. Meaning:
{ "paths": { "/audit-log/{owner}/": { "get": { "parameters": [ { "name": "page", "in": "query", "description": "A page number within the paginated result set.", "required": false, "schema": { "type": "integer" } } ] }, "parameters": [ { "name": "owner", "in": "path", "required": true, "schema": { "type": "string" } } ] }, }This PR refactors
toOperationsto handle this option. It now does so by and keeping track of operations being parsed and organizing them based on path. Whenever a path level parameter definition is found, it's saved and updates any already processed operations for that path. And whenever an operation is processed, it checks for any found parameters for that path and includes them into the operation.This not only fixes the display of the path params box in the site, but also make path params definitions available for all operations. A necessary piece for the API Sandbox work.