Go-swagger: How to serve Swagger UI from a preexisting web app?

Created on 4 May 2017  路  4Comments  路  Source: go-swagger/go-swagger

Does go-swagger provide an http.HandlerFunc or other easy method for serving Swagger UI from a prexisting web app? I want my web app to expose /swagger-ui, without using code generation, and without hosting a separate server.

question

Most helpful comment

Hi @casualjim

It is followup question to this thread,

Is there any way can we serve swagger UI using swagger-ui instead of ReDoc?
Do you have any example on it.

Please let me know

All 4 comments

Specifically, the petstore example hardcodes the Swagger spec, whereas a production application would be more likely to use some kind of resource loading system. Could the petstore example be updated to load the JSON spec from a file nearby in version control? Or even better, skip files altogether and generate the spec on launch via Swagger Go lib?

https://github.com/go-swagger/go-swagger/blob/master/examples/2.0/petstore/server/api/petstore.go

that is when you use reflection like in a language like java. The way we have it here is make the generation of the spec be a build time concern instead of a runtime concern. The assumption that was made is that after you build your app the API is unlikely to change.

That example that you link to is when you generate the code from a swagger spec. And there we embed the spec as default behavior but that isn't a hard constraint, you can change that at generation time and pass one in or initialize the generated code with a spec that was loaded from aremote url etc.

Sorry I didn't answer the first question yet.

There are a few ways you can serve a ui.
Use the middleware provided in the go-openapi/runtime package: https://github.com/go-openapi/runtime/blob/master/middleware/redoc.go

Most manual
https://github.com/go-swagger/go-swagger/issues/370

Hi @casualjim

It is followup question to this thread,

Is there any way can we serve swagger UI using swagger-ui instead of ReDoc?
Do you have any example on it.

Please let me know

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ravenwater picture Ravenwater  路  3Comments

phedoreanu picture phedoreanu  路  4Comments

bobvanluijt picture bobvanluijt  路  3Comments

alihalabyah picture alihalabyah  路  4Comments

ribice picture ribice  路  4Comments