-
-
Notifications
You must be signed in to change notification settings - Fork 524
Problem when combining @Schema with @JsonBackReference #390
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
Comments
Hi @dohool, Please provide the necessary information listed on our contribution guide on the section of Using GitHub Issues:
This issue will be reopened, once the necessary information are completed. (Please don't create same issue for the same topic) |
Spring-Boot-Version: 2.2.1.RELEASE Springdoc:
Model-Class: public class UsersDTO {
private Long personId;
@JsonManagedReference
private List<RoleDTO> roles;
}
public class RoleDTO {
private String role;
@JsonBackReference
@Schema(hidden = true)
private UsersDTO user;
} Expected result (yaml):
Provided result:
|
Spring-Boot-Version: 2.1.10.RELEASE Same issue. |
As described earlier, when trying to hide a field annotated with @Entity
public class EntityA1
{
@Id
private Long id;
// Only by enabling this AND enabling the annotation on the getter, will the object be hidden.
@Schema(hidden = true) // enabling only this, does not cause field to be hidden
@JsonBackReference // disabling this causes field to be hidden
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "referenced_entity_id")
private EntityB entityB;
public Long getId()
{
return id;
}
//@Schema(hidden = true) // enabling this causes AND enabling on field, causes field to be hidden
public EntityB getEntityB()
{
return entityB;
}
} However,
Expected:
Actual:
Using springdoc-openapi 1.4.1. See attached project. |
This is not an issue on springdoc-openapi. We rely on swagger-core official jars. You are using the combination of
This is the pure swagger code to reproduce the error: ResolvedSchema resolvedSchema = ModelConverters.getInstance()
.resolveAsResolvedSchema(new AnnotatedType(EntityA3.class));
if (resolvedSchema.schema != null) {
Schema schemaN = resolvedSchema.schema;
Assert.isNull(schemaN.getProperties().get("entityB"), "Should be hidden");
} You can submit your request to the swagger-core team for this feature/issue to support about |
Thank you for your feedback and taking the time to point out this is not a springdoc issue. I am new to the whole springdoc / swagger world, so I have limited ideas what part are springdoc and what parts are swagger. As a result of this, I also have no clear idea why adding |
Right, you can have a look at the swagger documentation first. |
When designing a model with bidirectional relationships, i am using Jackson's
@JsonBackReference
annotation to specify the back part, which will be omitted from serialization.Due to this, it should also be ignored in the openapi documentation.
But using
@Schema(hidden = true)
in combination with@JsonBackReference
does not work. The@Schema(hidden = true)
is ignored.The text was updated successfully, but these errors were encountered: