swaggo / gin-swagger

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

Support swagger oneOf #245

Closed StephanoGeorge closed 1 year ago

StephanoGeorge commented 1 year ago

https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/

For example:

type Response struct {
    Data any
}

func test(c *gin.Context) {
    switch c.Param("type") {
    case "string":
        c.JSON(http.StatusOK, Response{Data: String{...}})
        return
    case "int":
        c.JSON(http.StatusOK, Response{Data: Int{...}})
        return
    default:
    }
}

Thanks!

StephanoGeorge commented 1 year ago

Sorry for wrong repo