Skip to content

Conversation

@sebastien-rosset
Copy link
Contributor

@sebastien-rosset sebastien-rosset commented May 12, 2020

This PR adds support for use cases when a schema property is referencing another schema which is itself a oneOf.

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@sebastien-rosset
Copy link
Contributor Author

sebastien-rosset commented May 12, 2020

@spacether , I don't think we currently have any sample or unit test that exercises the following use case: a schema property is referencing a oneOf schema. I've added a new Drawing schema that has a "mainShape" and that main shape is a $ref to Shape. I have also add a unit test that currently fails. IMO that unit test should pass.

@spacether
Copy link
Contributor

spacether commented May 12, 2020

@sebastien-rosset please take a look at this branch which I made from this PR.
In it I add the function is_valid_type to check if input models are present in the discriminator in the required data type.
So if we expect Shape and we pass in ScaleneTrianagle, it checks the discriminator in Shape to see if it can find ScaleneTrianagle.

My branch's update makes it so we can instantiate Drawings with oneOf class inputs for Shape and Triangle types.
How about including that fix here?

@sebastien-rosset
Copy link
Contributor Author

@sebastien-rosset please take a look at this branch which I made from this PR.
In it I add the function is_valid_type to check if input models are present in the discriminator in the required data type.
So if we expect Shape and we pass in ScaleneTrianagle, it checks the discriminator in Shape to see if it can find ScaleneTrianagle.

My branch's update makes it so we can instantiate Drawings with oneOf class inputs for Shape and Triangle types.
How about including that fix here?

That's awesome, let me check.

@sebastien-rosset
Copy link
Contributor Author

I have tested your proposed changes, this seems to work, which is great.
I did have to make a small change to convert the dict_keys to a list before accessing the item at index 0.

@sebastien-rosset sebastien-rosset marked this pull request as ready for review May 12, 2020 21:34
@sebastien-rosset
Copy link
Contributor Author

There is a dependency on #6121 being merged before we can handle the 'null' type in oneOf. If we have a ShapeOrNull schema which is oneOf [type: 'null', Triangle, Quadrilateral] and in Drawing we have a secondary_shape property, then we should be able to assign None to Drawing.secondary_shape, whereas assigning None to Drawing.main_shape should raise an exception.

Copy link
Contributor

@spacether spacether left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Looks good to me.

@spacether spacether added this to the 5.0.0 milestone May 13, 2020
@spacether spacether merged commit 1a6cc67 into OpenAPITools:master May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants