-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[php-nextgen] Fix Nested oneOf/anyOf Behavior
#24318
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
Open
ckoegel
wants to merge
36
commits into
OpenAPITools:master
Choose a base branch
from
ckoegel:php-nextgen-nested-composed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
43b94b1
update codegen
ckoegel f69799d
update test codegen
ckoegel 3843c5c
mustache templates
ckoegel 64d4a0f
generate samples
ckoegel 17bcfc7
update model doc template
ckoegel c788027
regenerate samples
ckoegel 24f6b9b
add tests
ckoegel 8161b24
regenerate samples
ckoegel 72feca0
fix comment per cubic review
ckoegel 3c6eb0f
update composed model tests
ckoegel da12fc3
use Throwable to preserve error catch
ckoegel 0a3d632
update model serializer per cubic review
ckoegel 9a21acf
regenerate samples
ckoegel b86c6fc
regenerate tests
ckoegel d95922f
fix object serialization per cubic review
ckoegel ba73003
add function to flatten type hints
ckoegel d04e7bc
generate samples
ckoegel 3a01c20
add tests
ckoegel 9d1ce0b
regenerate
ckoegel fe2f126
split composed into oneOf/anyOf
ckoegel c31c074
regenerate samples
ckoegel a3fad7b
Merge branch 'master' of https://github.com/ckoegel/openapi-generator…
ckoegel 1582a69
Merge branch 'php-nextgen-anyof' into php-nextgen-nested-composed
ckoegel 457f0f4
samples again
ckoegel cbaf8c7
address cubic json decoding feedback
ckoegel b2a7e37
address cubic type validation feedback
ckoegel 1ac0a88
Update modules/openapi-generator/src/main/resources/php-nextgen/Objec…
ckoegel 9add223
generate samples
ckoegel c3cf715
Merge branch 'php-nextgen-anyof' of https://github.com/ckoegel/openap…
ckoegel 0c00fc5
generate samples
ckoegel c0c811e
Merge branch 'master' into php-nextgen-nested-composed
ckoegel 24aee7c
address cubic cyclic feedback
ckoegel 4b1cda7
address cubic docs feedback
ckoegel 0194b12
Update modules/openapi-generator/src/main/java/org/openapitools/codeg…
ckoegel c6e09a0
address cubic invalid php feedback
ckoegel 3a17e3b
Merge branch 'php-nextgen-nested-composed' of https://github.com/ckoe…
ckoegel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
samples/client/petstore/php-nextgen/OpenAPIClient-php/docs/Model/Creature.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Creature | ||
|
|
||
| This model is an `anyOf` wrapper: a value is at least one of the member types listed below. | ||
| It is never instantiated directly — use one of the concrete types. | ||
|
|
||
| ## anyOf | ||
|
|
||
| - [**\OpenAPI\Client\Model\Whale**](Whale.md) | ||
| - [**\OpenAPI\Client\Model\Zebra**](Zebra.md) | ||
| - [**\OpenAPI\Client\Model\Lizard**](Lizard.md) | ||
| - [**\OpenAPI\Client\Model\Snake**](Snake.md) | ||
|
|
||
| [[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/Creature.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <?php | ||
| /** | ||
| * Creature | ||
| * | ||
| * PHP version 8.1 | ||
| * | ||
| * @package OpenAPI\Client | ||
| * @author OpenAPI Generator team | ||
| * @link https://openapi-generator.tech | ||
| */ | ||
|
|
||
| /** | ||
| * OpenAPI Petstore | ||
| * | ||
| * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ | ||
| * | ||
| * The version of the OpenAPI document: 1.0.0 | ||
| * @generated Generated by: https://openapi-generator.tech | ||
| * Generator version: 7.25.0-SNAPSHOT | ||
| */ | ||
|
|
||
| /** | ||
| * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
| * https://openapi-generator.tech | ||
| * Do not edit the class manually. | ||
| */ | ||
|
|
||
| namespace OpenAPI\Client\Model; | ||
|
|
||
| /** | ||
| * Creature Class Doc Comment | ||
| * | ||
| * @package OpenAPI\Client | ||
| * @author OpenAPI Generator team | ||
| * @link https://openapi-generator.tech | ||
| */ | ||
| class Creature implements AnyOfInterface | ||
| { | ||
| /** | ||
| * The original name of the model. | ||
| * | ||
| * @var string | ||
| */ | ||
| public const MODEL_NAME = 'Creature'; | ||
|
|
||
| /** | ||
| * The discriminator property name, or null when the schema has no discriminator. | ||
| * | ||
| * @var string|null | ||
| */ | ||
| public const DISCRIMINATOR = null; | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public static function getAnyOfTypes(): array | ||
| { | ||
| return [ | ||
| '\OpenAPI\Client\Model\Mammal', | ||
| '\OpenAPI\Client\Model\Reptile' | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public static function getAnyOfDiscriminator(): ?string | ||
| { | ||
| return self::DISCRIMINATOR; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public static function getAnyOfDiscriminatorMappings(): array | ||
| { | ||
| return [ | ||
|
|
||
| ]; | ||
| } | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
P2:
Creature::getAnyOfTypes()remains nested, so consumers of the generated anyOf metadata seeMammal|Reptileinstead of the promised leaf unionWhale|Zebra|Lizard|Snake. Returning the transitive leaf types here keeps directCreaturedeserialization/introspection consistent with the flattened property types generated elsewhere.Prompt for AI agents
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.
I think this can be ignored,
getAnyOfTypes()is meant to return this model's directanyOfmembers, not its grandchildren, soMammalandReptileare what this should list imo. It's also used indeserializeAnyOf, which already recurses through them to return the leaves. Flattening it would skip their discriminators and make it guess by validity instead, which could result in picking the wrong type if multiple are valid.