我正在使用 Swaggo 来记录我的 Go API 端点。我有一个处理程序函数,其中我在 JSON 结构字段中定义了一个带有示例标签的结构,但这些示例并未出现在生成的 Swagger UI 中。
// @Summary Register a new user
// @Description Creates a new user account. In development environment, the user is activated immediately. Otherwise, an activation email is sent.
// @Tags users
// @Accept json
// @Produce json
// @Param request body main.application.registerUserHandler.input true "User registration details"
// @Success 202 {object} object{user=data.User}
// @Router /users [post]
func (app *application) registerUserHandler(w http.ResponseWriter, r *http.Request) {
var input struct {
Name string `json:"name" example:"John Doe"`
Email string `json:"email" example:"[email protected]"`
Password string `json:"password" example:"SecurePass123!"`
}
// ... rest of the handler ...
}
Swagger 文档生成正确,但结构中示例标签的示例值未显示在请求主体模式中。
有没有办法让 Swaggo 识别嵌套/内联结构中的示例标签?