1
votes

I'm using Springdoc to document my REST API made in Spring Boot. I need to hide some models/schemas from Schemas section in Swagger UI which are used only internally in API, so there is no need to display them in Schemas section.

This is one of the models I'm trying to hide:

@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table
public class EventRole extends AbstractEntity implements Serializable {
    @Column(nullable = false, length = 25)
    private String descriptor;
}

Superclass of model shown above:

@Data
@RequiredArgsConstructor
@SuperBuilder
@MappedSuperclass
public abstract class AbstractEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @CreationTimestamp
    @Column(nullable = false, updatable = false)
    private LocalDateTime creationDate;

    @UpdateTimestamp
    @Column(nullable = false)
    private LocalDateTime modificationDate;
}

Most of annotations in these examples are from JPA or Lombok. To be clear: AbstractEntity is not visible in Schemas section – I included it here just in case.

I've tried so far:

  • using @Hidden annotation on classes I want to hide
  • using @Schema(hidden = true) on these classes
  • adding SpringDocUtils.getConfig().addAnnotationsToIgnore(EventRole.class, AbstractEntity.class); to my OpenAPI bean configuration

Also I've tested @Hidden on controller methods and it works fine. @Schema(hidden = true) hides properly model properties. Unofrtunately, none of them hide whole model. Am I using wrong annotations or there might be other reason why this doesn't work? I'm new to OpenAPI 3.x and Springdoc and it is very likely that I misunderstood something.

A possible reason could be one of the API is using the model, thus even if you try to hide it, it's still resolved cause the endpoint needs it. Can you check your controller to see if the model is being used or not.Debargha Roy
@DebarghaRoy I'm sure that the model I'm trying to hide isn't used in any controller. I double checked it after reading your comment.Paweł Raglis
Can you share a reproducible example, maybe on GitHub, BitBucket etc.?Debargha Roy
@Paweł Raglis, you should add reproducible example as proposed by Debargha Roy.brianbro