Repository navigation
[java][okhttp-gson] Add typed constructors and is<Member>() checks to oneOf and anyOf models #25568
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
base: master
Are you sure you want to change the base?
Changes from all commits
6ef33f7
a1b81c6
831a936
0106e38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: oneOf/anyOf typed constructors | ||
| description: oneOf/anyOf members that need a typed constructor in the okhttp-gson client, and members that must not get one | ||
| version: 1.0.0 | ||
| servers: | ||
| - url: http://localhost | ||
| paths: | ||
| /composed: | ||
| get: | ||
| operationId: getComposed | ||
| responses: | ||
| '200': | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/Composed' | ||
| components: | ||
| schemas: | ||
| Composed: | ||
| type: object | ||
| properties: | ||
| status: | ||
| $ref: '#/components/schemas/OpenPetStatus' | ||
| scalar: | ||
| $ref: '#/components/schemas/Scalar' | ||
| petOrPets: | ||
| $ref: '#/components/schemas/PetOrPets' | ||
| numbers: | ||
| $ref: '#/components/schemas/Numbers' | ||
| petOrAnything: | ||
| $ref: '#/components/schemas/PetOrAnything' | ||
| petOrFreeForm: | ||
| $ref: '#/components/schemas/PetOrFreeForm' | ||
| nullablePetOrName: | ||
| $ref: '#/components/schemas/NullablePetOrName' | ||
| petOrNullable: | ||
| $ref: '#/components/schemas/PetOrNullable' | ||
| nullableOrName: | ||
| $ref: '#/components/schemas/NullableOrName' | ||
| PetStatus: | ||
| type: string | ||
| enum: | ||
| - available | ||
| - pending | ||
| - sold | ||
| OpenPetStatus: | ||
| anyOf: | ||
| - $ref: '#/components/schemas/PetStatus' | ||
| - type: string | ||
| Scalar: | ||
| oneOf: | ||
| - type: number | ||
| - type: integer | ||
| format: int32 | ||
| - type: integer | ||
| format: int64 | ||
| - type: boolean | ||
| Pet: | ||
| type: object | ||
| properties: | ||
| name: | ||
| type: string | ||
| PetOrPets: | ||
| oneOf: | ||
| - $ref: '#/components/schemas/Pet' | ||
| - type: array | ||
| items: | ||
| $ref: '#/components/schemas/Pet' | ||
| Numbers: | ||
| anyOf: | ||
| - type: array | ||
| items: | ||
| type: number | ||
| - type: array | ||
| items: | ||
| type: integer | ||
| PetOrAnything: | ||
| anyOf: | ||
| - $ref: '#/components/schemas/Pet' | ||
| - description: Any value | ||
| PetOrFreeForm: | ||
| oneOf: | ||
| - $ref: '#/components/schemas/Pet' | ||
| - type: object | ||
| NullablePetOrName: | ||
| nullable: true | ||
| oneOf: | ||
| - $ref: '#/components/schemas/Pet' | ||
| - type: string | ||
| Nullable: | ||
| type: object | ||
| properties: | ||
| reason: | ||
| type: string | ||
| PetOrNullable: | ||
| oneOf: | ||
| - $ref: '#/components/schemas/Pet' | ||
| - $ref: '#/components/schemas/Nullable' | ||
| NullableOrName: | ||
| anyOf: | ||
| - $ref: '#/components/schemas/Nullable' | ||
| - type: string |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,16 @@ public MyExampleGet200Response(Object o) { | |
| setActualInstance(o); | ||
| } | ||
|
|
||
| public MyExampleGet200Response(List<@Valid OneOf1> o) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This typed array constructor rejects an otherwise valid empty array. Update Prompt for AI agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not changing this here. The rejection comes from |
||
| this(); | ||
| setActualInstance(o); | ||
| } | ||
|
|
||
| public MyExampleGet200Response(OneOf1 o) { | ||
| this(); | ||
| setActualInstance(o); | ||
| } | ||
|
|
||
| static { | ||
| schemas.put("List<@Valid OneOf1>", List.class); | ||
| schemas.put("OneOf1", OneOf1.class); | ||
|
|
@@ -241,6 +251,15 @@ public OneOf1 getOneOf1() throws ClassCastException { | |
| return (OneOf1)super.getActualInstance(); | ||
| } | ||
|
|
||
| /** | ||
| * Check if the actual instance is of the type `OneOf1`. | ||
| * | ||
| * @return true if the actual instance is of the type `OneOf1` | ||
| */ | ||
| public boolean isOneOf1() { | ||
| return super.getActualInstance() instanceof OneOf1; | ||
| } | ||
|
|
||
| /** | ||
| * Validates the JSON Element and throws an exception if issues found | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.