swagger-tools
swagger-tools copied to clipboard
Deeper defaults for parameters in body
Body parameters (in is "body") are always grouped in a single object, and as such there is no way to set defaults for some of the parameters nested inside that body[1].
This change looks deeper into the object for default values of the parameters rather than just the overall body. This is to support more flexible configuration of expected parameters in body, and brings the body support closer to ae.g. path which already supports multiple parameters.
This change will look for default parameter values for all object type parameters. This is also recursive, so if an object has a parameter that is an object then this code will look for defaults in that nested object.
Note [1]: with the current code, it's not even possible to set a default for the whole body's schema. Defaults are only looked for in parameter.default, but body defaults would be in parameter.schema.default (see helpers.js:getParameterValue()) . This has not been changed in the this pull request.
Note [2]: this has only been implemented for Swagger 2.0 as I am not familiar with Swagger 1.2, so felt it best to leave 1.2 as-is.
@whitlockjc Any chance this could be merged in? Seems to fix default body values as mentioned in #421
I'll merge it in when I am planning the next release. That should be soon.
@whitlockjc this is still an issue - do you intend to merge this or is there another way you want to do it?
We're stuck on this as well. Can this be merged?
Actually I tested this and this doesn't work for :
- parameters that have schema prop with
allOf - Arrays