Reputation: 79
I'm currently working on a Spring Boot project with Springdoc for API documentation. I have a need to hide certain classes from appearing in the Swagger UI schema. I've tried using the @Schema(hidden=true) and @Hidden annotations from the OpenAPI 3 specification on the class level, but these do not seem to have any effect.
Here's an example of how I'm using these annotations:
@Getter
@Setter
@Entity
@Hidden
@Schema(hidden = true)
@Table(name = "difficulty")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Difficulty {
@Id
@Column(name = "id", nullable = false)
private Integer id;
@Column(name = "name", nullable = false, length = 10)
private String name;
}
However, when I use these annotations at the field level within a class, they work as expected, and the annotated fields do not appear in the schema.
@Getter
@Setter
@Entity
@Table(name = "difficulty")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Difficulty {
@Id
@Hidden
@Column(name = "id", nullable = false)
private Integer id;
@Column(name = "name", nullable = false, length = 10)
private String name;
}
here are dependecies
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-security</artifactId>
<version>1.7.0</version>
</dependency>
Upvotes: 0
Views: 2208
Reputation: 1
Do the following
Upvotes: 0
Reputation: 2724
To hide specific classes from appearing in the Swagger UI schema, you can leverage below annotations provided by Swagger :
@ApiIgnore
@ApiOperation(hidden = true)
Both annotations helps us control which classes/methods appear in the Swagger UI schema.
Note : Please add springfox-swagger2
and springfox-swagger-ui
in project's build configuration to enable Swagger integration.
Upvotes: 0