https://github.com/swaggo/swag/issues/123
I have a struct
type Person struct {
Name string `json:"name"
Email string `json:"email"
Occupation string `json:"occupation"
}
This is being used by a route to generate a swagger spec
// HandlePostPerson godoc
// @Summary Create a Person
// @Description Create a Person
// @Accept json
// @Produce json
// @Param person body Person true "A Person"
// @Router /person [post]
func (personHandler *PersonHandler) HandlePostPerson(c *gin.Context) {
...
}
This will make all the fields in the Person struct as required in the Swagger Spec.
Ignore fields in the swagger
If you are ok ignoring Email in the Request, then you have to do this:
type Person struct {
Name string `json:"name" validate:"required"`
Email string `json:"email"`
Occupation string `json:"occupation" validate:"required"`
}
This will make the Name & Occupation as required in your Swagger spec i.e. comes with *