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

Adds free form model generation in python-experimental #7373

Conversation

spacether
Copy link
Contributor

@spacether spacether commented Sep 8, 2020

If a free form object schema has validations I think that we should generate it as a model

  • I think that we should do this to allow another composed schema to oneOf include an object schema with validations
  • In the current master branch, those validations are omitted because there will not be a model to contain the validations

If a free form schema is used as an interface schema (another schema allOf includes it) I think that we should generate the interface as a model

If merged, this will resolve #7361 for python-experimental only

  • Tests added for these free form schema use cases

How this change was made:

  • unaliasSchema is changed into a public method in each generator
  • when generating models, if we are examining a FreeFormObject, we create a schema ref to it and see if unaliasSchema preserves the ref(meaning the model will be generated) or it unaliases the schema (meaning the model won't be generated)
  • the method hasValidation is added to codegenModel to return a boolean saying if there is validation in the root level of the component schema that we are examining. This is needed to check if arrayModels have validations in all generators that make arraymodels. This is also needed in python-experimental to produce FreeFormObject models with validation.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

Python Technical Committee
@taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @Jyhess (2019/01) @arun-nalla (2019/11) @spacether (2019/11)

@wing328
Copy link
Member

wing328 commented Sep 16, 2020

@spacether when you've time, can you please resolve the merge conflicts?

@spacether spacether force-pushed the produces_freeform_objects_with_validation branch from 958c064 to 4c9b39b Compare September 16, 2020 02:26
@spacether
Copy link
Contributor Author

@spacether when you've time, can you please resolve the merge conflicts?

@wing328 merge conflicts have been resolved. Thank you for letting me know about them.

@spacether spacether merged commit 35d4272 into OpenAPITools:master Sep 20, 2020
@spacether spacether deleted the produces_freeform_objects_with_validation branch November 20, 2020 07:14
AmateurECE added a commit to AmateurECE/openapi-generator that referenced this pull request Jan 24, 2023
Issue OpenAPITools#5969 and PR OpenAPITools#5970 document an issue with rust-server where free form
models are not generated. OpenAPITools#7373 adds some free form model generation to
python-experimental (later ported to other languages, it seems), but this
feature only covers two of three possible use cases. The third use case remains
unimplemented, though it is used in some larger OpenAPI document sets, such as
DMTF's Redfish schema (which contains 33 of these free form objects without
validation).

related functions), but there does not seem to be an adequate replacement for
detecting free form objects in the OpenAPI data model from template context.
Unfortunately, free form objects require special consideration in statically
type-checked languages such as Rust.

quickly closed, presumably because `isFreeFormObject` was still present in the
data model at the time the issue was opened.

This commit adds a global property (default `false`) called
`generateFreeFormModels` (I'm taking suggestions for a better name) which
enables generation for the third use case not addressed by OpenAPITools#7373. Additionally,
isFreeFormObject is added back into the object model for any case where a
free-form object is generated, allowing generators for languages such as Rust
to handle them gracefully.
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.

[BUG] FreeForm object models with validations are not generated
2 participants