-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
Describe the bug
As READMD.md mentioned below:
// JSONResult's data field will be overridden by the specific type proto.Order
@success 200 {object} jsonresult.JSONResult{data=proto.Order} "desc"
swaggo supports overriding an existing struct with another struct type in comments.
However, in the v2 branch, this feature is not working correctly.
To Reproduce
Steps to reproduce the behavior:
create a simple example:
main.go
import (
"net/http"
"swaggo-v2/api"
)
// @title Swagger Example API
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
func main() {
http.HandleFunc("/testapi/data1/", api.GetData1)
http.HandleFunc("/testapi/data2/", api.GetData2)
http.ListenAndServe(":8080", nil)
}api/api.go
package api
import "net/http"
type Response struct {
httpStatus int `json:"-"`
Code string `json:"code" example:"0"`
Msg string `json:"message"`
Data interface{} `json:"data"`
}
type GetData1Response struct {
Field1 string `json:"field1" example:"Field1"`
Field2 string `json:"field2" example:"Field2"`
}
// GetData1 godoc
//
// @Summary Get data1
// @Produce json
// @Success 200 {object} Response{data=GetData1Response}
// @Router /internal/data1 [get]
func GetData1(w http.ResponseWriter, r *http.Request) {
//write your code
}
type GetData2Response struct {
Field3 string `json:"field3" example:"Field3"`
Field4 string `json:"field4" example:"Field4"`
}
// GetData2 godoc
//
// @Summary Get data2
// @Produce json
// @Success 200 {object} Response{data=GetData2Response}
// @Router /internal/data2 [get]
func GetData2(w http.ResponseWriter, r *http.Request) {
//write your code
}Expected behavior
expect swagger.yaml should be like this

not currently would got like this

Your swag version
v2.0.0-rc4
Your go version
go1.23.1
Desktop (please complete the following information):
- OS: macOS, darwin/arm64
- Browser: arc
- Version: Sonoma Version 14.5
Additional context
Add any other context about the problem here.
hunshcn, hainguyen8y and SkinonikS
Metadata
Metadata
Assignees
Labels
No labels