You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Johnathan Ingram (Jira)" <ji...@apache.org> on 2022/05/03 07:21:00 UTC
[jira] [Created] (CAMEL-18040) OpenApi Specification Generator Does not generate oneOf when annotation @Schema(oneOf = {X.class, Y.class}) is specified on a class
Johnathan Ingram created CAMEL-18040:
----------------------------------------
Summary: OpenApi Specification Generator Does not generate oneOf when annotation @Schema(oneOf = {X.class, Y.class}) is specified on a class
Key: CAMEL-18040
URL: https://issues.apache.org/jira/browse/CAMEL-18040
Project: Camel
Issue Type: Improvement
Components: camel-rest-openapi
Affects Versions: 3.14.2
Reporter: Johnathan Ingram
Fix For: 3.14.3
Given the following classes
{code:java}
@Schema(oneOf = {FormA.class, FormB.class})
public abstract class Form {
} {code}
{code:java}
public class FormA extends Form {
String code;
String a;
int b;
public String getCode() { return this.code; }
public void setCode(String code) { this.code = code; }
public String getA() { return this.a; }
public void setA(String a) { this.a = a; }
public int getB() { return this.b; }
public void setB(int b) { this.b = b; }
} {code}
{code:java}
public class FormB extends Form {
String code;
int x;
String y;
public String getCode() { return this.code; }
public void setCode(String code) { this.code = code; }
public int getX() { return this.x; }
public void setX(int x) { this.x = x; }
public String getY() { return this.y; }
public void setY(String y) { this.y = y; }
} {code}
{code:java}
public class Wrapper {
@JsonProperty("system") String system;
@JsonProperty("form") Form form;
public String getSystem() { return this.system; }
public void setSystem(String system) { this.system = system; }
public Form getForm() { return this.form; }
@JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "system") @JsonSubTypes({ @Type(value = FormA.class, name = "Form A"), @Type(value = FormB.class, name = "Form B") })
public void setForm(Form form) { this.form = form; }
} {code}
And finally the request of a Camel Rest Endpoint
{code:java}
rest("/prototype/")
.id("rest.proto.oneof")
.post("oneof")
.bindingMode(RestBindingMode.json) .description("Prototype OneOf")
.id("proto.oneof")
.consumes("application/json")
.produces(MediaType.APPLICATION_JSON )
.type(Wrapper.class)
.responseMessage()
.code(200).message("Oneof working")
.endResponseMessage()
....{code}
The OpenAPI specification is correct except for the Form class in the schema components section
{code:java}
"Form" : {
"type" : "object"
},
"FormA" : {
"type" : "object",
"properties" : {
"code" : {
"type" : "string"
},
"a" : {
"type" : "string"
},
"b" : {
"format" : "int32",
"type" : "integer"
}
}
},
"FormB" : {
"type" : "object",
"properties" : {
"code" : {
"type" : "string"
},
"x" : {
"format" : "int32",
"type" : "integer"
},
"y" : {
"type" : "string"
}
}
},
"Wrapper" : {
"type" : "object",
"properties" : {
"system" : {
"type" : "string"
},
"form" : {
"$ref" : "#/components/schemas/Form"
}
}
}
}
{code}
NOTE: Form should be
{code:java}
"Form" : {
"oneOf" : [
....
]
}, {code}
--
This message was sent by Atlassian Jira
(v8.20.7#820007)