gin-swagger icon indicating copy to clipboard operation
gin-swagger copied to clipboard

Multiple API versions or API Definitions in single server

Open mandeepji opened this issue 3 years ago • 5 comments

Hi, How can I support multiple versions (definitions) of APIs from single server?

Problem Statement: Product has to support multiple versions (latest & backward compatible) at different paths like: /v1/... /v2/... And have different swagger.yaml for each version.

Multiple versions could be using path variable (/{version}/...) but makes difficult to generate version specific output.

mandeepji avatar Feb 11 '22 17:02 mandeepji

@mandeepji you can take a look at the following example.

ubogdan avatar Apr 22 '22 13:04 ubogdan

@mandeepji you can take a look at the following example. @ubogdan Hi, I fllow the example: https://github.com/swaggo/gin-swagger/tree/master/example/multiple, and found a bug below: First i visit the v1 api document at: http://localhost:8080/swagger/v1/index.html and then visit the v2 api document at http://localhost:8080/swagger/v2/index.html and get the true response all. But last when i back to the v1 api document the *.css and *.js can not found.

solamiku avatar Jul 21 '22 02:07 solamiku

@ubogdan Hi, I fllow the example: https://github.com/swaggo/gin-swagger/tree/master/example/multiple, and found a bug below: First i visit the v1 api document at: http://localhost:8080/swagger/v1/index.html and then visit the v2 api document at http://localhost:8080/swagger/v2/index.html and get the true response all. But last when i back to the v1 api document the *.css and *.js can not found.

Hi, I faced the same issue

Reason, swaggerFiles.Handler is one single instance and patching the Prefix twice will end up making the request from first prefix invalid.

~~One ugly workaround is to use lower level of gin-swagger. For swaggerfiles.Handler, one from "github.com/swaggo/gin-swagger/swaggerFiles", one from "github.com/swaggo/files".~~

Updated: Use swaggerFiles.NewHandler() instead of swaggerFiles.Handler .

fzdy1914 avatar Jul 28 '22 09:07 fzdy1914

@fzdy1914, Would you mind updating the gin-swagger code base, please? I'm pretty busy this week.

ubogdan avatar Aug 02 '22 13:08 ubogdan

@fzdy1914, Would you mind updating the gin-swagger code base, please? I'm pretty busy this week.

@ubogdan Can check https://github.com/swaggo/gin-swagger/pull/224.

fzdy1914 avatar Aug 03 '22 03:08 fzdy1914