diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 1ab927a6a26c..5b6c12647702 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -2688,6 +2688,9 @@ protected void updateModelForAnyType(CodegenModel m, Schema schema) { addAdditionPropertiesToCodeGenModel(m, schema); m.isMap = true; } + if (m.parent == null && !Objects.equals(m.dataType, "Object")) { + m.parent = m.dataType; + } if (schema.getProperties() != null || schema.getRequired() != null && !(schema instanceof ComposedSchema)) { // passing null to allProperties and allRequired as there's no parent addVars(m, unaliasPropertySchema(schema.getProperties()), schema.getRequired(), null, null); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index 29c7066193d7..0c3754b86965 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -984,19 +984,19 @@ public void testAllOfSingleAndDoubleRefWithOwnPropsNoDiscriminator() { // to test allOf with double refs Schema supermanSchema = openAPI.getComponents().getSchemas().get("SuperMan"); CodegenModel supermanModel = codegen.fromModel("SuperMan", supermanSchema); - Assert.assertNull(supermanModel.parent); + Assert.assertEquals(supermanModel.parent, "Human"); Assert.assertEquals(supermanModel.allParents, null); // to test allOf with single ref Schema superboySchema = openAPI.getComponents().getSchemas().get("SuperBoy"); CodegenModel superboyModel = codegen.fromModel("SuperBoy", superboySchema); - Assert.assertNull(superboyModel.parent); + Assert.assertEquals(superboyModel.parent, "Human"); Assert.assertEquals(superboyModel.allParents, null); // to test allOf with single ref and no "type: object" in the (last) inline schema Schema superbabySchema = openAPI.getComponents().getSchemas().get("SuperBaby"); CodegenModel superbabyModel = codegen.fromModel("SuperBaby", superbabySchema); - Assert.assertNull(superbabyModel.parent); + Assert.assertEquals(superbabyModel.parent, "Human"); Assert.assertEquals(superbabyModel.allParents, null); } @@ -1602,7 +1602,7 @@ public void testAllOfSingleRefNoOwnProps() { codegen.setOpenAPI(openAPI); CodegenModel model = codegen.fromModel("NewMessageEventCoreNoOwnProps", schema); Assert.assertEquals(getNames(model.getVars()), Arrays.asList("id", "message")); - Assert.assertNull(model.parent); + Assert.assertEquals(model.parent, "MessageEventCore"); Assert.assertNull(model.allParents); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java index 028316f4193f..380aa61db478 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java @@ -335,7 +335,7 @@ public void mapModelTest() { Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a map model"); Assert.assertEquals(cm.vars.size(), 0); - Assert.assertEquals(cm.parent, null); + Assert.assertEquals(cm.parent, "dict"); Assert.assertEquals(cm.imports.size(), 1); } diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java index 0a5b037ab6e5..fe36c9c0ba1d 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java @@ -42,7 +42,7 @@ ComplexQuadrilateral.JSON_PROPERTY_QUADRILATERAL_TYPE }) @jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ComplexQuadrilateral { +public class ComplexQuadrilateral extends ShapeInterface { public static final String JSON_PROPERTY_SHAPE_TYPE = "shapeType"; private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { ComplexQuadrilateral complexQuadrilateral = (ComplexQuadrilateral) o; return Objects.equals(this.shapeType, complexQuadrilateral.shapeType) && Objects.equals(this.quadrilateralType, complexQuadrilateral.quadrilateralType)&& - Objects.equals(this.additionalProperties, complexQuadrilateral.additionalProperties); + Objects.equals(this.additionalProperties, complexQuadrilateral.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, quadrilateralType, additionalProperties); + return Objects.hash(shapeType, quadrilateralType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ComplexQuadrilateral {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" quadrilateralType: ").append(toIndentedString(quadrilateralType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/EquilateralTriangle.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/EquilateralTriangle.java index 217e53a7d871..2d65ef7321d7 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/EquilateralTriangle.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/EquilateralTriangle.java @@ -42,7 +42,7 @@ EquilateralTriangle.JSON_PROPERTY_TRIANGLE_TYPE }) @jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class EquilateralTriangle { +public class EquilateralTriangle extends ShapeInterface { public static final String JSON_PROPERTY_SHAPE_TYPE = "shapeType"; private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { EquilateralTriangle equilateralTriangle = (EquilateralTriangle) o; return Objects.equals(this.shapeType, equilateralTriangle.shapeType) && Objects.equals(this.triangleType, equilateralTriangle.triangleType)&& - Objects.equals(this.additionalProperties, equilateralTriangle.additionalProperties); + Objects.equals(this.additionalProperties, equilateralTriangle.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, triangleType, additionalProperties); + return Objects.hash(shapeType, triangleType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class EquilateralTriangle {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" triangleType: ").append(toIndentedString(triangleType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java index 19e71a3b53c1..9359666f465b 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java @@ -38,7 +38,7 @@ IsoscelesTriangle.JSON_PROPERTY_TRIANGLE_TYPE }) @jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class IsoscelesTriangle { +public class IsoscelesTriangle extends ShapeInterface { public static final String JSON_PROPERTY_SHAPE_TYPE = "shapeType"; private String shapeType; @@ -113,18 +113,20 @@ public boolean equals(Object o) { } IsoscelesTriangle isoscelesTriangle = (IsoscelesTriangle) o; return Objects.equals(this.shapeType, isoscelesTriangle.shapeType) && - Objects.equals(this.triangleType, isoscelesTriangle.triangleType); + Objects.equals(this.triangleType, isoscelesTriangle.triangleType) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, triangleType); + return Objects.hash(shapeType, triangleType, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class IsoscelesTriangle {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" triangleType: ").append(toIndentedString(triangleType)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ScaleneTriangle.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ScaleneTriangle.java index 15bc62cc8e60..7f57f68ef6d0 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ScaleneTriangle.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/ScaleneTriangle.java @@ -42,7 +42,7 @@ ScaleneTriangle.JSON_PROPERTY_TRIANGLE_TYPE }) @jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ScaleneTriangle { +public class ScaleneTriangle extends ShapeInterface { public static final String JSON_PROPERTY_SHAPE_TYPE = "shapeType"; private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { ScaleneTriangle scaleneTriangle = (ScaleneTriangle) o; return Objects.equals(this.shapeType, scaleneTriangle.shapeType) && Objects.equals(this.triangleType, scaleneTriangle.triangleType)&& - Objects.equals(this.additionalProperties, scaleneTriangle.additionalProperties); + Objects.equals(this.additionalProperties, scaleneTriangle.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, triangleType, additionalProperties); + return Objects.hash(shapeType, triangleType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ScaleneTriangle {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" triangleType: ").append(toIndentedString(triangleType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java index 87fcfee6f40a..c144a270673e 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java @@ -42,7 +42,7 @@ SimpleQuadrilateral.JSON_PROPERTY_QUADRILATERAL_TYPE }) @jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class SimpleQuadrilateral { +public class SimpleQuadrilateral extends ShapeInterface { public static final String JSON_PROPERTY_SHAPE_TYPE = "shapeType"; private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { SimpleQuadrilateral simpleQuadrilateral = (SimpleQuadrilateral) o; return Objects.equals(this.shapeType, simpleQuadrilateral.shapeType) && Objects.equals(this.quadrilateralType, simpleQuadrilateral.quadrilateralType)&& - Objects.equals(this.additionalProperties, simpleQuadrilateral.additionalProperties); + Objects.equals(this.additionalProperties, simpleQuadrilateral.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, quadrilateralType, additionalProperties); + return Objects.hash(shapeType, quadrilateralType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class SimpleQuadrilateral {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" quadrilateralType: ").append(toIndentedString(quadrilateralType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java index 92b5eaf18995..2d50931040fc 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java @@ -242,7 +242,6 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri .registerTypeAdapterFactory(new org.openapitools.client.model.DanishPig.CustomTypeAdapterFactory()) .registerTypeAdapterFactory(new org.openapitools.client.model.DeprecatedObject.CustomTypeAdapterFactory()) .registerTypeAdapterFactory(new org.openapitools.client.model.Dog.CustomTypeAdapterFactory()) - .registerTypeAdapterFactory(new org.openapitools.client.model.DogAllOf.CustomTypeAdapterFactory()) .registerTypeAdapterFactory(new org.openapitools.client.model.Drawing.CustomTypeAdapterFactory()) .registerTypeAdapterFactory(new org.openapitools.client.model.EnumArrays.CustomTypeAdapterFactory()) .registerTypeAdapterFactory(new org.openapitools.client.model.EnumTest.CustomTypeAdapterFactory()) @@ -281,7 +280,6 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri .registerTypeAdapterFactory(new org.openapitools.client.model.ReadOnlyFirst.CustomTypeAdapterFactory()) .registerTypeAdapterFactory(new org.openapitools.client.model.ScaleneTriangle.CustomTypeAdapterFactory()) .registerTypeAdapterFactory(new org.openapitools.client.model.Shape.CustomTypeAdapterFactory()) - .registerTypeAdapterFactory(new org.openapitools.client.model.ShapeInterface.CustomTypeAdapterFactory()) .registerTypeAdapterFactory(new org.openapitools.client.model.ShapeOrNull.CustomTypeAdapterFactory()) .registerTypeAdapterFactory(new org.openapitools.client.model.SimpleQuadrilateral.CustomTypeAdapterFactory()) .registerTypeAdapterFactory(new org.openapitools.client.model.SpecialModelName.CustomTypeAdapterFactory()) diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOfInlineAllOfArrayAllofDogPropertyInner.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOfInlineAllOfArrayAllofDogPropertyInner.java index b04874108033..f087e5cd742d 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOfInlineAllOfArrayAllofDogPropertyInner.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ArrayOfInlineAllOfArrayAllofDogPropertyInner.java @@ -50,7 +50,7 @@ * ArrayOfInlineAllOfArrayAllofDogPropertyInner */ @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ArrayOfInlineAllOfArrayAllofDogPropertyInner { +public class ArrayOfInlineAllOfArrayAllofDogPropertyInner extends DogAllOf { public static final String SERIALIZED_NAME_BREED = "breed"; @SerializedName(SERIALIZED_NAME_BREED) private String breed; @@ -155,18 +155,20 @@ public boolean equals(Object o) { ArrayOfInlineAllOfArrayAllofDogPropertyInner arrayOfInlineAllOfArrayAllofDogPropertyInner = (ArrayOfInlineAllOfArrayAllofDogPropertyInner) o; return Objects.equals(this.breed, arrayOfInlineAllOfArrayAllofDogPropertyInner.breed) && Objects.equals(this.color, arrayOfInlineAllOfArrayAllofDogPropertyInner.color)&& - Objects.equals(this.additionalProperties, arrayOfInlineAllOfArrayAllofDogPropertyInner.additionalProperties); + Objects.equals(this.additionalProperties, arrayOfInlineAllOfArrayAllofDogPropertyInner.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(breed, color, additionalProperties); + return Objects.hash(breed, color, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ArrayOfInlineAllOfArrayAllofDogPropertyInner {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" breed: ").append(toIndentedString(breed)).append("\n"); sb.append(" color: ").append(toIndentedString(color)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java index 1a73911047f5..7406463715f7 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java @@ -50,7 +50,7 @@ * ComplexQuadrilateral */ @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ComplexQuadrilateral { +public class ComplexQuadrilateral extends ShapeInterface { public static final String SERIALIZED_NAME_SHAPE_TYPE = "shapeType"; @SerializedName(SERIALIZED_NAME_SHAPE_TYPE) private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { ComplexQuadrilateral complexQuadrilateral = (ComplexQuadrilateral) o; return Objects.equals(this.shapeType, complexQuadrilateral.shapeType) && Objects.equals(this.quadrilateralType, complexQuadrilateral.quadrilateralType)&& - Objects.equals(this.additionalProperties, complexQuadrilateral.additionalProperties); + Objects.equals(this.additionalProperties, complexQuadrilateral.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, quadrilateralType, additionalProperties); + return Objects.hash(shapeType, quadrilateralType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ComplexQuadrilateral {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" quadrilateralType: ").append(toIndentedString(quadrilateralType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/DogAllOf.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/DogAllOf.java index a15a3e0929ac..7624b4bd1781 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/DogAllOf.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/DogAllOf.java @@ -186,69 +186,6 @@ public static void validateJsonObject(JsonObject jsonObj) throws IOException { } } - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!DogAllOf.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'DogAllOf' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(DogAllOf.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, DogAllOf value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - obj.remove("additionalProperties"); - // serialize additonal properties - if (value.getAdditionalProperties() != null) { - for (Map.Entry entry : value.getAdditionalProperties().entrySet()) { - if (entry.getValue() instanceof String) - obj.addProperty(entry.getKey(), (String) entry.getValue()); - else if (entry.getValue() instanceof Number) - obj.addProperty(entry.getKey(), (Number) entry.getValue()); - else if (entry.getValue() instanceof Boolean) - obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); - else if (entry.getValue() instanceof Character) - obj.addProperty(entry.getKey(), (Character) entry.getValue()); - else { - obj.add(entry.getKey(), gson.toJsonTree(entry.getValue()).getAsJsonObject()); - } - } - } - elementAdapter.write(out, obj); - } - - @Override - public DogAllOf read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - // store additional fields in the deserialized instance - DogAllOf instance = thisAdapter.fromJsonTree(jsonObj); - for (Map.Entry entry : jsonObj.entrySet()) { - if (!openapiFields.contains(entry.getKey())) { - if (entry.getValue().isJsonPrimitive()) { // primitive type - if (entry.getValue().getAsJsonPrimitive().isString()) - instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); - else if (entry.getValue().getAsJsonPrimitive().isNumber()) - instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); - else if (entry.getValue().getAsJsonPrimitive().isBoolean()) - instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); - else - throw new IllegalArgumentException(String.format("The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); - } else { // non-primitive type - instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); - } - } - } - return instance; - } - - }.nullSafe(); - } - } /** * Create an instance of DogAllOf given an JSON string diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/EquilateralTriangle.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/EquilateralTriangle.java index 37e46b978d4b..1869e4982740 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/EquilateralTriangle.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/EquilateralTriangle.java @@ -50,7 +50,7 @@ * EquilateralTriangle */ @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class EquilateralTriangle { +public class EquilateralTriangle extends ShapeInterface { public static final String SERIALIZED_NAME_SHAPE_TYPE = "shapeType"; @SerializedName(SERIALIZED_NAME_SHAPE_TYPE) private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { EquilateralTriangle equilateralTriangle = (EquilateralTriangle) o; return Objects.equals(this.shapeType, equilateralTriangle.shapeType) && Objects.equals(this.triangleType, equilateralTriangle.triangleType)&& - Objects.equals(this.additionalProperties, equilateralTriangle.additionalProperties); + Objects.equals(this.additionalProperties, equilateralTriangle.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, triangleType, additionalProperties); + return Objects.hash(shapeType, triangleType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class EquilateralTriangle {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" triangleType: ").append(toIndentedString(triangleType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java index df7563afde93..bd4616cede1a 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java @@ -50,7 +50,7 @@ * IsoscelesTriangle */ @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class IsoscelesTriangle { +public class IsoscelesTriangle extends ShapeInterface { public static final String SERIALIZED_NAME_SHAPE_TYPE = "shapeType"; @SerializedName(SERIALIZED_NAME_SHAPE_TYPE) private String shapeType; @@ -119,18 +119,20 @@ public boolean equals(Object o) { } IsoscelesTriangle isoscelesTriangle = (IsoscelesTriangle) o; return Objects.equals(this.shapeType, isoscelesTriangle.shapeType) && - Objects.equals(this.triangleType, isoscelesTriangle.triangleType); + Objects.equals(this.triangleType, isoscelesTriangle.triangleType) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, triangleType); + return Objects.hash(shapeType, triangleType, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class IsoscelesTriangle {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" triangleType: ").append(toIndentedString(triangleType)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScaleneTriangle.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScaleneTriangle.java index a15c2fa880f4..a7b092c05d77 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScaleneTriangle.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ScaleneTriangle.java @@ -50,7 +50,7 @@ * ScaleneTriangle */ @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ScaleneTriangle { +public class ScaleneTriangle extends ShapeInterface { public static final String SERIALIZED_NAME_SHAPE_TYPE = "shapeType"; @SerializedName(SERIALIZED_NAME_SHAPE_TYPE) private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { ScaleneTriangle scaleneTriangle = (ScaleneTriangle) o; return Objects.equals(this.shapeType, scaleneTriangle.shapeType) && Objects.equals(this.triangleType, scaleneTriangle.triangleType)&& - Objects.equals(this.additionalProperties, scaleneTriangle.additionalProperties); + Objects.equals(this.additionalProperties, scaleneTriangle.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, triangleType, additionalProperties); + return Objects.hash(shapeType, triangleType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ScaleneTriangle {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" triangleType: ").append(toIndentedString(triangleType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeInterface.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeInterface.java index 4eba102348e9..c69befd7b6a8 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeInterface.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/ShapeInterface.java @@ -182,81 +182,11 @@ public static void validateJsonObject(JsonObject jsonObj) throws IOException { throw new IllegalArgumentException(String.format("The required field(s) %s in ShapeInterface is not found in the empty JSON string", ShapeInterface.openapiRequiredFields.toString())); } } - - // check to make sure all required properties/fields are present in the JSON string - for (String requiredField : ShapeInterface.openapiRequiredFields) { - if (jsonObj.get(requiredField) == null) { - throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString())); - } - } if (jsonObj.get("shapeType") != null && !jsonObj.get("shapeType").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `shapeType` to be a primitive type in the JSON string but got `%s`", jsonObj.get("shapeType").toString())); } } - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!ShapeInterface.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'ShapeInterface' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(ShapeInterface.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, ShapeInterface value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - obj.remove("additionalProperties"); - // serialize additonal properties - if (value.getAdditionalProperties() != null) { - for (Map.Entry entry : value.getAdditionalProperties().entrySet()) { - if (entry.getValue() instanceof String) - obj.addProperty(entry.getKey(), (String) entry.getValue()); - else if (entry.getValue() instanceof Number) - obj.addProperty(entry.getKey(), (Number) entry.getValue()); - else if (entry.getValue() instanceof Boolean) - obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); - else if (entry.getValue() instanceof Character) - obj.addProperty(entry.getKey(), (Character) entry.getValue()); - else { - obj.add(entry.getKey(), gson.toJsonTree(entry.getValue()).getAsJsonObject()); - } - } - } - elementAdapter.write(out, obj); - } - - @Override - public ShapeInterface read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - // store additional fields in the deserialized instance - ShapeInterface instance = thisAdapter.fromJsonTree(jsonObj); - for (Map.Entry entry : jsonObj.entrySet()) { - if (!openapiFields.contains(entry.getKey())) { - if (entry.getValue().isJsonPrimitive()) { // primitive type - if (entry.getValue().getAsJsonPrimitive().isString()) - instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); - else if (entry.getValue().getAsJsonPrimitive().isNumber()) - instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); - else if (entry.getValue().getAsJsonPrimitive().isBoolean()) - instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); - else - throw new IllegalArgumentException(String.format("The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); - } else { // non-primitive type - instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); - } - } - } - return instance; - } - - }.nullSafe(); - } - } /** * Create an instance of ShapeInterface given an JSON string diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java index d08035d83332..de4d9090cf50 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java @@ -50,7 +50,7 @@ * SimpleQuadrilateral */ @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class SimpleQuadrilateral { +public class SimpleQuadrilateral extends ShapeInterface { public static final String SERIALIZED_NAME_SHAPE_TYPE = "shapeType"; @SerializedName(SERIALIZED_NAME_SHAPE_TYPE) private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { SimpleQuadrilateral simpleQuadrilateral = (SimpleQuadrilateral) o; return Objects.equals(this.shapeType, simpleQuadrilateral.shapeType) && Objects.equals(this.quadrilateralType, simpleQuadrilateral.quadrilateralType)&& - Objects.equals(this.additionalProperties, simpleQuadrilateral.additionalProperties); + Objects.equals(this.additionalProperties, simpleQuadrilateral.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, quadrilateralType, additionalProperties); + return Objects.hash(shapeType, quadrilateralType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class SimpleQuadrilateral {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" quadrilateralType: ").append(toIndentedString(quadrilateralType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java index f0a582f87f25..3d5fa9f0d640 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ComplexQuadrilateral.java @@ -42,7 +42,7 @@ ComplexQuadrilateral.JSON_PROPERTY_QUADRILATERAL_TYPE }) @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ComplexQuadrilateral { +public class ComplexQuadrilateral extends ShapeInterface { public static final String JSON_PROPERTY_SHAPE_TYPE = "shapeType"; private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { ComplexQuadrilateral complexQuadrilateral = (ComplexQuadrilateral) o; return Objects.equals(this.shapeType, complexQuadrilateral.shapeType) && Objects.equals(this.quadrilateralType, complexQuadrilateral.quadrilateralType)&& - Objects.equals(this.additionalProperties, complexQuadrilateral.additionalProperties); + Objects.equals(this.additionalProperties, complexQuadrilateral.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, quadrilateralType, additionalProperties); + return Objects.hash(shapeType, quadrilateralType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ComplexQuadrilateral {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" quadrilateralType: ").append(toIndentedString(quadrilateralType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EquilateralTriangle.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EquilateralTriangle.java index 0e13e5eaebf0..cd7f4e7966db 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EquilateralTriangle.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/EquilateralTriangle.java @@ -42,7 +42,7 @@ EquilateralTriangle.JSON_PROPERTY_TRIANGLE_TYPE }) @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class EquilateralTriangle { +public class EquilateralTriangle extends ShapeInterface { public static final String JSON_PROPERTY_SHAPE_TYPE = "shapeType"; private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { EquilateralTriangle equilateralTriangle = (EquilateralTriangle) o; return Objects.equals(this.shapeType, equilateralTriangle.shapeType) && Objects.equals(this.triangleType, equilateralTriangle.triangleType)&& - Objects.equals(this.additionalProperties, equilateralTriangle.additionalProperties); + Objects.equals(this.additionalProperties, equilateralTriangle.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, triangleType, additionalProperties); + return Objects.hash(shapeType, triangleType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class EquilateralTriangle {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" triangleType: ").append(toIndentedString(triangleType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java index eb0448b30d1b..dd4d1b505b64 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/IsoscelesTriangle.java @@ -38,7 +38,7 @@ IsoscelesTriangle.JSON_PROPERTY_TRIANGLE_TYPE }) @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class IsoscelesTriangle { +public class IsoscelesTriangle extends ShapeInterface { public static final String JSON_PROPERTY_SHAPE_TYPE = "shapeType"; private String shapeType; @@ -113,18 +113,20 @@ public boolean equals(Object o) { } IsoscelesTriangle isoscelesTriangle = (IsoscelesTriangle) o; return Objects.equals(this.shapeType, isoscelesTriangle.shapeType) && - Objects.equals(this.triangleType, isoscelesTriangle.triangleType); + Objects.equals(this.triangleType, isoscelesTriangle.triangleType) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, triangleType); + return Objects.hash(shapeType, triangleType, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class IsoscelesTriangle {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" triangleType: ").append(toIndentedString(triangleType)).append("\n"); sb.append("}"); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ScaleneTriangle.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ScaleneTriangle.java index 143f82323c62..b71712c2ab46 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ScaleneTriangle.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/ScaleneTriangle.java @@ -42,7 +42,7 @@ ScaleneTriangle.JSON_PROPERTY_TRIANGLE_TYPE }) @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ScaleneTriangle { +public class ScaleneTriangle extends ShapeInterface { public static final String JSON_PROPERTY_SHAPE_TYPE = "shapeType"; private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { ScaleneTriangle scaleneTriangle = (ScaleneTriangle) o; return Objects.equals(this.shapeType, scaleneTriangle.shapeType) && Objects.equals(this.triangleType, scaleneTriangle.triangleType)&& - Objects.equals(this.additionalProperties, scaleneTriangle.additionalProperties); + Objects.equals(this.additionalProperties, scaleneTriangle.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, triangleType, additionalProperties); + return Objects.hash(shapeType, triangleType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ScaleneTriangle {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" triangleType: ").append(toIndentedString(triangleType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java index 61ae59418898..4cc7822d11dc 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/SimpleQuadrilateral.java @@ -42,7 +42,7 @@ SimpleQuadrilateral.JSON_PROPERTY_QUADRILATERAL_TYPE }) @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class SimpleQuadrilateral { +public class SimpleQuadrilateral extends ShapeInterface { public static final String JSON_PROPERTY_SHAPE_TYPE = "shapeType"; private String shapeType; @@ -155,18 +155,20 @@ public boolean equals(Object o) { SimpleQuadrilateral simpleQuadrilateral = (SimpleQuadrilateral) o; return Objects.equals(this.shapeType, simpleQuadrilateral.shapeType) && Objects.equals(this.quadrilateralType, simpleQuadrilateral.quadrilateralType)&& - Objects.equals(this.additionalProperties, simpleQuadrilateral.additionalProperties); + Objects.equals(this.additionalProperties, simpleQuadrilateral.additionalProperties) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(shapeType, quadrilateralType, additionalProperties); + return Objects.hash(shapeType, quadrilateralType, super.hashCode(), additionalProperties); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class SimpleQuadrilateral {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" shapeType: ").append(toIndentedString(shapeType)).append("\n"); sb.append(" quadrilateralType: ").append(toIndentedString(quadrilateralType)).append("\n"); sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");