add isOverridden, update java pojo with setter for parent prop (#15051)

This commit is contained in:
William Cheng
2023-03-29 10:57:49 +08:00
committed by GitHub
parent 36332331e4
commit 9fa032b365
850 changed files with 645 additions and 796 deletions

View File

@@ -159,6 +159,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
public boolean isCircularReference;
public boolean isDiscriminator;
public boolean isNew; // true when this property overrides an inherited property
public Boolean isOverridden; // true if the property is a parent property (not defined in child/current schema)
public List<String> _enum;
public Map<String, Object> allowableValues;
// If 'additionalProperties' is not set, items is null.
@@ -1067,6 +1068,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
sb.append(", isCircularReference=").append(isCircularReference);
sb.append(", isDiscriminator=").append(isDiscriminator);
sb.append(", isNew=").append(isNew);
sb.append(", isOverridden=").append(isOverridden);
sb.append(", _enum=").append(_enum);
sb.append(", allowableValues=").append(allowableValues);
sb.append(", items=").append(items);
@@ -1159,6 +1161,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
isCircularReference == that.isCircularReference &&
isDiscriminator == that.isDiscriminator &&
isNew == that.isNew &&
isOverridden == that.isOverridden &&
hasValidation == that.hasValidation &&
isInherited == that.isInherited &&
isXmlAttribute == that.isXmlAttribute &&
@@ -1236,7 +1239,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isFile,
isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword, isFreeFormObject,
isArray, isMap, isEnum, isInnerEnum, isEnumRef, isAnyType, isReadOnly, isWriteOnly, isNullable, isShort,
isUnboundedInteger, isSelfReference, isCircularReference, isDiscriminator, isNew, _enum,
isUnboundedInteger, isSelfReference, isCircularReference, isDiscriminator, isNew, isOverridden, _enum,
allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars,
vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase,
nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName,

View File

@@ -5724,6 +5724,7 @@ public class DefaultCodegen implements CodegenConfig {
for (CodegenProperty var : cm.vars) {
// create a map of codegen properties for lookup later
varsMap.put(var.baseName, var);
var.isOverridden = false;
}
}
}
@@ -5748,6 +5749,10 @@ public class DefaultCodegen implements CodegenConfig {
cp = fromProperty(key, prop, mandatory.contains(key));
}
if (cm != null && cm.allVars == vars && cp.isOverridden == null) { // processing allVars and it's a parent property
cp.isOverridden = true;
}
vars.add(cp);
m.setHasVars(true);

View File

