Open xorima opened 1 month ago
based on attachment readme. the code should be like this
type Response struct {
Status int `json:"status"`
Data any `json:"data"`
}
type DTOs struct {
A string `json:"a" example:"a"`
B string `json:"b" example:"b"`
C string `json:"b" example:"c"`
}
// Post - Receives the GitHub webhooks
//
// @Summary This API is there to receive the GitHub events.
// @Description Once received, this will add them to the event stream for consumers.
// @Tags Webhooks
// @Accept json
// @Produce json
// @Success 200 {object} Response{data=DTOs} "Successful Response"
// @Router /api/v1/webhook/github [post]
func (wh *WebhookHandler) Post(w http.ResponseWriter, r *http.Request) {
wh.log.Info("got request")
resp := NewResponse(http.StatusAccepted, "Accepted")
w.WriteHeader(resp.Status)
_, err := w.Write(resp.ToJson())
if err != nil {
wh.log.Error("failure in writing webhook response", slogger.ErrorAttr(err))
}
}
Thanks @martinyonatann
using the example has gotten closer, but still not fully there
this is using this as the example:
type Response struct {
Status int `json:"status"`
Message string `json:"message"`
}
type Success struct {
A int `json:"status" example:"200"`
}
// @Success 202 {object} Response{status=Success} "Successful Response"
It feels like I will have to make a custom response type for each, which while not end of the world it's not what I originally intended :)
Describe the bug In the documentation it says I can give detail to the generated examples in the below maner, but when I try this I get an error:
Readme example:
error got on my code :
2024/10/06 12:45:03 ParseComment error in file /Users/jfield/dev/xorima/github-bridge/internal/app/webhook.go :invalid type: Response{status=200,message=
To Reproduce Code: file:
app/webhook.go
file:
app/response.go
Expected behavior
swag init
generates with appropriate examplesScreenshots
Your swag version 1.16.3
Your go version e.g. 1.12.0
Additional context I am doing this so I will not have to create multiple structs that are identical but have different examples, as that would add complexity which is not desired