-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[codegen][python-experimental] Composed schema with additionalProperties #6290
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
[codegen][python-experimental] Composed schema with additionalProperties #6290
Conversation
|
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
samples/openapi3/client/petstore/python-experimental/tests/test_deserialization.py
Show resolved
Hide resolved
|
@wing328 , I think the addAdditionPropertiesToCodeGenModel function should be called for composed schemas as well, not just map schemas. AFAIK, the |
…ll-of-additional-properties
|
I think it's not a good idea to use single class inheritance to implement additionalProperties (e.g. Java client). That may work for non-composed schemas, but that does not work for composed 'allOf' schemas. For example, in Java, if |
samples/openapi3/client/petstore/python-experimental/test/test_fruit.py
Outdated
Show resolved
Hide resolved
…lack Adds *args input to __init__ method to fix test testFruitNullValue
…ll-of-additional-properties
…enapi-generator into all-of-additional-properties
…ll-of-additional-properties
…ll-of-additional-properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thank you for the PR!
* master: [PS] Refactor the http signing auth with ecdsa support (OpenAPITools#6397) [Rust Server] Hyper 0.13 + Async/Await support (OpenAPITools#6244) [Rust] set supportAsync to true as the default (OpenAPITools#6480) [php-symfony] Set required PHP version ^7.1.3 (OpenAPITools#6181) update doc [csharp] Rename netstandard to netstandard1.3 (OpenAPITools#6460) feat: support deprecated parameters for typescript-axios generator (OpenAPITools#6475) [REQ][typescript-axios] useSingleRequestParameter should mark parameter optional if all properties are optional (OpenAPITools#6477) better struct alias in rust (OpenAPITools#6470) Migrate Go server samples to OAS 3 only (OpenAPITools#6471) [Rust][reqwest] add async support (OpenAPITools#6464) [codegen][python-experimental] Composed schema with additionalProperties (OpenAPITools#6290) [Java] Decommission Retrofit 1.x support (OpenAPITools#6447) remove scala oas3 samples (OpenAPITools#6446) [Java][jersey2] Fix RuntimeException when HTTP signature parameters are not configured (OpenAPITools#6457) [Java][jersey2] Improve http signature code comments (OpenAPITools#6463) [typescript-angular] drop support of angular below 6.0.0 (OpenAPITools#6360) [cli] new 'author template' command (OpenAPITools#6441) python-experimental updates ancestor + adds descendant discriminator tests (OpenAPITools#6417)
* master: (36 commits) Improve handling spaces in example command (#6482) fix maven plugin snapshot version comment out erlang server test (#6499) Migrate Perl samples to use OAS v3 spec (#6490) [core] Refactor templating management (#6357) migrate apex samples to use oas3 spec (#6488) add new file in php-symfony sample [PS] Refactor the http signing auth with ecdsa support (#6397) [Rust Server] Hyper 0.13 + Async/Await support (#6244) [Rust] set supportAsync to true as the default (#6480) [php-symfony] Set required PHP version ^7.1.3 (#6181) update doc [csharp] Rename netstandard to netstandard1.3 (#6460) feat: support deprecated parameters for typescript-axios generator (#6475) [REQ][typescript-axios] useSingleRequestParameter should mark parameter optional if all properties are optional (#6477) better struct alias in rust (#6470) Migrate Go server samples to OAS 3 only (#6471) [Rust][reqwest] add async support (#6464) [codegen][python-experimental] Composed schema with additionalProperties (#6290) [Java] Decommission Retrofit 1.x support (#6447) ...
Background
As per OAS specification:
additionalPropertieskeyword is not specified, whenadditionalProperties: trueor whenadditionalProperties: {}. TheadditionalPropertieskeyword can also be used to specify a schema for the undeclared properties.additionalPropertieskeyword, both as a sibling of allOf/oneOf/anyOf, and in the child schemas.Changes
disallowAdditionalPropertiesIfNotPresentCLI option to control the interpretation of theadditionalPropertieskeyword. See below for more details.additionalPropertieskeyword to comply with the OAS 2.0 and 3.x specifications.additionalPropertieskeyword is not present in the OAS document, that should be interpreted as ifadditionalPropertieshad been set totrue.disallowAdditionalPropertiesIfNotPresentCLI option totrue, which is the default for now.disallowAdditionalPropertiesIfNotPresentCLI option totrue.true(i.e. non-compliant behavior, as originally implemented). Initially I wanted to change the default value tofalsefor all code generators, but it's too much work. For now I am only enabling the compliant mode forpython-experimental.additionalPropertieskeyword set. The issue is specifically resolved for python-experimental.additionalPropertieskeyword.nullablekeyword. When a schema is nullable, the client should accept thenullvalue in the input data.additionalPropertieswhich is referencing a schema with a$ref. Generate importsadditionalPropertiesreferences a schemaNote: breaking changes are introduced in this PR, but they are necessary to be compliant with the OAS specification.
For example:
In the above example, the
additionalPropertieskeyword is not specified, which means by default undeclared properties should be allowed. This equivalent to:Related Issues and future work
While working on this PR, the following related issues have been identified:
additionalPropertieskeyword is limited to python-experimental for now. Significant changes may have to be done in other languages. For example, in the Java clients, single inheritance is used, that causes a conflict between inheriting theallOfparent and theHashMapparent.PR checklist
./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.shif updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).master,4.3.x,5.0.x. Default:master.