gogf / gf

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
https://goframe.org
MIT License
11.5k stars 1.57k forks source link

net/ghttp: Use `ghttp.MiddlewareHandlerResponse` causes the responses value in the swagger document to be incorrect #3786

Open nonlinearthink opened 6 days ago

nonlinearthink commented 6 days ago

What do you want to ask?

I am using ghttp.MiddlewareHandlerResponse, but the output swagger document does not include the 'code', 'message', and 'data' fields, and I used the swagger-generator to generate the client's code, which strongly depends on the swagger document.

UncleChair commented 5 days ago

Middleware would not change the final doc. If you want to add a "common response", you can add one in the openapi config

openapi.Config.CommonResponse = api.CommonRes{}

or change response structure one by one in your Standardized Routing.

nonlinearthink commented 5 days ago

@UncleChair Thank you, I have resolved this problem through:

openapi := s.GetOpenApi()
openapi.Config.CommonResponse = ghttp.DefaultHandlerResponse{}
openapi.Config.CommonResponseDataField = "Data"