apinf / openapi-designer

Design interface for creating Open API (Swagger) specification files
https://openapi.design
MIT License
69 stars 18 forks source link

Fix lookup of global path param references in path definitions #365

Closed carlevans719 closed 5 years ago

carlevans719 commented 5 years ago

Great project - thanks!

This is a partial fix for #354.

Steps to repro the issue:

  1. With a fresh, empty spec, add a parameter to the Definitions tab
    • location should be "path"
    • name should be "test"
  2. Add a path which includes the param in it - e.g. "/{test}"
  3. Start filling out a method for the path - e.g. add a description to the "get" method
  4. Add a parameter with a type of "reference" to the method and select the "test" parameter
  5. In the Javascript console, note the exception raised as a result of this line (attempting to call getValue() on undefined)

Alternatively, just use this spec.

This patch changes the behaviour of the parseParamRef function. First it grabs the "Parameters" field. Then it iterates over the child fields (which are parameter definitions) and it returns as soon as it finds one which matches the name in the path.

I noticed that the path is still flagged as invalid if the parameter reference is added after the path is set but it works the other way round (adding the parameter then changing the path) so I think there's somewhere else I need to tweak too but I'm not sure where it is. Any pointers would be really appreciated!