Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java][jersey2] Add helper methods for oneOf Java classes #7115

Merged
merged 2 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im

/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas.
* the instance parameter is valid against the oneOf child schemas:
* {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}
*
* It could be an instance of the 'oneOf' schemas.
* The oneOf child schemas may themselves be a composed schema (allOf, anyOf, oneOf).
Expand All @@ -207,6 +208,28 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im
throw new RuntimeException("Invalid instance type. Must be {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}");
}

/**
* Get the actual instance, which can be the following:
* {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}
*
* @return The actual instance ({{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}})
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}

{{#oneOf}}
/**
* 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();
}

{{/oneOf}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ public Map<String, GenericType> getSchemas() {

/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas.
* the instance parameter is valid against the oneOf child schemas:
* Apple, Banana
*
* It could be an instance of the 'oneOf' schemas.
* The oneOf child schemas may themselves be a composed schema (allOf, anyOf, oneOf).
Expand All @@ -215,7 +216,38 @@ public void setActualInstance(Object instance) {
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();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public Map<String, GenericType> getSchemas() {

/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas.
* the instance parameter is valid against the oneOf child schemas:
* AppleReq, BananaReq
*
* It could be an instance of the 'oneOf' schemas.
* The oneOf child schemas may themselves be a composed schema (allOf, anyOf, oneOf).
Expand All @@ -222,7 +223,38 @@ public void setActualInstance(Object instance) {
throw new RuntimeException("Invalid instance type. Must be AppleReq, BananaReq");
}

/**
* Get the actual instance, which can be the following:
* AppleReq, BananaReq
*
* @return The actual instance (AppleReq, BananaReq)
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}

/**
* Get the actual instance of `AppleReq`. If the actual instanct is not `AppleReq`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `AppleReq`
* @throws ClassCastException if the instance is not `AppleReq`
*/
public AppleReq getAppleReq() throws ClassCastException {
return (AppleReq)super.getActualInstance();
}

