[Java] fix nullable arrays when JsonNullable is used (#10012)

This commit is contained in:
Oleh Kurpiak
2021-07-27 08:57:07 +03:00
committed by GitHub
parent ddd23ab197
commit aa4018d09b
56 changed files with 2965 additions and 70 deletions

View File

@@ -27,6 +27,7 @@ import io.swagger.annotations.ApiModelProperty;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
@@ -336,7 +337,7 @@ public class AdditionalPropertiesClass {
AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o;
return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) &&
Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) &&
Objects.equals(this.anytype1, additionalPropertiesClass.anytype1) &&
equalsNullable(this.anytype1, additionalPropertiesClass.anytype1) &&
Objects.equals(this.mapWithUndeclaredPropertiesAnytype1, additionalPropertiesClass.mapWithUndeclaredPropertiesAnytype1) &&
Objects.equals(this.mapWithUndeclaredPropertiesAnytype2, additionalPropertiesClass.mapWithUndeclaredPropertiesAnytype2) &&
Objects.equals(this.mapWithUndeclaredPropertiesAnytype3, additionalPropertiesClass.mapWithUndeclaredPropertiesAnytype3) &&
@@ -344,9 +345,22 @@ public class AdditionalPropertiesClass {
Objects.equals(this.mapWithUndeclaredPropertiesString, additionalPropertiesClass.mapWithUndeclaredPropertiesString);
}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && a.get().getClass().isArray() ? Arrays.equals((T[])a.get(), (T[])b.get()) : Objects.equals(a.get(), b.get()));
}
@Override
public int hashCode() {
return Objects.hash(mapProperty, mapOfMapProperty, anytype1, mapWithUndeclaredPropertiesAnytype1, mapWithUndeclaredPropertiesAnytype2, mapWithUndeclaredPropertiesAnytype3, emptyMap, mapWithUndeclaredPropertiesString);
return Objects.hash(mapProperty, mapOfMapProperty, hashCodeNullable(anytype1), mapWithUndeclaredPropertiesAnytype1, mapWithUndeclaredPropertiesAnytype2, mapWithUndeclaredPropertiesAnytype3, emptyMap, mapWithUndeclaredPropertiesString);
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent()
? (a.get().getClass().isArray() ? Arrays.hashCode((T[])a.get()) : Objects.hashCode(a.get()))
: 31;
}
@Override

View File

@@ -34,6 +34,7 @@ import org.openapitools.client.model.Fruit;
import org.openapitools.client.model.NullableShape;
import org.openapitools.client.model.Shape;
import org.openapitools.client.model.ShapeOrNull;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
@@ -236,14 +237,27 @@ public class Drawing {
Drawing drawing = (Drawing) o;
return Objects.equals(this.mainShape, drawing.mainShape) &&
Objects.equals(this.shapeOrNull, drawing.shapeOrNull) &&
Objects.equals(this.nullableShape, drawing.nullableShape) &&
equalsNullable(this.nullableShape, drawing.nullableShape) &&
Objects.equals(this.shapes, drawing.shapes)&&
Objects.equals(this.additionalProperties, drawing.additionalProperties);
}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && a.get().getClass().isArray() ? Arrays.equals((T[])a.get(), (T[])b.get()) : Objects.equals(a.get(), b.get()));
}
@Override
public int hashCode() {
return Objects.hash(mainShape, shapeOrNull, nullableShape, shapes, additionalProperties);
return Objects.hash(mainShape, shapeOrNull, hashCodeNullable(nullableShape), shapes, additionalProperties);
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent()
? (a.get().getClass().isArray() ? Arrays.hashCode((T[])a.get()) : Objects.hashCode(a.get()))
: 31;
}
@Override

View File

@@ -28,6 +28,7 @@ import org.openapitools.client.model.OuterEnum;
import org.openapitools.client.model.OuterEnumDefaultValue;
import org.openapitools.client.model.OuterEnumInteger;
import org.openapitools.client.model.OuterEnumIntegerDefaultValue;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
@@ -517,15 +518,28 @@ public class EnumTest {
Objects.equals(this.enumInteger, enumTest.enumInteger) &&
Objects.equals(this.enumIntegerOnly, enumTest.enumIntegerOnly) &&
Objects.equals(this.enumNumber, enumTest.enumNumber) &&
Objects.equals(this.outerEnum, enumTest.outerEnum) &&
equalsNullable(this.outerEnum, enumTest.outerEnum) &&
Objects.equals(this.outerEnumInteger, enumTest.outerEnumInteger) &&
Objects.equals(this.outerEnumDefaultValue, enumTest.outerEnumDefaultValue) &&
Objects.equals(this.outerEnumIntegerDefaultValue, enumTest.outerEnumIntegerDefaultValue);
}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && a.get().getClass().isArray() ? Arrays.equals((T[])a.get(), (T[])b.get()) : Objects.equals(a.get(), b.get()));
}
@Override
public int hashCode() {
return Objects.hash(enumString, enumStringRequired, enumInteger, enumIntegerOnly, enumNumber, outerEnum, outerEnumInteger, outerEnumDefaultValue, outerEnumIntegerDefaultValue);
return Objects.hash(enumString, enumStringRequired, enumInteger, enumIntegerOnly, enumNumber, hashCodeNullable(outerEnum), outerEnumInteger, outerEnumDefaultValue, outerEnumIntegerDefaultValue);
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent()
? (a.get().getClass().isArray() ? Arrays.hashCode((T[])a.get()) : Objects.hashCode(a.get()))
: 31;
}
@Override

View File

