We are using Swagger to model our API with Spring annotations:
@Operation(summary = "Creates a post for given user.")
@PostMapping("/post")
open fun createPost(
@RequestParam("userId") user: User,
)
The issue we are having is that Swagger does not know there is a logic behind and we are only passing userId: Long for which the user is loaded by Hibernate.
The model of User contains several @OneToOne, @ManyToOne, @OneToMany relations to other entities and Swagger builds the model of User with all of them. This causes the model to be huge and some of our Swagger docs wouldn't even load in the browser as the model is in the size of megabytes.
Is there a way to tell Swagger:
- to ignore specific entity/entities
- to enforce different type (in this case
Long)
Ideally something like:
@Operation(summary = "Creates a post for given user.")
@PostMapping("/post")
open fun createPost(
@SwaggerType(Long::class)
@RequestParam("userId")
user: User,
)