Skip to content

[core] Provide User feedback on confusing use of oneOf #4695

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

Merged
merged 1 commit into from
Dec 7, 2019

Conversation

jimschubert
Copy link
Member

OAS 3.x specification isn't entirely clear on oneOf support. JSON Schema
defines oneOf in such a way that the Schema is only valid if it
validates against exactly one of the referenced Schemas. This suggests
that a Schema defined with oneOf can't include additional "dynamic"
properties. OpenAPI extends on this by adding the necessary
discriminator object, which allows tooling to decide the intended
Schema.

As tooling, openapi-generator may support loose or confusing definitions
in the Specification to better support our user's use cases. In this
case, we may warn that while this usage is technically valid the two
target specifications are unclear about the actual constraints regarding
oneOf.

This adds the warning and recommendation I proposed in review of #4482

cc @spacether @OpenAPITools/generator-core-team

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.

OAS 3.x specification isn't entirely clear on oneOf support. JSON Schema
defines oneOf in such a way that the Schema is only valid if it
validates against exactly one of the referenced Schemas. This suggests
that a Schema defined with oneOf can't include additional "dynamic"
properties. OpenAPI extends on this by adding the necessary
discriminator object, which allows tooling to decide the intended
Schema.

As tooling, openapi-generator may support loose or confusing definitions
in the Specification to better support our user's use cases. In this
case, we may warn that while this usage is technically valid the two
target specifications are unclear about the actual constraints regarding
oneOf.
@auto-labeler
Copy link

auto-labeler bot commented Dec 4, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

// parent model
final String parentName = ModelUtils.getParentName(composed, allDefinitions);
final List<String> allParents = ModelUtils.getAllParentsName(composed, allDefinitions);
final Schema parent = StringUtils.isBlank(parentName) || allDefinitions == null ? null : allDefinitions.get(parentName);
final boolean hasParent = StringUtils.isNotBlank(parentName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we deleting this because it is unused?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. This would fail compilation of it was still expected.

@spacether
Copy link
Contributor

@jimschubert this looks good. Should we add tests?

@jimschubert
Copy link
Member Author

@spacether I'm not sure how we'd add tests. The changes in non-cli code is logging and a special case to test a minimal scenario which resulted in an NPE. That NPE will need to be investigated later.

For the CLI, we don't have tests that verify generated files. The change in this PR only results in stdout text, for which we don't have tests on other commands.

@spacether
Copy link
Contributor

spacether commented Dec 5, 2019

@spacether I'm not sure how we'd add tests. The changes in non-cli code is logging and a special case to test a minimal scenario which resulted in an NPE. That NPE will need to be investigated later.

For the CLI, we don't have tests that verify generated files. The change in this PR only results in stdout text, for which we don't have tests on other commands.

Good to know, sounds like adding them would be more hassle than the benefit that we would get.

@jimschubert jimschubert added this to the 4.2.3 milestone Dec 7, 2019
@jimschubert jimschubert merged commit 0c00505 into master Dec 7, 2019
@jimschubert jimschubert deleted the warn-on-composed-oneOf branch December 7, 2019 16:33
@jfeltesse-mdsol jfeltesse-mdsol mentioned this pull request Mar 25, 2020
5 tasks
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