@@ -24,6 +24,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
@@ -90,12 +91,25 @@ public class HealthCheckResult {
return false;
}
HealthCheckResult healthCheckResult = (HealthCheckResult) o;
return Objects.equals(this.nullableMessage, healthCheckResult.nullableMessage);
return equalsNullable(this.nullableMessage, healthCheckResult.nullableMessage);
}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && a.get().getClass().isArray() ? Arrays.equals((T[])a.get(), (T[])b.get()) : Objects.equals(a.get(), b.get()));
}
@Override
public int hashCode() {
return Objects.hash(nullableMessage);
return Objects.hash(hashCodeNullable(nullableMessage));
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent()
? (a.get().getClass().isArray() ? Arrays.hashCode((T[])a.get()) : Objects.hashCode(a.get()))
: 31;
}
@Override

View File

@@ -35,6 +35,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
@@ -603,24 +604,37 @@ public class NullableClass {
return false;
}
NullableClass nullableClass = (NullableClass) o;
return Objects.equals(this.integerProp, nullableClass.integerProp) &&
Objects.equals(this.numberProp, nullableClass.numberProp) &&
Objects.equals(this.booleanProp, nullableClass.booleanProp) &&
Objects.equals(this.stringProp, nullableClass.stringProp) &&
Objects.equals(this.dateProp, nullableClass.dateProp) &&
Objects.equals(this.datetimeProp, nullableClass.datetimeProp) &&
Objects.equals(this.arrayNullableProp, nullableClass.arrayNullableProp) &&
Objects.equals(this.arrayAndItemsNullableProp, nullableClass.arrayAndItemsNullableProp) &&
return equalsNullable(this.integerProp, nullableClass.integerProp) &&
equalsNullable(this.numberProp, nullableClass.numberProp) &&
equalsNullable(this.booleanProp, nullableClass.booleanProp) &&
equalsNullable(this.stringProp, nullableClass.stringProp) &&
equalsNullable(this.dateProp, nullableClass.dateProp) &&
equalsNullable(this.datetimeProp, nullableClass.datetimeProp) &&
equalsNullable(this.arrayNullableProp, nullableClass.arrayNullableProp) &&
equalsNullable(this.arrayAndItemsNullableProp, nullableClass.arrayAndItemsNullableProp) &&
Objects.equals(this.arrayItemsNullable, nullableClass.arrayItemsNullable) &&
Objects.equals(this.objectNullableProp, nullableClass.objectNullableProp) &&
Objects.equals(this.objectAndItemsNullableProp, nullableClass.objectAndItemsNullableProp) &&
equalsNullable(this.objectNullableProp, nullableClass.objectNullableProp) &&
equalsNullable(this.objectAndItemsNullableProp, nullableClass.objectAndItemsNullableProp) &&
Objects.equals(this.objectItemsNullable, nullableClass.objectItemsNullable)&&
Objects.equals(this.additionalProperties, nullableClass.additionalProperties);
}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && a.get().getClass().isArray() ? Arrays.equals((T[])a.get(), (T[])b.get()) : Objects.equals(a.get(), b.get()));
}
@Override
public int hashCode() {
return Objects.hash(integerProp, numberProp, booleanProp, stringProp, dateProp, datetimeProp, arrayNullableProp, arrayAndItemsNullableProp, arrayItemsNullable, objectNullableProp, objectAndItemsNullableProp, objectItemsNullable, additionalProperties);
return Objects.hash(hashCodeNullable(integerProp), hashCodeNullable(numberProp), hashCodeNullable(booleanProp), hashCodeNullable(stringProp), hashCodeNullable(dateProp), hashCodeNullable(datetimeProp), hashCodeNullable(arrayNullableProp), hashCodeNullable(arrayAndItemsNullableProp), arrayItemsNullable, hashCodeNullable(objectNullableProp), hashCodeNullable(objectAndItemsNullableProp), objectItemsNullable, additionalProperties);
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent()
? (a.get().getClass().isArray() ? Arrays.hashCode((T[])a.get()) : Objects.hashCode(a.get()))
: 31;
}
@Override

View File

@@ -24,6 +24,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
@@ -444,14 +445,27 @@ public class User {
Objects.equals(this.phone, user.phone) &&
Objects.equals(this.userStatus, user.userStatus) &&
Objects.equals(this.objectWithNoDeclaredProps, user.objectWithNoDeclaredProps) &&
Objects.equals(this.objectWithNoDeclaredPropsNullable, user.objectWithNoDeclaredPropsNullable) &&
Objects.equals(this.anyTypeProp, user.anyTypeProp) &&
Objects.equals(this.anyTypePropNullable, user.anyTypePropNullable);
equalsNullable(this.objectWithNoDeclaredPropsNullable, user.objectWithNoDeclaredPropsNullable) &&
equalsNullable(this.anyTypeProp, user.anyTypeProp) &&
equalsNullable(this.anyTypePropNullable, user.anyTypePropNullable);
}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && a.get().getClass().isArray() ? Arrays.equals((T[])a.get(), (T[])b.get()) : Objects.equals(a.get(), b.get()));
}
@Override
public int hashCode() {
return Objects.hash(id, username, firstName, lastName, email, password, phone, userStatus, objectWithNoDeclaredProps, objectWithNoDeclaredPropsNullable, anyTypeProp, anyTypePropNullable);
return Objects.hash(id, username, firstName, lastName, email, password, phone, userStatus, objectWithNoDeclaredProps, hashCodeNullable(objectWithNoDeclaredPropsNullable), hashCodeNullable(anyTypeProp), hashCodeNullable(anyTypePropNullable));
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent()
? (a.get().getClass().isArray() ? Arrays.hashCode((T[])a.get()) : Objects.hashCode(a.get()))
: 31;
}
@Override