forked from loafle/openapi-generator-original
add helper methods to anyOf in java models (#7130)
This commit is contained in:
parent
201ac77d0c
commit
4a7c4ac81d
@ -148,6 +148,14 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
return {{classname}}.schemas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the instance that matches the anyOf child schema, check
|
||||
* the instance parameter is valid against the anyOf child schemas:
|
||||
* {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}
|
||||
*
|
||||
* It could be an instance of the 'anyOf' schemas.
|
||||
* The anyOf child schemas may themselves be a composed schema (allOf, anyOf, anyOf).
|
||||
*/
|
||||
@Override
|
||||
public void setActualInstance(Object instance) {
|
||||
{{#isNullable}}
|
||||
@ -166,4 +174,29 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
|
||||
{{/anyOf}}
|
||||
throw new RuntimeException("Invalid instance type. Must be {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual instance, which can be the following:
|
||||
* {{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}}
|
||||
*
|
||||
* @return The actual instance ({{#anyOf}}{{{.}}}{{^-last}}, {{/-last}}{{/anyOf}})
|
||||
*/
|
||||
@Override
|
||||
public Object getActualInstance() {
|
||||
return super.getActualInstance();
|
||||
}
|
||||
|
||||
{{#anyOf}}
|
||||
/**
|
||||
* Get the actual instance of `{{{.}}}`. If the actual instanct is not `{{{.}}}`,
|
||||
* the ClassCastException will be thrown.
|
||||
*
|
||||
* @return The actual instance of `{{{.}}}`
|
||||
* @throws ClassCastException if the instance is not `{{{.}}}`
|
||||
*/
|
||||
public {{{.}}} get{{{.}}}() throws ClassCastException {
|
||||
return ({{{.}}})super.getActualInstance();
|
||||
}
|
||||
|
||||
{{/anyOf}}
|
||||
}
|
||||
|
@ -153,6 +153,14 @@ public class GmFruit extends AbstractOpenApiSchema {
|
||||
return GmFruit.schemas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the instance that matches the anyOf child schema, check
|
||||
* the instance parameter is valid against the anyOf child schemas:
|
||||
* Apple, Banana
|
||||
*
|
||||
* It could be an instance of the 'anyOf' schemas.
|
||||
* The anyOf child schemas may themselves be a composed schema (allOf, anyOf, anyOf).
|
||||
*/
|
||||
@Override
|
||||
public void setActualInstance(Object instance) {
|
||||
if (JSON.isInstanceOf(Apple.class, instance, new HashSet<Class<?>>())) {
|
||||
@ -167,5 +175,39 @@ public class GmFruit extends AbstractOpenApiSchema {
|
||||
|
||||
throw new RuntimeException("Invalid instance type. Must be Apple, Banana");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual instance, which can be the following:
|
||||
* Apple, Banana
|
||||
*
|
||||
* @return The actual instance (Apple, Banana)
|
||||
*/
|
||||
@Override
|
||||
public Object getActualInstance() {
|
||||
return super.getActualInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual instance of `Apple`. If the actual instanct is not `Apple`,
|
||||
* the ClassCastException will be thrown.
|
||||
*
|
||||
* @return The actual instance of `Apple`
|
||||
* @throws ClassCastException if the instance is not `Apple`
|
||||
*/
|
||||
public Apple getApple() throws ClassCastException {
|
||||
return (Apple)super.getActualInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual instance of `Banana`. If the actual instanct is not `Banana`,
|
||||
* the ClassCastException will be thrown.
|
||||
*
|
||||
* @return The actual instance of `Banana`
|
||||
* @throws ClassCastException if the instance is not `Banana`
|
||||
*/
|
||||
public Banana getBanana() throws ClassCastException {
|
||||
return (Banana)super.getActualInstance();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user