swagger-tools icon indicating copy to clipboard operation
swagger-tools copied to clipboard

Deeper defaults for parameters in body

Open farrago opened this issue 9 years ago • 5 comments
trafficstars

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.

farrago avatar Dec 07 '15 15:12 farrago

@whitlockjc Any chance this could be merged in? Seems to fix default body values as mentioned in #421

confuser avatar Jul 15 '17 16:07 confuser

I'll merge it in when I am planning the next release. That should be soon.

whitlockjc avatar Jul 17 '17 22:07 whitlockjc

@whitlockjc this is still an issue - do you intend to merge this or is there another way you want to do it?

dt-atkinson avatar Oct 11 '18 11:10 dt-atkinson

We're stuck on this as well. Can this be merged?

atlanteh avatar Jun 08 '20 21:06 atlanteh

Actually I tested this and this doesn't work for :

  • parameters that have schema prop with allOf
  • Arrays

atlanteh avatar Jun 09 '20 14:06 atlanteh