mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-18 21:47:04 +00:00
[JAVA] fix several anyOf/oneOf problems (#19817)
* erasure duplicates * sanitize beanValidation * oneOf maps * anyOf * update samples
This commit is contained in:
@@ -87,7 +87,7 @@ public class GmFruit extends AbstractOpenApiSchema {
|
||||
JsonNode tree = jp.readValueAsTree();
|
||||
|
||||
Object deserialized = null;
|
||||
// deserialize Apple
|
||||
// deserialize Apple (nullable)
|
||||
try {
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs(Apple.class);
|
||||
GmFruit ret = new GmFruit();
|
||||
@@ -129,7 +129,7 @@ public class GmFruit extends AbstractOpenApiSchema {
|
||||
}
|
||||
|
||||
public GmFruit(Apple o) {
|
||||
super("anyOf", Boolean.FALSE);
|
||||
super("anyOf", Boolean.TRUE);
|
||||
setActualInstance(o);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,17 +104,6 @@ public class MammalAnyof extends AbstractOpenApiSchema {
|
||||
ret.setActualInstance(deserialized);
|
||||
return ret;
|
||||
}
|
||||
// deserialize Pig
|
||||
try {
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs(Pig.class);
|
||||
MammalAnyof ret = new MammalAnyof();
|
||||
ret.setActualInstance(deserialized);
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
// deserialization failed, continue, log to help debugging
|
||||
log.log(Level.FINER, "Input data does not match 'MammalAnyof'", e);
|
||||
}
|
||||
|
||||
// deserialize Whale
|
||||
try {
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs(Whale.class);
|
||||
@@ -137,6 +126,17 @@ public class MammalAnyof extends AbstractOpenApiSchema {
|
||||
log.log(Level.FINER, "Input data does not match 'MammalAnyof'", e);
|
||||
}
|
||||
|
||||
// deserialize Pig
|
||||
try {
|
||||
deserialized = tree.traverse(jp.getCodec()).readValueAs(Pig.class);
|
||||
MammalAnyof ret = new MammalAnyof();
|
||||
ret.setActualInstance(deserialized);
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
// deserialization failed, continue, log to help debugging
|
||||
log.log(Level.FINER, "Input data does not match 'MammalAnyof'", e);
|
||||
}
|
||||
|
||||
throw new IOException(String.format("Failed deserialization for MammalAnyof: no match found"));
|
||||
}
|
||||
|
||||
@@ -205,11 +205,6 @@ public class MammalAnyof extends AbstractOpenApiSchema {
|
||||
public int hashCode() {
|
||||
return Objects.hash(getActualInstance(), isNullable(), getSchemaType(), additionalProperties);
|
||||
}
|
||||
public MammalAnyof(Pig o) {
|
||||
super("anyOf", Boolean.FALSE);
|
||||
setActualInstance(o);
|
||||
}
|
||||
|
||||
public MammalAnyof(Whale o) {
|
||||
super("anyOf", Boolean.FALSE);
|
||||
setActualInstance(o);
|
||||
@@ -220,6 +215,11 @@ public class MammalAnyof extends AbstractOpenApiSchema {
|
||||
setActualInstance(o);
|
||||
}
|
||||
|
||||
public MammalAnyof(Pig o) {
|
||||
super("anyOf", Boolean.FALSE);
|
||||
setActualInstance(o);
|
||||
}
|
||||
|
||||
static {
|
||||
schemas.put("Pig", new GenericType<Pig>() {
|
||||
});
|
||||
@@ -252,11 +252,6 @@ public class MammalAnyof extends AbstractOpenApiSchema {
|
||||
*/
|
||||
@Override
|
||||
public void setActualInstance(Object instance) {
|
||||
if (JSON.isInstanceOf(Pig.class, instance, new HashSet<>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(Whale.class, instance, new HashSet<>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
@@ -267,6 +262,11 @@ public class MammalAnyof extends AbstractOpenApiSchema {
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.isInstanceOf(Pig.class, instance, new HashSet<>())) {
|
||||
super.setActualInstance(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new RuntimeException("Invalid instance type. Must be Pig, Whale, Zebra");
|
||||
}
|
||||
|
||||
@@ -281,17 +281,6 @@ public class MammalAnyof extends AbstractOpenApiSchema {
|
||||
return super.getActualInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual instance of `Pig`. If the actual instance is not `Pig`,
|
||||
* the ClassCastException will be thrown.
|
||||
*
|
||||
* @return The actual instance of `Pig`
|
||||
* @throws ClassCastException if the instance is not `Pig`
|
||||
*/
|
||||
public Pig getPig() throws ClassCastException {
|
||||
return (Pig)super.getActualInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual instance of `Whale`. If the actual instance is not `Whale`,
|
||||
* the ClassCastException will be thrown.
|
||||
@@ -314,5 +303,16 @@ public class MammalAnyof extends AbstractOpenApiSchema {
|
||||
return (Zebra)super.getActualInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual instance of `Pig`. If the actual instance is not `Pig`,
|
||||
* the ClassCastException will be thrown.
|
||||
*
|
||||
* @return The actual instance of `Pig`
|
||||
* @throws ClassCastException if the instance is not `Pig`
|
||||
*/
|
||||
public Pig getPig() throws ClassCastException {
|
||||
return (Pig)super.getActualInstance();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user