Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defaults in nested oneOf aren't being populated #594

Closed
kiahnjl opened this issue May 5, 2021 · 2 comments
Closed

Defaults in nested oneOf aren't being populated #594

kiahnjl opened this issue May 5, 2021 · 2 comments
Labels

Comments

@kiahnjl
Copy link

kiahnjl commented May 5, 2021

Describe the bug
This only seems to be an issue when using oneOf nested inside a field or an array (i.e not at the top-level) AND where a oneOf subschema contains a field that uses a default value.

Under these circumstances, it seems like the default values aren't being populated automatically. This seems to happen even if a discriminator is used.

To Reproduce
Use oneOf to describe a field or array (Note: I have a proper example below) e.g

pet:
  oneOf:
    - $ref: '#/components/schemas/CatObject'
    - $ref: '#/components/schemas/DogObject'

Add a default value to one of the subschemas e.g

# DogObject
bark:
  type: boolean
  default: false

Actual behavior
When POSTing to an endpoint using this spec, the default value for the field is not populated.

Expected behavior
I would expect the default value to be populated, as this is the behavior using this field in other contexts.

Examples and context
I pushed up an example to a forked version of this repo, which you can use to see the changes I made (see here) to test this out.

I was also unsure if this is related to this comment here about only supporting top-level discriminators. However, I wasn't sure because I'm not using discriminators in my example.

@cdimascio cdimascio added bug Something isn't working triage and removed bug Something isn't working labels May 21, 2021
@cdimascio
Copy link
Owner

cdimascio commented May 21, 2021

@kiahnjl thanks for this issue. and thanks for your interest. currently, only top level discriminators are supported. in this case its nested. I'm going to close this, as we've have other issues that account for this csae. i.e. #104, et la

work is needed to support nested discriminators

PRs are certainly welcome

@kiahnjl
Copy link
Author

kiahnjl commented May 21, 2021

Thanks for confirming @cdimascio, that makes sense! I'll try and make some time to have a look :)

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

No branches or pull requests

2 participants