From 6ef33f7a0eda4c95ec36bee08bb756be51657f0d Mon Sep 17 00:00:00 2001 From: Spenser Jones Date: Mon, 2 Nov 2026 16:39:08 -0600 Subject: [PATCH 1/4] [java][okhttp-gson] Add typed constructors to oneOf and anyOf models --- .../okhttp-gson/anyof_model.mustache | 15 ++++ .../okhttp-gson/oneof_model.mustache | 15 ++++ .../codegen/java/JavaClientCodegenTest.java | 38 ++++++++ ...http-gson-composed-typed-constructors.yaml | 86 +++++++++++++++++++ .../client/model/MyExampleGet200Response.java | 10 +++ .../client/model/MyExamplePostRequest.java | 5 ++ .../client/model/SimpleOneOf.java | 10 +++ .../client/model/OneOfStringOrInt.java | 10 +++ ...evelParameterOneofRefToOneofParameter.java | 10 +++ ...oRefParameterAnyofRefToAnyofParameter.java | 10 +++ .../client/model/SelfReferenceAnyOf.java | 10 +++ .../client/model/SelfReferenceOneOf.java | 10 +++ .../client/model/StringOrInt.java | 10 +++ .../AllOfModelArrayAnyOfAllOfAttributesC.java | 10 +++ ...elArrayAnyOfAllOfLinkListColumn1Value.java | 10 +++ .../openapitools/client/model/ArrayAnyOf.java | 10 +++ .../openapitools/client/model/ArrayOneOf.java | 10 +++ ...akeAnyOfWIthSameErasureGet200Response.java | 5 ++ ...akeOneOfWIthSameErasureGet200Response.java | 5 ++ .../model/FakeRefParameterPetIdParameter.java | 10 +++ .../FreeFormObjectTestClassProperties.java | 5 ++ .../org/openapitools/client/model/Fruit.java | 10 +++ .../openapitools/client/model/FruitReq.java | 10 +++ .../openapitools/client/model/GmFruit.java | 10 +++ .../org/openapitools/client/model/Mammal.java | 15 ++++ .../client/model/MammalAnyof.java | 15 ++++ .../model/NullableFieldsMapResponse.java | 10 +++ .../client/model/NullableShape.java | 10 +++ .../org/openapitools/client/model/Pig.java | 10 +++ .../client/model/Quadrilateral.java | 10 +++ .../org/openapitools/client/model/Scalar.java | 20 +++++ .../client/model/ScalarAnyOf.java | 20 +++++ .../org/openapitools/client/model/Shape.java | 10 +++ .../client/model/ShapeOrNull.java | 10 +++ .../openapitools/client/model/Triangle.java | 15 ++++ .../org/openapitools/client/model/Value.java | 10 +++ 36 files changed, 489 insertions(+) create mode 100644 modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache index e1760876459d..e2d94ec74565 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache @@ -248,6 +248,21 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im setActualInstance(o); } + {{#composedSchemas}} + {{#anyOf}} + {{^vendorExtensions.x-duplicated-data-type}} + {{^isAnyType}} + {{^isFreeFormObject}} + public {{classname}}({{{dataType}}} o) { + this(); + setActualInstance(o); + } + + {{/isFreeFormObject}} + {{/isAnyType}} + {{/vendorExtensions.x-duplicated-data-type}} + {{/anyOf}} + {{/composedSchemas}} static { {{#composedSchemas}} {{#anyOf}} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache index dc71a8beb320..b974b43f0187 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache @@ -298,6 +298,21 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im setActualInstance(o); } + {{#composedSchemas}} + {{#oneOf}} + {{^vendorExtensions.x-duplicated-data-type}} + {{^isAnyType}} + {{^isFreeFormObject}} + public {{classname}}({{{dataType}}} o) { + this(); + setActualInstance(o); + } + + {{/isFreeFormObject}} + {{/isAnyType}} + {{/vendorExtensions.x-duplicated-data-type}} + {{/oneOf}} + {{/composedSchemas}} static { {{#composedSchemas}} {{#oneOf}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java index 256c2203428e..fa395b8fe2de 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java @@ -4561,6 +4561,44 @@ public void testNativeOneOfAnyOfWithContainerMembers() { .doesNotContain("getList()", "List.class"); } + @Test + public void testOkHttpGsonOneOfAnyOfTypedConstructors() { + final Path output = newTempFolder(); + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName(JAVA_GENERATOR) + .setLibrary(JavaClientCodegen.OKHTTP_GSON) + .setInputSpec("src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml") + .setOutputDir(output.toString().replace("\\", "/")); + + List files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); + + validateJavaSourceFiles(files); + final Path modelDir = output.resolve("src/main/java/org/openapitools/client/model"); + assertThat(modelDir.resolve("OpenTaxIdType.java")).content() + .contains( + "public OpenTaxIdType(Object o) {", + "public OpenTaxIdType(TaxIdType o) {", + "public OpenTaxIdType(String o) {"); + assertThat(modelDir.resolve("Scalar.java")).content() + .contains( + "public Scalar(BigDecimal o) {", + "public Scalar(Integer o) {", + "public Scalar(Long o) {", + "public Scalar(Boolean o) {"); + assertThat(modelDir.resolve("PetOrPets.java")).content() + .contains("public PetOrPets(Pet o) {", "public PetOrPets(List o) {"); + // List and List have the same erasure, so only the first gets a constructor. + assertThat(modelDir.resolve("Numbers.java")).content() + .contains("public Numbers(List o) {") + .doesNotContain("public Numbers(List o) {"); + // A free-form member is an Object, which the existing constructor already accepts. + assertThat(modelDir.resolve("PetOrFreeForm.java")).content() + .containsOnlyOnce("public PetOrFreeForm(Object o) {") + .contains("public PetOrFreeForm(Pet o) {"); + assertThat(modelDir.resolve("NullablePetOrName.java")).content() + .contains("public NullablePetOrName(Pet o) {", "public NullablePetOrName(String o) {"); + } + @Test public void testEnumWithImplements() { final Path output = newTempFolder(); diff --git a/modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml b/modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml new file mode 100644 index 000000000000..a2467462e7aa --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml @@ -0,0 +1,86 @@ +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: + taxIdType: + $ref: '#/components/schemas/OpenTaxIdType' + 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' + TaxIdType: + type: string + enum: + - USA_SSN + - CAN_SIN + OpenTaxIdType: + anyOf: + - $ref: '#/components/schemas/TaxIdType' + - 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' + - {} + PetOrFreeForm: + oneOf: + - $ref: '#/components/schemas/Pet' + - type: object + NullablePetOrName: + nullable: true + oneOf: + - $ref: '#/components/schemas/Pet' + - type: string diff --git a/samples/client/others/java/okhttp-gson-oneOf-array/src/main/java/org/openapitools/client/model/MyExampleGet200Response.java b/samples/client/others/java/okhttp-gson-oneOf-array/src/main/java/org/openapitools/client/model/MyExampleGet200Response.java index 4657204c26f9..48d89c25aa7c 100644 --- a/samples/client/others/java/okhttp-gson-oneOf-array/src/main/java/org/openapitools/client/model/MyExampleGet200Response.java +++ b/samples/client/others/java/okhttp-gson-oneOf-array/src/main/java/org/openapitools/client/model/MyExampleGet200Response.java @@ -170,6 +170,16 @@ public MyExampleGet200Response(Object o) { setActualInstance(o); } + public MyExampleGet200Response(List<@Valid OneOf1> o) { + this(); + setActualInstance(o); + } + + public MyExampleGet200Response(OneOf1 o) { + this(); + setActualInstance(o); + } + static { schemas.put("List<@Valid OneOf1>", List.class); schemas.put("OneOf1", OneOf1.class); diff --git a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java index 082bd1878b32..a7eec34c94c5 100644 --- a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java +++ b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java @@ -129,6 +129,11 @@ public MyExamplePostRequest(Object o) { setActualInstance(o); } + public MyExamplePostRequest(String o) { + this(); + setActualInstance(o); + } + static { schemas.put("String", String.class); } diff --git a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java index 07932d5fc0b7..3e151c831be5 100644 --- a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java +++ b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java @@ -151,6 +151,16 @@ public SimpleOneOf(Object o) { setActualInstance(o); } + public SimpleOneOf(String o) { + this(); + setActualInstance(o); + } + + public SimpleOneOf(Integer o) { + this(); + setActualInstance(o); + } + static { schemas.put("String", String.class); schemas.put("Integer", Integer.class); diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java index c04457ab3f31..d473d892c2e6 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java @@ -150,6 +150,16 @@ public OneOfStringOrInt(Object o) { setActualInstance(o); } + public OneOfStringOrInt(String o) { + this(); + setActualInstance(o); + } + + public OneOfStringOrInt(Integer o) { + this(); + setActualInstance(o); + } + static { schemas.put("String", String.class); schemas.put("Integer", Integer.class); diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java index f83522333b39..c2eef2b89d0a 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java @@ -150,6 +150,16 @@ public RefRefToPathLevelParameterOneofRefToOneofParameter(Object o) { setActualInstance(o); } + public RefRefToPathLevelParameterOneofRefToOneofParameter(String o) { + this(); + setActualInstance(o); + } + + public RefRefToPathLevelParameterOneofRefToOneofParameter(Integer o) { + this(); + setActualInstance(o); + } + static { schemas.put("String", String.class); schemas.put("Integer", Integer.class); diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java index 3c5843ad08a7..dd435d176c2e 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java @@ -161,6 +161,16 @@ public RefToRefParameterAnyofRefToAnyofParameter(Object o) { setActualInstance(o); } + public RefToRefParameterAnyofRefToAnyofParameter(String o) { + this(); + setActualInstance(o); + } + + public RefToRefParameterAnyofRefToAnyofParameter(List o) { + this(); + setActualInstance(o); + } + static { schemas.put("String", String.class); schemas.put("List", List.class); diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceAnyOf.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceAnyOf.java index 5cc19cc93ed4..03a3c20fdbf4 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceAnyOf.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceAnyOf.java @@ -145,6 +145,16 @@ public SelfReferenceAnyOf(Object o) { setActualInstance(o); } + public SelfReferenceAnyOf(String o) { + this(); + setActualInstance(o); + } + + public SelfReferenceAnyOf(Boolean o) { + this(); + setActualInstance(o); + } + static { schemas.put("String", String.class); schemas.put("Boolean", Boolean.class); diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceOneOf.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceOneOf.java index d0ef79421e47..44689480dc8d 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceOneOf.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceOneOf.java @@ -150,6 +150,16 @@ public SelfReferenceOneOf(Object o) { setActualInstance(o); } + public SelfReferenceOneOf(String o) { + this(); + setActualInstance(o); + } + + public SelfReferenceOneOf(Boolean o) { + this(); + setActualInstance(o); + } + static { schemas.put("String", String.class); schemas.put("Boolean", Boolean.class); diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java index 9a0a38075b95..9e86e39a2140 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java @@ -145,6 +145,16 @@ public StringOrInt(Object o) { setActualInstance(o); } + public StringOrInt(String o) { + this(); + setActualInstance(o); + } + + public StringOrInt(Integer o) { + this(); + setActualInstance(o); + } + static { schemas.put("String", String.class); schemas.put("Integer", Integer.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java index f73ad4b3df7a..b72dd28aab8e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java @@ -160,6 +160,16 @@ public AllOfModelArrayAnyOfAllOfAttributesC(Object o) { setActualInstance(o); } + public AllOfModelArrayAnyOfAllOfAttributesC(Pet o) { + this(); + setActualInstance(o); + } + + public AllOfModelArrayAnyOfAllOfAttributesC(Order o) { + this(); + setActualInstance(o); + } + static { schemas.put("Pet", Pet.class); schemas.put("Order", Order.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java index f5f4762e7f56..0cfe917ea9bb 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java @@ -151,6 +151,16 @@ public AllOfModelArrayAnyOfAllOfLinkListColumn1Value(Object o) { setActualInstance(o); } + public AllOfModelArrayAnyOfAllOfLinkListColumn1Value(User o) { + this(); + setActualInstance(o); + } + + public AllOfModelArrayAnyOfAllOfLinkListColumn1Value(Tag o) { + this(); + setActualInstance(o); + } + static { schemas.put("User", User.class); schemas.put("Tag", Tag.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java index 74da050c2c33..7852c238adb1 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java @@ -156,6 +156,16 @@ public ArrayAnyOf(Object o) { setActualInstance(o); } + public ArrayAnyOf(Integer o) { + this(); + setActualInstance(o); + } + + public ArrayAnyOf(List o) { + this(); + setActualInstance(o); + } + static { schemas.put("Integer", Integer.class); schemas.put("List", List.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java index c3a0de6127d4..aebff7659308 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java @@ -161,6 +161,16 @@ public ArrayOneOf(Object o) { setActualInstance(o); } + public ArrayOneOf(Integer o) { + this(); + setActualInstance(o); + } + + public ArrayOneOf(List o) { + this(); + setActualInstance(o); + } + static { schemas.put("Integer", Integer.class); schemas.put("List", List.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java index bc6abb05d483..6a2a161fffab 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeAnyOfWIthSameErasureGet200Response.java @@ -137,6 +137,11 @@ public FakeAnyOfWIthSameErasureGet200Response(Object o) { setActualInstance(o); } + public FakeAnyOfWIthSameErasureGet200Response(List o) { + this(); + setActualInstance(o); + } + static { schemas.put("List", List.class); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java index 3fb7cc820635..878bc6ce8505 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeOneOfWIthSameErasureGet200Response.java @@ -143,6 +143,11 @@ public FakeOneOfWIthSameErasureGet200Response(Object o) { setActualInstance(o); } + public FakeOneOfWIthSameErasureGet200Response(List o) { + this(); + setActualInstance(o); + } + static { schemas.put("List", List.class); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java index 405519f04d86..5508e6a826b1 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java @@ -150,6 +150,16 @@ public FakeRefParameterPetIdParameter(Object o) { setActualInstance(o); } + public FakeRefParameterPetIdParameter(String o) { + this(); + setActualInstance(o); + } + + public FakeRefParameterPetIdParameter(Integer o) { + this(); + setActualInstance(o); + } + static { schemas.put("String", String.class); schemas.put("Integer", Integer.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java index a20fc1708f12..1b72e3349862 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java @@ -153,6 +153,11 @@ public FreeFormObjectTestClassProperties(Object o) { setActualInstance(o); } + public FreeFormObjectTestClassProperties(String o) { + this(); + setActualInstance(o); + } + static { schemas.put("String", String.class); schemas.put("Map", Map.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java index cf6fde24c1d4..c0b6c62714d2 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java @@ -156,6 +156,16 @@ public Fruit(Object o) { setActualInstance(o); } + public Fruit(Apple o) { + this(); + setActualInstance(o); + } + + public Fruit(Banana o) { + this(); + setActualInstance(o); + } + static { schemas.put("Apple", Apple.class); schemas.put("Banana", Banana.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java index 5ab0527048a9..616fc6f03508 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java @@ -156,6 +156,16 @@ public FruitReq(Object o) { setActualInstance(o); } + public FruitReq(AppleReq o) { + this(); + setActualInstance(o); + } + + public FruitReq(BananaReq o) { + this(); + setActualInstance(o); + } + static { schemas.put("AppleReq", AppleReq.class); schemas.put("BananaReq", BananaReq.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java index 8feca027d028..db872114accf 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java @@ -151,6 +151,16 @@ public GmFruit(Object o) { setActualInstance(o); } + public GmFruit(Apple o) { + this(); + setActualInstance(o); + } + + public GmFruit(Banana o) { + this(); + setActualInstance(o); + } + static { schemas.put("Apple", Apple.class); schemas.put("Banana", Banana.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java index 38ef8c6df8ae..255106063b61 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java @@ -201,6 +201,21 @@ public Mammal(Object o) { setActualInstance(o); } + public Mammal(Whale o) { + this(); + setActualInstance(o); + } + + public Mammal(Zebra o) { + this(); + setActualInstance(o); + } + + public Mammal(Pig o) { + this(); + setActualInstance(o); + } + static { schemas.put("Whale", Whale.class); schemas.put("Zebra", Zebra.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/MammalAnyof.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/MammalAnyof.java index c50fd0d5e702..36c647c45d81 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/MammalAnyof.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/MammalAnyof.java @@ -201,6 +201,21 @@ public MammalAnyof(Object o) { setActualInstance(o); } + public MammalAnyof(Whale o) { + this(); + setActualInstance(o); + } + + public MammalAnyof(Zebra o) { + this(); + setActualInstance(o); + } + + public MammalAnyof(Pig o) { + this(); + setActualInstance(o); + } + static { schemas.put("Whale", Whale.class); schemas.put("Zebra", Zebra.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableFieldsMapResponse.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableFieldsMapResponse.java index 9655bccc6312..59c71a24b5a6 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableFieldsMapResponse.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableFieldsMapResponse.java @@ -153,6 +153,16 @@ public NullableFieldsMapResponse(Object o) { setActualInstance(o); } + public NullableFieldsMapResponse(NullableFieldsMapSuccess o) { + this(); + setActualInstance(o); + } + + public NullableFieldsMapResponse(NullableFieldsMapError o) { + this(); + setActualInstance(o); + } + static { schemas.put("NullableFieldsMapSuccess", NullableFieldsMapSuccess.class); schemas.put("NullableFieldsMapError", NullableFieldsMapError.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java index 297e30173109..18859d3ae9c0 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java @@ -177,6 +177,16 @@ public NullableShape(Object o) { setActualInstance(o); } + public NullableShape(Triangle o) { + this(); + setActualInstance(o); + } + + public NullableShape(Quadrilateral o) { + this(); + setActualInstance(o); + } + static { schemas.put("Triangle", Triangle.class); schemas.put("Quadrilateral", Quadrilateral.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java index b0b56db6cccb..cc2af5ecbb6e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java @@ -177,6 +177,16 @@ public Pig(Object o) { setActualInstance(o); } + public Pig(BasquePig o) { + this(); + setActualInstance(o); + } + + public Pig(DanishPig o) { + this(); + setActualInstance(o); + } + static { schemas.put("BasquePig", BasquePig.class); schemas.put("DanishPig", DanishPig.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java index 56dcb6ad2dc2..0e273b2efd19 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java @@ -177,6 +177,16 @@ public Quadrilateral(Object o) { setActualInstance(o); } + public Quadrilateral(SimpleQuadrilateral o) { + this(); + setActualInstance(o); + } + + public Quadrilateral(ComplexQuadrilateral o) { + this(); + setActualInstance(o); + } + static { schemas.put("SimpleQuadrilateral", SimpleQuadrilateral.class); schemas.put("ComplexQuadrilateral", ComplexQuadrilateral.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java index e64042c9706b..ad2fd9cad7b4 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java @@ -192,6 +192,26 @@ public Scalar(Object o) { setActualInstance(o); } + public Scalar(UUID o) { + this(); + setActualInstance(o); + } + + public Scalar(String o) { + this(); + setActualInstance(o); + } + + public Scalar(BigDecimal o) { + this(); + setActualInstance(o); + } + + public Scalar(Boolean o) { + this(); + setActualInstance(o); + } + static { schemas.put("UUID", UUID.class); schemas.put("String", String.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java index 96bd356790ca..81225f3a20e1 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java @@ -189,6 +189,26 @@ public ScalarAnyOf(Object o) { setActualInstance(o); } + public ScalarAnyOf(UUID o) { + this(); + setActualInstance(o); + } + + public ScalarAnyOf(String o) { + this(); + setActualInstance(o); + } + + public ScalarAnyOf(BigDecimal o) { + this(); + setActualInstance(o); + } + + public ScalarAnyOf(Boolean o) { + this(); + setActualInstance(o); + } + static { schemas.put("UUID", UUID.class); schemas.put("String", String.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java index cc54a5edd746..8bb3fd0ef61e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java @@ -177,6 +177,16 @@ public Shape(Object o) { setActualInstance(o); } + public Shape(Triangle o) { + this(); + setActualInstance(o); + } + + public Shape(Quadrilateral o) { + this(); + setActualInstance(o); + } + static { schemas.put("Triangle", Triangle.class); schemas.put("Quadrilateral", Quadrilateral.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java index c1cd3803fd1d..74cbea6984a7 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java @@ -177,6 +177,16 @@ public ShapeOrNull(Object o) { setActualInstance(o); } + public ShapeOrNull(Triangle o) { + this(); + setActualInstance(o); + } + + public ShapeOrNull(Quadrilateral o) { + this(); + setActualInstance(o); + } + static { schemas.put("Triangle", Triangle.class); schemas.put("Quadrilateral", Quadrilateral.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java index 9f32762e7a8f..e8b62b8a93dc 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java @@ -201,6 +201,21 @@ public Triangle(Object o) { setActualInstance(o); } + public Triangle(EquilateralTriangle o) { + this(); + setActualInstance(o); + } + + public Triangle(IsoscelesTriangle o) { + this(); + setActualInstance(o); + } + + public Triangle(ScaleneTriangle o) { + this(); + setActualInstance(o); + } + static { schemas.put("EquilateralTriangle", EquilateralTriangle.class); schemas.put("IsoscelesTriangle", IsoscelesTriangle.class); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java index db32b734aa75..e224d1470bfd 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java @@ -161,6 +161,16 @@ public Value(Object o) { setActualInstance(o); } + public Value(Scalar o) { + this(); + setActualInstance(o); + } + + public Value(List o) { + this(); + setActualInstance(o); + } + static { schemas.put("Scalar", Scalar.class); schemas.put("List", List.class); From a1b81c6814edc3a8e948a9cf9e558b908409bae0 Mon Sep 17 00:00:00 2001 From: Spenser Jones Date: Thu, 5 Nov 2026 15:50:38 -0600 Subject: [PATCH 2/4] [java][okhttp-gson] Add is() checks to oneOf and anyOf models --- .../okhttp-gson/anyof_model.mustache | 15 ++++++++ .../okhttp-gson/oneof_model.mustache | 15 ++++++++ .../codegen/java/JavaClientCodegenTest.java | 15 +++++--- .../client/model/MyExampleGet200Response.java | 9 +++++ .../client/model/MyExamplePostRequest.java | 9 +++++ .../client/model/SimpleOneOf.java | 18 ++++++++++ .../client/model/OneOfStringOrInt.java | 18 ++++++++++ ...evelParameterOneofRefToOneofParameter.java | 18 ++++++++++ ...oRefParameterAnyofRefToAnyofParameter.java | 9 +++++ .../client/model/SelfReferenceAnyOf.java | 18 ++++++++++ .../client/model/SelfReferenceOneOf.java | 18 ++++++++++ .../client/model/StringOrInt.java | 18 ++++++++++ .../AllOfModelArrayAnyOfAllOfAttributesC.java | 18 ++++++++++ ...elArrayAnyOfAllOfLinkListColumn1Value.java | 18 ++++++++++ .../openapitools/client/model/ArrayAnyOf.java | 9 +++++ .../openapitools/client/model/ArrayOneOf.java | 9 +++++ .../model/FakeRefParameterPetIdParameter.java | 18 ++++++++++ .../FreeFormObjectTestClassProperties.java | 9 +++++ .../org/openapitools/client/model/Fruit.java | 18 ++++++++++ .../openapitools/client/model/FruitReq.java | 18 ++++++++++ .../openapitools/client/model/GmFruit.java | 18 ++++++++++ .../org/openapitools/client/model/Mammal.java | 27 ++++++++++++++ .../client/model/MammalAnyof.java | 27 ++++++++++++++ .../model/NullableFieldsMapResponse.java | 18 ++++++++++ .../client/model/NullableShape.java | 18 ++++++++++ .../org/openapitools/client/model/Pig.java | 18 ++++++++++ .../client/model/Quadrilateral.java | 18 ++++++++++ .../org/openapitools/client/model/Scalar.java | 36 +++++++++++++++++++ .../client/model/ScalarAnyOf.java | 36 +++++++++++++++++++ .../org/openapitools/client/model/Shape.java | 18 ++++++++++ .../client/model/ShapeOrNull.java | 18 ++++++++++ .../openapitools/client/model/Triangle.java | 27 ++++++++++++++ .../org/openapitools/client/model/Value.java | 9 +++++ 33 files changed, 581 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache index e2d94ec74565..4fea268cce91 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache @@ -343,6 +343,21 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im return ({{{dataType}}})super.getActualInstance(); } + {{^isContainer}} + {{^isAnyType}} + {{^isFreeFormObject}} + /** + * Check if the actual instance is of the type `{{dataType}}`. + * + * @return true if the actual instance is of the type `{{dataType}}` + */ + public boolean is{{#sanitizeDataType}}{{{dataType}}}{{/sanitizeDataType}}() { + return super.getActualInstance() instanceof {{{dataType}}}; + } + + {{/isFreeFormObject}} + {{/isAnyType}} + {{/isContainer}} {{/vendorExtensions.x-duplicated-data-type-ignoring-erasure}} {{/anyOf}} {{/composedSchemas}} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache index b974b43f0187..71bb15de1712 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache @@ -394,6 +394,21 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im return ({{{dataType}}})super.getActualInstance(); } + {{^isContainer}} + {{^isAnyType}} + {{^isFreeFormObject}} + /** + * Check if the actual instance is of the type `{{dataType}}`. + * + * @return true if the actual instance is of the type `{{dataType}}` + */ + public boolean is{{#sanitizeDataType}}{{{dataType}}}{{/sanitizeDataType}}() { + return super.getActualInstance() instanceof {{{dataType}}}; + } + + {{/isFreeFormObject}} + {{/isAnyType}} + {{/isContainer}} {{/vendorExtensions.x-duplicated-data-type-ignoring-erasure}} {{/oneOf}} {{/composedSchemas}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java index fa395b8fe2de..92f9e3b8dc0e 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java @@ -4578,23 +4578,30 @@ public void testOkHttpGsonOneOfAnyOfTypedConstructors() { .contains( "public OpenTaxIdType(Object o) {", "public OpenTaxIdType(TaxIdType o) {", - "public OpenTaxIdType(String o) {"); + "public OpenTaxIdType(String o) {", + "public boolean isTaxIdType() {", + "return super.getActualInstance() instanceof TaxIdType;", + "public boolean isString() {"); assertThat(modelDir.resolve("Scalar.java")).content() .contains( "public Scalar(BigDecimal o) {", "public Scalar(Integer o) {", "public Scalar(Long o) {", "public Scalar(Boolean o) {"); + // instanceof can't tell List from another list, so containers get no is method assertThat(modelDir.resolve("PetOrPets.java")).content() - .contains("public PetOrPets(Pet o) {", "public PetOrPets(List o) {"); + .contains("public PetOrPets(Pet o) {", "public PetOrPets(List o) {", "public boolean isPet() {") + .doesNotContain("public boolean isList"); // List and List have the same erasure, so only the first gets a constructor. assertThat(modelDir.resolve("Numbers.java")).content() .contains("public Numbers(List o) {") .doesNotContain("public Numbers(List o) {"); - // A free-form member is an Object, which the existing constructor already accepts. + // A free-form member is an Object, which the existing constructor already accepts + // and which every instance would match. assertThat(modelDir.resolve("PetOrFreeForm.java")).content() .containsOnlyOnce("public PetOrFreeForm(Object o) {") - .contains("public PetOrFreeForm(Pet o) {"); + .contains("public PetOrFreeForm(Pet o) {", "public boolean isPet() {") + .doesNotContain("public boolean isObject() {"); assertThat(modelDir.resolve("NullablePetOrName.java")).content() .contains("public NullablePetOrName(Pet o) {", "public NullablePetOrName(String o) {"); } diff --git a/samples/client/others/java/okhttp-gson-oneOf-array/src/main/java/org/openapitools/client/model/MyExampleGet200Response.java b/samples/client/others/java/okhttp-gson-oneOf-array/src/main/java/org/openapitools/client/model/MyExampleGet200Response.java index 48d89c25aa7c..c984c5a38179 100644 --- a/samples/client/others/java/okhttp-gson-oneOf-array/src/main/java/org/openapitools/client/model/MyExampleGet200Response.java +++ b/samples/client/others/java/okhttp-gson-oneOf-array/src/main/java/org/openapitools/client/model/MyExampleGet200Response.java @@ -251,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 * diff --git a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java index a7eec34c94c5..e8fc2b720346 100644 --- a/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java +++ b/samples/client/others/java/okhttp-gson-oneOf/src/main/java/org/openapitools/client/model/MyExamplePostRequest.java @@ -184,6 +184,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java index 3e151c831be5..2186812af952 100644 --- a/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java +++ b/samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/model/SimpleOneOf.java @@ -217,6 +217,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Get the actual instance of `Integer`. If the actual instance is not `Integer`, * the ClassCastException will be thrown. @@ -229,6 +238,15 @@ public Integer getInteger() throws ClassCastException { return (Integer)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Integer`. + * + * @return true if the actual instance is of the type `Integer` + */ + public boolean isInteger() { + return super.getActualInstance() instanceof Integer; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java index d473d892c2e6..b9566197b989 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/OneOfStringOrInt.java @@ -216,6 +216,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Get the actual instance of `Integer`. If the actual instance is not `Integer`, * the ClassCastException will be thrown. @@ -228,6 +237,15 @@ public Integer getInteger() throws ClassCastException { return (Integer)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Integer`. + * + * @return true if the actual instance is of the type `Integer` + */ + public boolean isInteger() { + return super.getActualInstance() instanceof Integer; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java index c2eef2b89d0a..114ae1f13e95 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java @@ -216,6 +216,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Get the actual instance of `Integer`. If the actual instance is not `Integer`, * the ClassCastException will be thrown. @@ -228,6 +237,15 @@ public Integer getInteger() throws ClassCastException { return (Integer)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Integer`. + * + * @return true if the actual instance is of the type `Integer` + */ + public boolean isInteger() { + return super.getActualInstance() instanceof Integer; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java index dd435d176c2e..e6e5f169e147 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java @@ -230,6 +230,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Get the actual instance of `List<String>`. If the actual instance is not `List<String>`, * the ClassCastException will be thrown. diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceAnyOf.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceAnyOf.java index 03a3c20fdbf4..37b86d7b2c27 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceAnyOf.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceAnyOf.java @@ -210,6 +210,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Get the actual instance of `Boolean`. If the actual instance is not `Boolean`, * the ClassCastException will be thrown. @@ -221,6 +230,15 @@ public Boolean getBoolean() throws ClassCastException { return (Boolean)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Boolean`. + * + * @return true if the actual instance is of the type `Boolean` + */ + public boolean isBoolean() { + return super.getActualInstance() instanceof Boolean; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceOneOf.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceOneOf.java index 44689480dc8d..f5700037ad85 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceOneOf.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/SelfReferenceOneOf.java @@ -216,6 +216,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Get the actual instance of `Boolean`. If the actual instance is not `Boolean`, * the ClassCastException will be thrown. @@ -228,6 +237,15 @@ public Boolean getBoolean() throws ClassCastException { return (Boolean)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Boolean`. + * + * @return true if the actual instance is of the type `Boolean` + */ + public boolean isBoolean() { + return super.getActualInstance() instanceof Boolean; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java index 9e86e39a2140..7249af02cc0d 100644 --- a/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java +++ b/samples/client/petstore/java/okhttp-gson-3.1/src/main/java/org/openapitools/client/model/StringOrInt.java @@ -210,6 +210,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Get the actual instance of `Integer`. If the actual instance is not `Integer`, * the ClassCastException will be thrown. @@ -221,6 +230,15 @@ public Integer getInteger() throws ClassCastException { return (Integer)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Integer`. + * + * @return true if the actual instance is of the type `Integer` + */ + public boolean isInteger() { + return super.getActualInstance() instanceof Integer; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java index b72dd28aab8e..9ec4b96043ba 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfAttributesC.java @@ -226,6 +226,15 @@ public Pet getPet() throws ClassCastException { return (Pet)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Pet`. + * + * @return true if the actual instance is of the type `Pet` + */ + public boolean isPet() { + return super.getActualInstance() instanceof Pet; + } + /** * Get the actual instance of `Order`. If the actual instance is not `Order`, * the ClassCastException will be thrown. @@ -238,6 +247,15 @@ public Order getOrder() throws ClassCastException { return (Order)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Order`. + * + * @return true if the actual instance is of the type `Order` + */ + public boolean isOrder() { + return super.getActualInstance() instanceof Order; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java index 0cfe917ea9bb..2dfeb3c2891c 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AllOfModelArrayAnyOfAllOfLinkListColumn1Value.java @@ -216,6 +216,15 @@ public User getUser() throws ClassCastException { return (User)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `User`. + * + * @return true if the actual instance is of the type `User` + */ + public boolean isUser() { + return super.getActualInstance() instanceof User; + } + /** * Get the actual instance of `Tag`. If the actual instance is not `Tag`, * the ClassCastException will be thrown. @@ -227,6 +236,15 @@ public Tag getTag() throws ClassCastException { return (Tag)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Tag`. + * + * @return true if the actual instance is of the type `Tag` + */ + public boolean isTag() { + return super.getActualInstance() instanceof Tag; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java index 7852c238adb1..976862187c72 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayAnyOf.java @@ -224,6 +224,15 @@ public Integer getInteger() throws ClassCastException { return (Integer)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Integer`. + * + * @return true if the actual instance is of the type `Integer` + */ + public boolean isInteger() { + return super.getActualInstance() instanceof Integer; + } + /** * Get the actual instance of `List<String>`. If the actual instance is not `List<String>`, * the ClassCastException will be thrown. diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java index aebff7659308..8ecb1d85b19c 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOneOf.java @@ -230,6 +230,15 @@ public Integer getInteger() throws ClassCastException { return (Integer)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Integer`. + * + * @return true if the actual instance is of the type `Integer` + */ + public boolean isInteger() { + return super.getActualInstance() instanceof Integer; + } + /** * Get the actual instance of `List<String>`. If the actual instance is not `List<String>`, * the ClassCastException will be thrown. diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java index 5508e6a826b1..7ebd7ee404f1 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FakeRefParameterPetIdParameter.java @@ -216,6 +216,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Get the actual instance of `Integer`. If the actual instance is not `Integer`, * the ClassCastException will be thrown. @@ -228,6 +237,15 @@ public Integer getInteger() throws ClassCastException { return (Integer)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Integer`. + * + * @return true if the actual instance is of the type `Integer` + */ + public boolean isInteger() { + return super.getActualInstance() instanceof Integer; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java index 1b72e3349862..2f3f64e02f43 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FreeFormObjectTestClassProperties.java @@ -214,6 +214,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Get the actual instance of `Map<String, Object>`. If the actual instance is not `Map<String, Object>`, * the ClassCastException will be thrown. diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java index c0b6c62714d2..0bb63c80f7d5 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Fruit.java @@ -222,6 +222,15 @@ public Apple getApple() throws ClassCastException { return (Apple)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Apple`. + * + * @return true if the actual instance is of the type `Apple` + */ + public boolean isApple() { + return super.getActualInstance() instanceof Apple; + } + /** * Get the actual instance of `Banana`. If the actual instance is not `Banana`, * the ClassCastException will be thrown. @@ -234,6 +243,15 @@ public Banana getBanana() throws ClassCastException { return (Banana)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Banana`. + * + * @return true if the actual instance is of the type `Banana` + */ + public boolean isBanana() { + return super.getActualInstance() instanceof Banana; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java index 616fc6f03508..afca0b792aa8 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/FruitReq.java @@ -227,6 +227,15 @@ public AppleReq getAppleReq() throws ClassCastException { return (AppleReq)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `AppleReq`. + * + * @return true if the actual instance is of the type `AppleReq` + */ + public boolean isAppleReq() { + return super.getActualInstance() instanceof AppleReq; + } + /** * Get the actual instance of `BananaReq`. If the actual instance is not `BananaReq`, * the ClassCastException will be thrown. @@ -239,6 +248,15 @@ public BananaReq getBananaReq() throws ClassCastException { return (BananaReq)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `BananaReq`. + * + * @return true if the actual instance is of the type `BananaReq` + */ + public boolean isBananaReq() { + return super.getActualInstance() instanceof BananaReq; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java index db872114accf..c96839c8b1d1 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/GmFruit.java @@ -216,6 +216,15 @@ public Apple getApple() throws ClassCastException { return (Apple)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Apple`. + * + * @return true if the actual instance is of the type `Apple` + */ + public boolean isApple() { + return super.getActualInstance() instanceof Apple; + } + /** * Get the actual instance of `Banana`. If the actual instance is not `Banana`, * the ClassCastException will be thrown. @@ -227,6 +236,15 @@ public Banana getBanana() throws ClassCastException { return (Banana)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Banana`. + * + * @return true if the actual instance is of the type `Banana` + */ + public boolean isBanana() { + return super.getActualInstance() instanceof Banana; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java index 255106063b61..c75b34950ac4 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Mammal.java @@ -278,6 +278,15 @@ public Whale getWhale() throws ClassCastException { return (Whale)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Whale`. + * + * @return true if the actual instance is of the type `Whale` + */ + public boolean isWhale() { + return super.getActualInstance() instanceof Whale; + } + /** * Get the actual instance of `Zebra`. If the actual instance is not `Zebra`, * the ClassCastException will be thrown. @@ -290,6 +299,15 @@ public Zebra getZebra() throws ClassCastException { return (Zebra)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Zebra`. + * + * @return true if the actual instance is of the type `Zebra` + */ + public boolean isZebra() { + return super.getActualInstance() instanceof Zebra; + } + /** * Get the actual instance of `Pig`. If the actual instance is not `Pig`, * the ClassCastException will be thrown. @@ -302,6 +320,15 @@ public Pig getPig() throws ClassCastException { return (Pig)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Pig`. + * + * @return true if the actual instance is of the type `Pig` + */ + public boolean isPig() { + return super.getActualInstance() instanceof Pig; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/MammalAnyof.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/MammalAnyof.java index 36c647c45d81..09d48f5c080b 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/MammalAnyof.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/MammalAnyof.java @@ -277,6 +277,15 @@ public Whale getWhale() throws ClassCastException { return (Whale)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Whale`. + * + * @return true if the actual instance is of the type `Whale` + */ + public boolean isWhale() { + return super.getActualInstance() instanceof Whale; + } + /** * Get the actual instance of `Zebra`. If the actual instance is not `Zebra`, * the ClassCastException will be thrown. @@ -288,6 +297,15 @@ public Zebra getZebra() throws ClassCastException { return (Zebra)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Zebra`. + * + * @return true if the actual instance is of the type `Zebra` + */ + public boolean isZebra() { + return super.getActualInstance() instanceof Zebra; + } + /** * Get the actual instance of `Pig`. If the actual instance is not `Pig`, * the ClassCastException will be thrown. @@ -299,6 +317,15 @@ public Pig getPig() throws ClassCastException { return (Pig)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Pig`. + * + * @return true if the actual instance is of the type `Pig` + */ + public boolean isPig() { + return super.getActualInstance() instanceof Pig; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableFieldsMapResponse.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableFieldsMapResponse.java index 59c71a24b5a6..1d9f67e87e20 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableFieldsMapResponse.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableFieldsMapResponse.java @@ -218,6 +218,15 @@ public NullableFieldsMapSuccess getNullableFieldsMapSuccess() throws ClassCastEx return (NullableFieldsMapSuccess)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `NullableFieldsMapSuccess`. + * + * @return true if the actual instance is of the type `NullableFieldsMapSuccess` + */ + public boolean isNullableFieldsMapSuccess() { + return super.getActualInstance() instanceof NullableFieldsMapSuccess; + } + /** * Get the actual instance of `NullableFieldsMapError`. If the actual instance is not `NullableFieldsMapError`, * the ClassCastException will be thrown. @@ -229,6 +238,15 @@ public NullableFieldsMapError getNullableFieldsMapError() throws ClassCastExcept return (NullableFieldsMapError)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `NullableFieldsMapError`. + * + * @return true if the actual instance is of the type `NullableFieldsMapError` + */ + public boolean isNullableFieldsMapError() { + return super.getActualInstance() instanceof NullableFieldsMapError; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java index 18859d3ae9c0..ca72b58dd40e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/NullableShape.java @@ -248,6 +248,15 @@ public Triangle getTriangle() throws ClassCastException { return (Triangle)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Triangle`. + * + * @return true if the actual instance is of the type `Triangle` + */ + public boolean isTriangle() { + return super.getActualInstance() instanceof Triangle; + } + /** * Get the actual instance of `Quadrilateral`. If the actual instance is not `Quadrilateral`, * the ClassCastException will be thrown. @@ -260,6 +269,15 @@ public Quadrilateral getQuadrilateral() throws ClassCastException { return (Quadrilateral)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Quadrilateral`. + * + * @return true if the actual instance is of the type `Quadrilateral` + */ + public boolean isQuadrilateral() { + return super.getActualInstance() instanceof Quadrilateral; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java index cc2af5ecbb6e..12339a03d188 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Pig.java @@ -243,6 +243,15 @@ public BasquePig getBasquePig() throws ClassCastException { return (BasquePig)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `BasquePig`. + * + * @return true if the actual instance is of the type `BasquePig` + */ + public boolean isBasquePig() { + return super.getActualInstance() instanceof BasquePig; + } + /** * Get the actual instance of `DanishPig`. If the actual instance is not `DanishPig`, * the ClassCastException will be thrown. @@ -255,6 +264,15 @@ public DanishPig getDanishPig() throws ClassCastException { return (DanishPig)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `DanishPig`. + * + * @return true if the actual instance is of the type `DanishPig` + */ + public boolean isDanishPig() { + return super.getActualInstance() instanceof DanishPig; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java index 0e273b2efd19..08fe434c8d00 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Quadrilateral.java @@ -243,6 +243,15 @@ public SimpleQuadrilateral getSimpleQuadrilateral() throws ClassCastException { return (SimpleQuadrilateral)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `SimpleQuadrilateral`. + * + * @return true if the actual instance is of the type `SimpleQuadrilateral` + */ + public boolean isSimpleQuadrilateral() { + return super.getActualInstance() instanceof SimpleQuadrilateral; + } + /** * Get the actual instance of `ComplexQuadrilateral`. If the actual instance is not `ComplexQuadrilateral`, * the ClassCastException will be thrown. @@ -255,6 +264,15 @@ public ComplexQuadrilateral getComplexQuadrilateral() throws ClassCastException return (ComplexQuadrilateral)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `ComplexQuadrilateral`. + * + * @return true if the actual instance is of the type `ComplexQuadrilateral` + */ + public boolean isComplexQuadrilateral() { + return super.getActualInstance() instanceof ComplexQuadrilateral; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java index ad2fd9cad7b4..9f5ccb5001d2 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Scalar.java @@ -280,6 +280,15 @@ public UUID getUUID() throws ClassCastException { return (UUID)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `UUID`. + * + * @return true if the actual instance is of the type `UUID` + */ + public boolean isUUID() { + return super.getActualInstance() instanceof UUID; + } + /** * Get the actual instance of `String`. If the actual instance is not `String`, * the ClassCastException will be thrown. @@ -292,6 +301,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Get the actual instance of `BigDecimal`. If the actual instance is not `BigDecimal`, * the ClassCastException will be thrown. @@ -304,6 +322,15 @@ public BigDecimal getBigDecimal() throws ClassCastException { return (BigDecimal)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `BigDecimal`. + * + * @return true if the actual instance is of the type `BigDecimal` + */ + public boolean isBigDecimal() { + return super.getActualInstance() instanceof BigDecimal; + } + /** * Get the actual instance of `Boolean`. If the actual instance is not `Boolean`, * the ClassCastException will be thrown. @@ -316,6 +343,15 @@ public Boolean getBoolean() throws ClassCastException { return (Boolean)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Boolean`. + * + * @return true if the actual instance is of the type `Boolean` + */ + public boolean isBoolean() { + return super.getActualInstance() instanceof Boolean; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java index 81225f3a20e1..f360db82fc6b 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScalarAnyOf.java @@ -276,6 +276,15 @@ public UUID getUUID() throws ClassCastException { return (UUID)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `UUID`. + * + * @return true if the actual instance is of the type `UUID` + */ + public boolean isUUID() { + return super.getActualInstance() instanceof UUID; + } + /** * Get the actual instance of `String`. If the actual instance is not `String`, * the ClassCastException will be thrown. @@ -287,6 +296,15 @@ public String getString() throws ClassCastException { return (String)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `String`. + * + * @return true if the actual instance is of the type `String` + */ + public boolean isString() { + return super.getActualInstance() instanceof String; + } + /** * Get the actual instance of `BigDecimal`. If the actual instance is not `BigDecimal`, * the ClassCastException will be thrown. @@ -298,6 +316,15 @@ public BigDecimal getBigDecimal() throws ClassCastException { return (BigDecimal)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `BigDecimal`. + * + * @return true if the actual instance is of the type `BigDecimal` + */ + public boolean isBigDecimal() { + return super.getActualInstance() instanceof BigDecimal; + } + /** * Get the actual instance of `Boolean`. If the actual instance is not `Boolean`, * the ClassCastException will be thrown. @@ -309,6 +336,15 @@ public Boolean getBoolean() throws ClassCastException { return (Boolean)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Boolean`. + * + * @return true if the actual instance is of the type `Boolean` + */ + public boolean isBoolean() { + return super.getActualInstance() instanceof Boolean; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java index 8bb3fd0ef61e..c1d22ee77c1c 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Shape.java @@ -243,6 +243,15 @@ public Triangle getTriangle() throws ClassCastException { return (Triangle)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Triangle`. + * + * @return true if the actual instance is of the type `Triangle` + */ + public boolean isTriangle() { + return super.getActualInstance() instanceof Triangle; + } + /** * Get the actual instance of `Quadrilateral`. If the actual instance is not `Quadrilateral`, * the ClassCastException will be thrown. @@ -255,6 +264,15 @@ public Quadrilateral getQuadrilateral() throws ClassCastException { return (Quadrilateral)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Quadrilateral`. + * + * @return true if the actual instance is of the type `Quadrilateral` + */ + public boolean isQuadrilateral() { + return super.getActualInstance() instanceof Quadrilateral; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java index 74cbea6984a7..aa9f4af3b94f 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeOrNull.java @@ -248,6 +248,15 @@ public Triangle getTriangle() throws ClassCastException { return (Triangle)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Triangle`. + * + * @return true if the actual instance is of the type `Triangle` + */ + public boolean isTriangle() { + return super.getActualInstance() instanceof Triangle; + } + /** * Get the actual instance of `Quadrilateral`. If the actual instance is not `Quadrilateral`, * the ClassCastException will be thrown. @@ -260,6 +269,15 @@ public Quadrilateral getQuadrilateral() throws ClassCastException { return (Quadrilateral)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Quadrilateral`. + * + * @return true if the actual instance is of the type `Quadrilateral` + */ + public boolean isQuadrilateral() { + return super.getActualInstance() instanceof Quadrilateral; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java index e8b62b8a93dc..6e7f0aa18514 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Triangle.java @@ -278,6 +278,15 @@ public EquilateralTriangle getEquilateralTriangle() throws ClassCastException { return (EquilateralTriangle)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `EquilateralTriangle`. + * + * @return true if the actual instance is of the type `EquilateralTriangle` + */ + public boolean isEquilateralTriangle() { + return super.getActualInstance() instanceof EquilateralTriangle; + } + /** * Get the actual instance of `IsoscelesTriangle`. If the actual instance is not `IsoscelesTriangle`, * the ClassCastException will be thrown. @@ -290,6 +299,15 @@ public IsoscelesTriangle getIsoscelesTriangle() throws ClassCastException { return (IsoscelesTriangle)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `IsoscelesTriangle`. + * + * @return true if the actual instance is of the type `IsoscelesTriangle` + */ + public boolean isIsoscelesTriangle() { + return super.getActualInstance() instanceof IsoscelesTriangle; + } + /** * Get the actual instance of `ScaleneTriangle`. If the actual instance is not `ScaleneTriangle`, * the ClassCastException will be thrown. @@ -302,6 +320,15 @@ public ScaleneTriangle getScaleneTriangle() throws ClassCastException { return (ScaleneTriangle)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `ScaleneTriangle`. + * + * @return true if the actual instance is of the type `ScaleneTriangle` + */ + public boolean isScaleneTriangle() { + return super.getActualInstance() instanceof ScaleneTriangle; + } + /** * Validates the JSON Element and throws an exception if issues found * diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java index e224d1470bfd..fbd565d4ef18 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/Value.java @@ -230,6 +230,15 @@ public Scalar getScalar() throws ClassCastException { return (Scalar)super.getActualInstance(); } + /** + * Check if the actual instance is of the type `Scalar`. + * + * @return true if the actual instance is of the type `Scalar` + */ + public boolean isScalar() { + return super.getActualInstance() instanceof Scalar; + } + /** * Get the actual instance of `List<Scalar>`. If the actual instance is not `List<Scalar>`, * the ClassCastException will be thrown. From 831a93611a6731ed2c1dd04aefe4b55e66daf589 Mon Sep 17 00:00:00 2001 From: Spenser Jones Date: Thu, 5 Nov 2026 16:31:31 -0600 Subject: [PATCH 3/4] [java][okhttp-gson] Use a pet status example in the typed constructor test --- .../codegen/java/JavaClientCodegenTest.java | 12 ++++++------ .../okhttp-gson-composed-typed-constructors.yaml | 15 ++++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java index 92f9e3b8dc0e..c4c732d6c347 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java @@ -4574,13 +4574,13 @@ public void testOkHttpGsonOneOfAnyOfTypedConstructors() { validateJavaSourceFiles(files); final Path modelDir = output.resolve("src/main/java/org/openapitools/client/model"); - assertThat(modelDir.resolve("OpenTaxIdType.java")).content() + assertThat(modelDir.resolve("OpenPetStatus.java")).content() .contains( - "public OpenTaxIdType(Object o) {", - "public OpenTaxIdType(TaxIdType o) {", - "public OpenTaxIdType(String o) {", - "public boolean isTaxIdType() {", - "return super.getActualInstance() instanceof TaxIdType;", + "public OpenPetStatus(Object o) {", + "public OpenPetStatus(PetStatus o) {", + "public OpenPetStatus(String o) {", + "public boolean isPetStatus() {", + "return super.getActualInstance() instanceof PetStatus;", "public boolean isString() {"); assertThat(modelDir.resolve("Scalar.java")).content() .contains( diff --git a/modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml b/modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml index a2467462e7aa..c86fd80ec535 100644 --- a/modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml @@ -21,8 +21,8 @@ components: Composed: type: object properties: - taxIdType: - $ref: '#/components/schemas/OpenTaxIdType' + status: + $ref: '#/components/schemas/OpenPetStatus' scalar: $ref: '#/components/schemas/Scalar' petOrPets: @@ -35,14 +35,15 @@ components: $ref: '#/components/schemas/PetOrFreeForm' nullablePetOrName: $ref: '#/components/schemas/NullablePetOrName' - TaxIdType: + PetStatus: type: string enum: - - USA_SSN - - CAN_SIN - OpenTaxIdType: + - available + - pending + - sold + OpenPetStatus: anyOf: - - $ref: '#/components/schemas/TaxIdType' + - $ref: '#/components/schemas/PetStatus' - type: string Scalar: oneOf: From 0106e38656a20e137464229d9fbcae8542cd5126 Mon Sep 17 00:00:00 2001 From: Spenser Jones Date: Mon, 9 Nov 2026 16:27:51 -0600 Subject: [PATCH 4/4] [java][okhttp-gson] Skip is() for a member named Nullable and test any-type members --- .../codegen/languages/JavaClientCodegen.java | 10 ++++++++++ .../okhttp-gson/anyof_model.mustache | 2 ++ .../okhttp-gson/oneof_model.mustache | 2 ++ .../codegen/java/JavaClientCodegenTest.java | 13 ++++++++++++- ...http-gson-composed-typed-constructors.yaml | 19 ++++++++++++++++++- 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index c2b1a9aa93b0..d840194d688f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -46,6 +46,7 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Stream; import static com.google.common.base.CaseFormat.LOWER_CAMEL; import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; @@ -1255,6 +1256,15 @@ public Map postProcessAllModels(Map objs) break; } } + // AbstractOpenApiSchema already declares Boolean isNullable(), so a oneOf/anyOf + // member named Nullable gets no is() check + if (cm.getComposedSchemas() != null) { + Stream.of(cm.getComposedSchemas().getOneOf(), cm.getComposedSchemas().getAnyOf()) + .filter(Objects::nonNull) + .flatMap(List::stream) + .filter(member -> "Nullable".equals(sanitizeDataType(member.dataType))) + .forEach(member -> member.vendorExtensions.put("x-is-method-inherited", true)); + } } } return objs; diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache index 4fea268cce91..7ea7f78eb39d 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/anyof_model.mustache @@ -343,6 +343,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im return ({{{dataType}}})super.getActualInstance(); } + {{^vendorExtensions.x-is-method-inherited}} {{^isContainer}} {{^isAnyType}} {{^isFreeFormObject}} @@ -358,6 +359,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im {{/isFreeFormObject}} {{/isAnyType}} {{/isContainer}} + {{/vendorExtensions.x-is-method-inherited}} {{/vendorExtensions.x-duplicated-data-type-ignoring-erasure}} {{/anyOf}} {{/composedSchemas}} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache index 71bb15de1712..d5c5b6532d53 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/oneof_model.mustache @@ -394,6 +394,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im return ({{{dataType}}})super.getActualInstance(); } + {{^vendorExtensions.x-is-method-inherited}} {{^isContainer}} {{^isAnyType}} {{^isFreeFormObject}} @@ -409,6 +410,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im {{/isFreeFormObject}} {{/isAnyType}} {{/isContainer}} + {{/vendorExtensions.x-is-method-inherited}} {{/vendorExtensions.x-duplicated-data-type-ignoring-erasure}} {{/oneOf}} {{/composedSchemas}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java index c4c732d6c347..cb33d40b0a30 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java @@ -4596,14 +4596,25 @@ public void testOkHttpGsonOneOfAnyOfTypedConstructors() { assertThat(modelDir.resolve("Numbers.java")).content() .contains("public Numbers(List o) {") .doesNotContain("public Numbers(List o) {"); - // A free-form member is an Object, which the existing constructor already accepts + // Free-form and any-type members are an Object, which the existing constructor already accepts // and which every instance would match. + assertThat(modelDir.resolve("PetOrAnything.java")).content() + .containsOnlyOnce("public PetOrAnything(Object o) {") + .contains("public PetOrAnything(Pet o) {", "public boolean isPet() {", "public Object getObject() throws ClassCastException {") + .doesNotContain("public boolean isObject() {"); assertThat(modelDir.resolve("PetOrFreeForm.java")).content() .containsOnlyOnce("public PetOrFreeForm(Object o) {") .contains("public PetOrFreeForm(Pet o) {", "public boolean isPet() {") .doesNotContain("public boolean isObject() {"); assertThat(modelDir.resolve("NullablePetOrName.java")).content() .contains("public NullablePetOrName(Pet o) {", "public NullablePetOrName(String o) {"); + // AbstractOpenApiSchema already declares Boolean isNullable() + assertThat(modelDir.resolve("PetOrNullable.java")).content() + .contains("public PetOrNullable(Nullable o) {", "public Nullable getNullable() throws ClassCastException {", "public boolean isPet() {") + .doesNotContain("public boolean isNullable() {"); + assertThat(modelDir.resolve("NullableOrName.java")).content() + .contains("public NullableOrName(Nullable o) {", "public Nullable getNullable() throws ClassCastException {", "public boolean isString() {") + .doesNotContain("public boolean isNullable() {"); } @Test diff --git a/modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml b/modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml index c86fd80ec535..592eb723cd5f 100644 --- a/modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/java/okhttp-gson-composed-typed-constructors.yaml @@ -35,6 +35,10 @@ components: $ref: '#/components/schemas/PetOrFreeForm' nullablePetOrName: $ref: '#/components/schemas/NullablePetOrName' + petOrNullable: + $ref: '#/components/schemas/PetOrNullable' + nullableOrName: + $ref: '#/components/schemas/NullableOrName' PetStatus: type: string enum: @@ -75,7 +79,7 @@ components: PetOrAnything: anyOf: - $ref: '#/components/schemas/Pet' - - {} + - description: Any value PetOrFreeForm: oneOf: - $ref: '#/components/schemas/Pet' @@ -85,3 +89,16 @@ components: 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