iris-contrib / swagger

Iris middleware to automatically generate RESTful API documentation with Swagger 2.0
MIT License
115 stars 32 forks source link

How to use swagger with different instance names #22

Closed avingoyal closed 1 year ago

avingoyal commented 1 year ago

Describe the bug I'm generating swagger documentation by running swag init --instanceName auth

To Reproduce Steps to reproduce the behavior:

  1. Create a simple go project, using iris
  2. Create a swagger folder in your project root
  3. Generate multiple swagger docs using different instancenames. For example:
    cd <Project-Root>/swagger
    swag init -dir ../cmd/myproject --instanceName main
    swag init -dir ../pkg/auth --instanceName auth
    swag init -dir ../pkg/anotherPackage --instanceName anotherPackage
  4. In your main.go, one should be able to register multiple instance names against differnet url paths. E.g. ginSwagger does it this way:
    router.GET("/swagger/main/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, ginSwagger.InstanceName("main")))
    router.GET("/swagger/auth/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, ginSwagger.InstanceName("auth")))
    router.GET("/swagger/anotherPackage/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, ginSwagger.InstanceName("anotherPackage")))

    For more details, please refer to this: https://myschools.me/suguo/gin-swagger/src/commit/88c9ed2643de9f3b9fd2ac9ad03d9e63bd7721d3/example/multiple/main.go

Expected behavior I should be able to define and use different instance names as I need to consolidate and generate swagger documentation for all of my packages at one place.

Screenshots Not applicable

Desktop (please complete the following information):

iris.Version