@@ -270,7 +270,23 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
{{/isReadOnly}}
{{/vars}}
{{#parent}}
{{#allVars}}
{{#isOverridden}}
@Override
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
{{#vendorExtensions.x-is-jackson-optional-nullable}}
this.{{setter}}(JsonNullable.<{{{datatypeWithEnum}}}>of({{name}}));
{{/vendorExtensions.x-is-jackson-optional-nullable}}
{{^vendorExtensions.x-is-jackson-optional-nullable}}
this.{{setter}}({{name}});
{{/vendorExtensions.x-is-jackson-optional-nullable}}
return this;
}
{{/isOverridden}}
{{/allVars}}
{{/parent}}
@Override
public boolean equals(Object o) {
{{#useReflectionEqualsHashCode}}

View File

@@ -1908,4 +1908,50 @@ public class JavaClientCodegenTest {
assertFileNotContains(Paths.get(outputPath + "/src/main/java/org/openapitools/client/model/Pet.java"), "@JsonSubTypes.Type(value = Dog.class, name = \"Dog\")");
assertFileNotContains(Paths.get(outputPath + "/src/main/java/org/openapitools/client/model/Pet.java"), "@JsonSubTypes.Type(value = Lizard.class, name = \"Lizard\")");
}
@Test
public void testIsOverriddenProperty() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOf_composition_discriminator.yaml");
JavaClientCodegen codegen = new JavaClientCodegen();
Schema test1 = openAPI.getComponents().getSchemas().get("Cat");
codegen.setOpenAPI(openAPI);
CodegenModel cm1 = codegen.fromModel("Cat", test1);
CodegenProperty cp0 = cm1.getAllVars().get(0);
Assert.assertEquals(cp0.getName(), "petType");
Assert.assertEquals(cp0.isOverridden, true);
CodegenProperty cp1 = cm1.getAllVars().get(1);
Assert.assertEquals(cp1.getName(), "name");
Assert.assertEquals(cp1.isOverridden, false);
}
@Test
public void testForJavaApacheHttpClientOverrideSetter() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
String outputPath = output.getAbsolutePath().replace('\\', '/');
OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/3_0/allOf_composition_discriminator.yaml", null, new ParseOptions()).getOpenAPI();
JavaClientCodegen codegen = new JavaClientCodegen();
codegen.setOutputDir(output.getAbsolutePath());
ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);
DefaultGenerator generator = new DefaultGenerator();
codegen.setLibrary(JavaClientCodegen.APACHE);
generator.opts(input).generate();
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/client/model/Cat.java"), " @Override\n" +
" public Cat petType(String petType) {");
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/client/model/Pet.java"), " }\n" +
"\n" +
" public Pet petType(String petType) {\n");
}
}

View File

@@ -95,7 +95,6 @@ public class Bird {
this.color = color;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -95,7 +95,6 @@ public class Category {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -130,6 +130,17 @@ public class DataQuery extends Query {
this.date = date;
}
@Override
public DataQuery id(Long id) {
this.setId(id);
return this;
}
@Override
public DataQuery outcomes(List<OutcomesEnum> outcomes) {
this.setOutcomes(outcomes);
return this;
}
@Override
public boolean equals(Object o) {

View File

@@ -127,7 +127,6 @@ public class DataQueryAllOf {
this.date = date;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -407,7 +407,6 @@ public class DefaultValue {
this.stringNullable = JsonNullable.<String>of(stringNullable);
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -272,7 +272,6 @@ public class Pet {
this.status = status;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -142,7 +142,6 @@ public class Query {
this.outcomes = outcomes;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -95,7 +95,6 @@ public class Tag {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -156,7 +156,6 @@ public class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -76,7 +76,6 @@ public class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter {
this.values = values;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -81,7 +81,6 @@ public class Bird {
this.color = color;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -81,7 +81,6 @@ public class Category {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -112,6 +112,17 @@ public class DataQuery extends Query {
this.date = date;
}
@Override
public DataQuery id(Long id) {
this.setId(id);
return this;
}
@Override
public DataQuery outcomes(List<OutcomesEnum> outcomes) {
this.setOutcomes(outcomes);
return this;
}
@Override
public boolean equals(Object o) {

View File

@@ -108,7 +108,6 @@ public class DataQueryAllOf {
this.date = date;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -346,7 +346,6 @@ public class DefaultValue {
this.stringNullable = stringNullable;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -254,7 +254,6 @@ public class Pet {
this.status = status;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -140,7 +140,6 @@ public class Query {
this.outcomes = outcomes;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -81,7 +81,6 @@ public class Tag {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -133,7 +133,6 @@ public class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -65,7 +65,6 @@ public class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter {
this.values = values;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -113,7 +113,6 @@ public class AdditionalPropertiesClass {
this.mapOfMapProperty = mapOfMapProperty;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -96,7 +96,6 @@ public class AllOfWithSingleRef {
this.singleRefType = singleRefType;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -108,7 +108,6 @@ public class Animal {
this.color = color;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -76,7 +76,6 @@ public class ArrayOfArrayOfNumberOnly {
this.arrayArrayNumber = arrayArrayNumber;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -76,7 +76,6 @@ public class ArrayOfNumberOnly {
this.arrayNumber = arrayNumber;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -152,7 +152,6 @@ public class ArrayTest {
this.arrayArrayOfModel = arrayArrayOfModel;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -215,7 +215,6 @@ public class Capitalization {
this.ATT_NAME = ATT_NAME;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -76,6 +76,17 @@ public class Cat extends Animal {
this.declawed = declawed;
}
@Override
public Cat className(String className) {
this.setClassName(className);
return this;
}
@Override
public Cat color(String color) {
this.setColor(color);
return this;
}
@Override
public boolean equals(Object o) {

View File

@@ -66,7 +66,6 @@ public class CatAllOf {
this.declawed = declawed;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -95,7 +95,6 @@ public class Category {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -65,7 +65,6 @@ public class ClassModel {
this.propertyClass = propertyClass;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -65,7 +65,6 @@ public class Client {
this.client = client;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -67,7 +67,6 @@ public class DeprecatedObject {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -76,6 +76,17 @@ public class Dog extends Animal {
this.breed = breed;
}
@Override
public Dog className(String className) {
this.setClassName(className);
return this;
}
@Override
public Dog color(String color) {
this.setColor(color);
return this;
}
@Override
public boolean equals(Object o) {

View File

@@ -66,7 +66,6 @@ public class DogAllOf {
this.breed = breed;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -175,7 +175,6 @@ public class EnumArrays {
this.arrayEnum = arrayEnum;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -436,7 +436,6 @@ public class EnumTest {
this.outerEnumIntegerDefaultValue = outerEnumIntegerDefaultValue;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -106,7 +106,6 @@ public class FileSchemaTestClass {
this.files = files;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -65,7 +65,6 @@ public class Foo {
this.bar = bar;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -67,7 +67,6 @@ public class FooGetDefaultResponse {
this.string = string;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -531,7 +531,6 @@ public class FormatTest {
this.patternWithDigitsAndDelimiter = patternWithDigitsAndDelimiter;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -84,7 +84,6 @@ public class HasOnlyReadOnly {
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -77,7 +77,6 @@ public class HealthCheckResult {
this.nullableMessage = JsonNullable.<String>of(nullableMessage);
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -224,7 +224,6 @@ public class MapTest {
this.indirectMap = indirectMap;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -138,7 +138,6 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
this.map = map;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -96,7 +96,6 @@ public class Model200Response {
this.propertyClass = propertyClass;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -126,7 +126,6 @@ public class ModelApiResponse {
this.message = message;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -66,7 +66,6 @@ public class ModelFile {
this.sourceURI = sourceURI;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -66,7 +66,6 @@ public class ModelList {
this._123list = _123list;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -66,7 +66,6 @@ public class ModelReturn {
this._return = _return;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -143,7 +143,6 @@ public class Name {
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -551,7 +551,6 @@ public class NullableClass extends HashMap<String, Object> {
this.objectItemsNullable = objectItemsNullable;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -66,7 +66,6 @@ public class NumberOnly {
this.justNumber = justNumber;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -173,7 +173,6 @@ public class ObjectWithDeprecatedFields {
this.bars = bars;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -253,7 +253,6 @@ public class Order {
this.complete = complete;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -126,7 +126,6 @@ public class OuterComposite {
this.myBoolean = myBoolean;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -66,7 +66,6 @@ public class OuterObjectWithEnumProperty {
this.value = value;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -276,7 +276,6 @@ public class Pet {
this.status = status;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -92,7 +92,6 @@ public class ReadOnlyFirst {
this.baz = baz;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -66,7 +66,6 @@ public class SpecialModelName {
this.$specialPropertyName = $specialPropertyName;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -95,7 +95,6 @@ public class Tag {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -275,7 +275,6 @@ public class User {
this.userStatus = userStatus;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -66,7 +66,6 @@ public class AdditionalPropertiesAnyType extends HashMap<String, Object> {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -67,7 +67,6 @@ public class AdditionalPropertiesArray extends HashMap<String, List> {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -66,7 +66,6 @@ public class AdditionalPropertiesBoolean extends HashMap<String, Boolean> {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -431,7 +431,6 @@ public class AdditionalPropertiesClass {
this.anytype3 = anytype3;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -66,7 +66,6 @@ public class AdditionalPropertiesInteger extends HashMap<String, Integer> {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -67,7 +67,6 @@ public class AdditionalPropertiesNumber extends HashMap<String, BigDecimal> {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -66,7 +66,6 @@ public class AdditionalPropertiesObject extends HashMap<String, Map> {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -66,7 +66,6 @@ public class AdditionalPropertiesString extends HashMap<String, String> {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -107,7 +107,6 @@ public class Animal {
this.color = color;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -74,7 +74,6 @@ public class ArrayOfArrayOfNumberOnly {
this.arrayArrayNumber = arrayArrayNumber;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -74,7 +74,6 @@ public class ArrayOfNumberOnly {
this.arrayNumber = arrayNumber;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -150,7 +150,6 @@ public class ArrayTest {
this.arrayArrayOfModel = arrayArrayOfModel;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -113,6 +113,17 @@ public class BigCat extends Cat {
this.kind = kind;
}
@Override
public BigCat className(String className) {
this.setClassName(className);
return this;
}
@Override
public BigCat color(String color) {
this.setColor(color);
return this;
}
@Override
public boolean equals(Object o) {

View File

@@ -103,7 +103,6 @@ public class BigCatAllOf {
this.kind = kind;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -213,7 +213,6 @@ public class Capitalization {
this.ATT_NAME = ATT_NAME;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -77,6 +77,17 @@ public class Cat extends Animal {
this.declawed = declawed;
}
@Override
public Cat className(String className) {
this.setClassName(className);
return this;
}
@Override
public Cat color(String color) {
this.setColor(color);
return this;
}
@Override
public boolean equals(Object o) {

View File

@@ -64,7 +64,6 @@ public class CatAllOf {
this.declawed = declawed;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -93,7 +93,6 @@ public class Category {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -63,7 +63,6 @@ public class ClassModel {
this.propertyClass = propertyClass;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -63,7 +63,6 @@ public class Client {
this.client = client;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -74,6 +74,17 @@ public class Dog extends Animal {
this.breed = breed;
}
@Override
public Dog className(String className) {
this.setClassName(className);
return this;
}
@Override
public Dog color(String color) {
this.setColor(color);
return this;
}
@Override
public boolean equals(Object o) {

View File

@@ -64,7 +64,6 @@ public class DogAllOf {
this.breed = breed;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -173,7 +173,6 @@ public class EnumArrays {
this.arrayEnum = arrayEnum;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -329,7 +329,6 @@ public class EnumTest {
this.outerEnum = outerEnum;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -63,7 +63,6 @@ public class File {
this.sourceURI = sourceURI;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -104,7 +104,6 @@ public class FileSchemaTestClass {
this.files = files;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -469,7 +469,6 @@ public class FormatTest {
this.bigDecimal = bigDecimal;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -82,7 +82,6 @@ public class HasOnlyReadOnly {
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -222,7 +222,6 @@ public class MapTest {
this.indirectMap = indirectMap;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -136,7 +136,6 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
this.map = map;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -94,7 +94,6 @@ public class Model200Response {
this.propertyClass = propertyClass;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -124,7 +124,6 @@ public class ModelApiResponse {
this.message = message;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -64,7 +64,6 @@ public class ModelList {
this._123list = _123list;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -64,7 +64,6 @@ public class ModelReturn {
this._return = _return;
}
@Override
public boolean equals(Object o) {
if (this == o) {

Some files were not shown because too many files have changed in this diff Show More