-
-
Notifications
You must be signed in to change notification settings - Fork 548
Description
Describe the bug
It's hard to explain in own words what is wrong. Better to look below on sample code and all will be clear to you immediately.
Long story short: Generated openApi component is missing references in properties to child components if @JsonIgnoreProperties is used.
It looks like @JsonIgnoreProperties is taken into account in generation of components. And it should not because those components can be used in multiple paths.
To Reproduce
spring-boot version: 2.6.3
spring-doc version:1.6.2
used modules:
springdoc-openapi-webmvc-core
springdoc-openapi-common
Sample code
It is important to mention that all of the classes below have defined endpoint with multiple operations in which they are returning corresponding objects.
public class Moo implements Serializable {
private Foo foo;
@JsonIgnoreProperties(value = { "foo" }, allowSetters = true)
private Goo goo;
// getters, setters
}
public class Foo implements Serializable {
}
public class Goo implements Serializable {
private Foo foo;
// getters, setters
}
Actual part of generated model:
"components": {
"schemas": {
"Moo": {
"type": "object",
"properties": {
"foo": {
"$ref": "#/components/schemas/Foo"
},
"goo": {
"$ref": "#/components/schemas/Goo"
}
}
},
"Foo": {
"type": "object"
},
"Goo": {
"type": "object"
}
}
}
Expected behavior
Because class Goo has its own endpoint with multiple operations (same as class Moo), I expect that component Foo will be included as reference in Goo component as shown below.
Expected part of generated model:
"components": {
"schemas": {
"Moo": {
"type": "object",
"properties": {
"foo": {
"$ref": "#/components/schemas/Foo"
},
"goo": {
"$ref": "#/components/schemas/Goo"
}
}
},
"Foo": {
"type": "object"
},
"Goo": {
"type": "object",
"properties": {
"foo": {
"$ref": "#/components/schemas/Foo"
}
}
}
}
}
As soon as you remove @JsonIgnoreProperties from class Moo result will look as above in "Expected part of generated model:". I suppose that as first component is generated Moo. Then components Foo and Goo are created. But in generation of component Goo is @JsonIgnoreComponent from Moo taken into account.