/**
* Get the actual instance of `BananaReq`. If the actual instanct is not `BananaReq`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `BananaReq`
* @throws ClassCastException if the instance is not `BananaReq`
*/
public BananaReq getBananaReq() throws ClassCastException {
return (BananaReq)super.getActualInstance();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ public Map<String, GenericType> getSchemas() {

/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas.
* the instance parameter is valid against the oneOf child schemas:
* Pig, Whale, Zebra
*
* It could be an instance of the 'oneOf' schemas.
* The oneOf child schemas may themselves be a composed schema (allOf, anyOf, oneOf).
Expand All @@ -335,7 +336,49 @@ public void setActualInstance(Object instance) {
throw new RuntimeException("Invalid instance type. Must be Pig, Whale, Zebra");
}

/**
* Get the actual instance, which can be the following:
* Pig, Whale, Zebra
*
* @return The actual instance (Pig, Whale, Zebra)
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}

/**
* Get the actual instance of `Pig`. If the actual instanct 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 instanct is not `Whale`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Whale`
* @throws ClassCastException if the instance is not `Whale`
*/
public Whale getWhale() throws ClassCastException {
return (Whale)super.getActualInstance();
}

/**
* Get the actual instance of `Zebra`. If the actual instanct is not `Zebra`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Zebra`
* @throws ClassCastException if the instance is not `Zebra`
*/
public Zebra getZebra() throws ClassCastException {
return (Zebra)super.getActualInstance();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ public Map<String, GenericType> getSchemas() {

/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas.
* the instance parameter is valid against the oneOf child schemas:
* Quadrilateral, Triangle
*
* It could be an instance of the 'oneOf' schemas.
* The oneOf child schemas may themselves be a composed schema (allOf, anyOf, oneOf).
Expand All @@ -298,7 +299,38 @@ public void setActualInstance(Object instance) {
throw new RuntimeException("Invalid instance type. Must be Quadrilateral, Triangle");
}

/**
* Get the actual instance, which can be the following:
* Quadrilateral, Triangle
*
* @return The actual instance (Quadrilateral, Triangle)
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}

/**
* Get the actual instance of `Quadrilateral`. If the actual instanct is not `Quadrilateral`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Quadrilateral`
* @throws ClassCastException if the instance is not `Quadrilateral`
*/
public Quadrilateral getQuadrilateral() throws ClassCastException {
return (Quadrilateral)super.getActualInstance();
}

/**
* Get the actual instance of `Triangle`. If the actual instanct is not `Triangle`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Triangle`
* @throws ClassCastException if the instance is not `Triangle`
*/
public Triangle getTriangle() throws ClassCastException {
return (Triangle)super.getActualInstance();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ public Map<String, GenericType> getSchemas() {

/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas.
* the instance parameter is valid against the oneOf child schemas:
* BasquePig, DanishPig
*
* It could be an instance of the 'oneOf' schemas.
* The oneOf child schemas may themselves be a composed schema (allOf, anyOf, oneOf).
Expand All @@ -291,7 +292,38 @@ public void setActualInstance(Object instance) {
throw new RuntimeException("Invalid instance type. Must be BasquePig, DanishPig");
}

/**
* Get the actual instance, which can be the following:
* BasquePig, DanishPig
*
* @return The actual instance (BasquePig, DanishPig)
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}

/**
* Get the actual instance of `BasquePig`. If the actual instanct is not `BasquePig`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `BasquePig`
* @throws ClassCastException if the instance is not `BasquePig`
*/
public BasquePig getBasquePig() throws ClassCastException {
return (BasquePig)super.getActualInstance();
}

/**
* Get the actual instance of `DanishPig`. If the actual instanct is not `DanishPig`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `DanishPig`
* @throws ClassCastException if the instance is not `DanishPig`
*/
public DanishPig getDanishPig() throws ClassCastException {
return (DanishPig)super.getActualInstance();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ public Map<String, GenericType> getSchemas() {

/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas.
* the instance parameter is valid against the oneOf child schemas:
* ComplexQuadrilateral, SimpleQuadrilateral
*
* It could be an instance of the 'oneOf' schemas.
* The oneOf child schemas may themselves be a composed schema (allOf, anyOf, oneOf).
Expand All @@ -291,7 +292,38 @@ public void setActualInstance(Object instance) {
throw new RuntimeException("Invalid instance type. Must be ComplexQuadrilateral, SimpleQuadrilateral");
}

/**
* Get the actual instance, which can be the following:
* ComplexQuadrilateral, SimpleQuadrilateral
*
* @return The actual instance (ComplexQuadrilateral, SimpleQuadrilateral)
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}

/**
* Get the actual instance of `ComplexQuadrilateral`. If the actual instanct is not `ComplexQuadrilateral`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `ComplexQuadrilateral`
* @throws ClassCastException if the instance is not `ComplexQuadrilateral`
*/
public ComplexQuadrilateral getComplexQuadrilateral() throws ClassCastException {
return (ComplexQuadrilateral)super.getActualInstance();
}

/**
* Get the actual instance of `SimpleQuadrilateral`. If the actual instanct is not `SimpleQuadrilateral`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `SimpleQuadrilateral`
* @throws ClassCastException if the instance is not `SimpleQuadrilateral`
*/
public SimpleQuadrilateral getSimpleQuadrilateral() throws ClassCastException {
return (SimpleQuadrilateral)super.getActualInstance();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ public Map<String, GenericType> getSchemas() {

/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas.
* the instance parameter is valid against the oneOf child schemas:
* Quadrilateral, Triangle
*
* It could be an instance of the 'oneOf' schemas.
* The oneOf child schemas may themselves be a composed schema (allOf, anyOf, oneOf).
Expand All @@ -291,7 +292,38 @@ public void setActualInstance(Object instance) {
throw new RuntimeException("Invalid instance type. Must be Quadrilateral, Triangle");
}

/**
* Get the actual instance, which can be the following:
* Quadrilateral, Triangle
*
* @return The actual instance (Quadrilateral, Triangle)
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}

/**
* Get the actual instance of `Quadrilateral`. If the actual instanct is not `Quadrilateral`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Quadrilateral`
* @throws ClassCastException if the instance is not `Quadrilateral`
*/
public Quadrilateral getQuadrilateral() throws ClassCastException {
return (Quadrilateral)super.getActualInstance();
}

/**
* Get the actual instance of `Triangle`. If the actual instanct is not `Triangle`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Triangle`
* @throws ClassCastException if the instance is not `Triangle`
*/
public Triangle getTriangle() throws ClassCastException {
return (Triangle)super.getActualInstance();
}

}

Loading