swaggo / gin-swagger

gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
MIT License
3.66k stars 266 forks source link

Enable annotation readOnly #283

Closed Tomelin closed 9 months ago

Tomelin commented 9 months ago

Hi,

I'm using gin-swagger and I created my swagger scope this format:

// NamingPost godoc // @Summary post all register in name API // @Tags naming // @Accept json // @Produce json // @Description post all register in name API // @Success 200 {object} []domain.Name // @Failure 404 {object} error // @Failure 500 {object} error // @Router /api/v1/name[post]

But I need to enable ReadOnly for ID. How can I enable the parameters in Openapi 3.0?

Tomelin commented 9 months ago

I found this option for enable in struct:

Take a note of key-value swaggerignore:”true”. This would help to hide those parameters which we don’t need in UI.

My struct looks like this:

type Name struct {
    Id   *int    `json:"id" binding:"required"swaggerignore:"true"`
    Name *string `json:"name" binding:"required"`
    Code *string `json:"code" binding:"required,min=3"`
}