support nullable check for OAS 3.1 (#15698)

This commit is contained in:
karzang
2023-06-05 13:34:51 +02:00
committed by GitHub
parent d2446013d1
commit bc7bdca87f
35 changed files with 191 additions and 178 deletions

View File

@@ -1973,8 +1973,8 @@ components:
type: string
fruitReq:
additionalProperties: false
nullable: true
oneOf:
- type: "null"
- $ref: '#/components/schemas/appleReq'
- $ref: '#/components/schemas/bananaReq'
appleReq:
@@ -2023,8 +2023,8 @@ components:
in OAS schema >= 3.1.
discriminator:
propertyName: shapeType
nullable: true
oneOf:
- type: "null"
- $ref: '#/components/schemas/Triangle'
- $ref: '#/components/schemas/Quadrilateral'
NullableShape:

View File

@@ -55,7 +55,7 @@ public class Drawing {
private Shape mainShape;
public static final String JSON_PROPERTY_SHAPE_OR_NULL = "shapeOrNull";
private ShapeOrNull shapeOrNull;
private JsonNullable<ShapeOrNull> shapeOrNull = JsonNullable.<ShapeOrNull>undefined();
public static final String JSON_PROPERTY_NULLABLE_SHAPE = "nullableShape";
private JsonNullable<NullableShape> nullableShape = JsonNullable.<NullableShape>undefined();
@@ -92,7 +92,7 @@ public class Drawing {
public Drawing shapeOrNull(ShapeOrNull shapeOrNull) {
this.shapeOrNull = shapeOrNull;
this.shapeOrNull = JsonNullable.<ShapeOrNull>of(shapeOrNull);
return this;
}
@@ -101,20 +101,28 @@ public class Drawing {
* @return shapeOrNull
**/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_SHAPE_OR_NULL)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
@JsonIgnore
public ShapeOrNull getShapeOrNull() {
return shapeOrNull;
return shapeOrNull.orElse(null);
}
@JsonProperty(JSON_PROPERTY_SHAPE_OR_NULL)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setShapeOrNull(ShapeOrNull shapeOrNull) {
public JsonNullable<ShapeOrNull> getShapeOrNull_JsonNullable() {
return shapeOrNull;
}
@JsonProperty(JSON_PROPERTY_SHAPE_OR_NULL)
public void setShapeOrNull_JsonNullable(JsonNullable<ShapeOrNull> shapeOrNull) {
this.shapeOrNull = shapeOrNull;
}
public void setShapeOrNull(ShapeOrNull shapeOrNull) {
this.shapeOrNull = JsonNullable.<ShapeOrNull>of(shapeOrNull);
}
public Drawing nullableShape(NullableShape nullableShape) {
this.nullableShape = JsonNullable.<NullableShape>of(nullableShape);
@@ -232,7 +240,7 @@ public class Drawing {
}
Drawing drawing = (Drawing) o;
return Objects.equals(this.mainShape, drawing.mainShape) &&
Objects.equals(this.shapeOrNull, drawing.shapeOrNull) &&
equalsNullable(this.shapeOrNull, drawing.shapeOrNull) &&
equalsNullable(this.nullableShape, drawing.nullableShape) &&
Objects.equals(this.shapes, drawing.shapes)&&
Objects.equals(this.additionalProperties, drawing.additionalProperties);
@@ -244,7 +252,7 @@ public class Drawing {
@Override
public int hashCode() {
return Objects.hash(mainShape, shapeOrNull, hashCodeNullable(nullableShape), shapes, additionalProperties);
return Objects.hash(mainShape, hashCodeNullable(shapeOrNull), hashCodeNullable(nullableShape), shapes, additionalProperties);
}
private static <T> int hashCodeNullable(JsonNullable<T> a) {