swagger-core
swagger-core copied to clipboard
Nested Properties in Schema with same root element annotation will result in one property
Hello,
I'm currently working with V2.2.2. I use javax for some Annotations
I have following schemas in my rest service:
@Content(mediaType = MediaType.APPLICATION_XML, schema = @Schema(implementation = ClassA.class)
@Content(mediaType = MediaType.APPLICATION_XML, schema = @Schema(implementation = ClassB.class)
and I have 2 more classes, ClassC and ClassD. They are not Schemas, but they are used inside the ClassA / ClassB like this:
public class ClassA {
private List<ClassC> classC = new ArrayList<>();
public class ClassB {
private List<ClassD> classD = new ArrayList<>();
Class C and Class D have the same @XMLRootElement(name = "SubClass")
@XmlRootElement(name = "SubClass")
@XmlAccessorType(XmlAccessType.FIELD)
public class ClassC {
@XmlRootElement(name = "SubClass")
@XmlAccessorType(XmlAccessType.FIELD)
public class ClassD {
The @XMLRootElement is supposed to be the same, because its about the same topic, with different content. The Classes have different names and are also contained in different packages
But now, only one of the SubClass turns into a schema (and the other one is probably overwritten):
"SubClass" : {
"type" : "object",
"properties" : {
"UUID" : {
"type" : "string"
},
"Name" : {
"type" : "string"
},
"Path" : {
"type" : "string"
},
"Module" : {
"type" : "string"
}
}
},
"ClassA" : {
"type" : "object",
"properties" : {
"Process" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/SubClass"
"ClassB" : {
"type" : "object",
"properties" : {
"Process" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/SubClass"
I tried using TypeNameResolver.std.setUseFqn(true); and hoped that the full name of the ClassC and ClassD would be used. But they stayed the same.
I also tried a ModelConverters.getInstance().addConverter(new CustomConverter(Json.mapper())); combined with a TypeNameResolver extension that mapps the name to the qualified name -> as seen here: https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-core/src/test/java/io/swagger/v3/core/converting/override/CustomResolverTest.java#L49
Am I missing something? do I need to Annotate something in ClassC / ClassD ? I really want to keep the names of the Classes for better usage.
I also tried to put a @Schema(title = "") for both Classes C and D (with different titles)
this does ONLY work if there is NO @XmlRootElement(name = "") in the Class
but, with an empty @XmlRootElement, it works?
why can't I use schema at the top of a class AND XmlRootElement? I see very weird behavior here
It seems that @XmlRootElement(name = "") and @Schema cannot co-exist
https://stackoverflow.com/questions/73552642/schema-and-xmlrootelement-cannot-co-exist