swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.71k stars 1.2k forks source link

Merging middleware information with routes #939

Open Zambiorix opened 3 years ago

Zambiorix commented 3 years ago

Is your feature request related to a problem? Please describe.

I am using Swag with Echo and I've implemented several middleware, like authorization, rate limit, logging and lots more. These middleware sometimes use header and/or parameter information and can produce failures.

Now when I describe a route I have to remember to include all the possible information from the used middlewares. That is prone to errors, if I forget something or if the middleware is updated...

Unless I am mistaken, there is no way of merging middleware information with routes.. I would love to see a solution that solves this problem

Describe the solution you'd like

Maybe include 2 new tags:

For middleware description:

// @Middleware myMiddleware
// @Failure 503 {object} httputil.HTTPError

For route description:

// @MiddlewareRef myMiddleware

So that information from the middleware is merged with the route information

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

Thanks!

ubogdan commented 3 years ago

I think a better idea is to use an @template annotation and include that template in your route/controler definition.

Do you think you contribute with a PR for this issue?

addshore commented 1 year ago

I have a similar usecase for such as feature, either middleware-focused, or template focused (or perhaps some sort of global response template)

Right now I have to define the following in all routes, which are actually specific to a middleware

// @Failure 429 {string} string "Limit exceeded"
// @Header       429  {integer}  X-Ratelimit-Limit
// @Header       429  {integer}  X-Ratelimit-Remaining
// @Header       429  {integer}  X-Ratelimit-Reset