Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Deeper defaults for parameters in body #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

farrago
Copy link

@farrago farrago commented Dec 7, 2015

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.

Body parameters (`in` is `"body"`) are always grouped in a single Object,
and as such there is only the option to set a `default` for the whole
body (or none).

This change looks deeper into the object for `default`s to support more
flexible configuration of expected parameters in `body`.  This brings
the body support closer to e.g. `path` which already supports multiple
parameters.

This change will look for defaults 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: 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.

Test Plan:
- Test that `gulp` runs and passes, ensuring:
-- new code passes lint rules
-- existing unit tests all run and pass
- Add new tests for testing the new features, and confirm all pass.
- Check the code coverage, and verify that (almost) all new lines have
  been covered.
-- The only new lines not being covered is the exclusion of Swagger 1.2
   schemas, which has only been checked visually.
@confuser
Copy link

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

@whitlockjc
Copy link
Member

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

@dt-atkinson
Copy link

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

@atlanteh
Copy link

atlanteh commented Jun 8, 2020

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

@atlanteh
Copy link

atlanteh commented Jun 9, 2020

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

  • parameters that have schema prop with allOf
  • Arrays

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants