New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to serve Swagger UI from a preexisting web app? #1029

Closed
mcandre opened this Issue May 3, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@mcandre
Copy link

mcandre commented May 3, 2017

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.

@mcandre

This comment has been minimized.

Copy link

mcandre commented May 3, 2017

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

@casualjim

This comment has been minimized.

Copy link
Member

casualjim commented May 3, 2017

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.

@casualjim

This comment has been minimized.

Copy link
Member

casualjim commented May 3, 2017

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
#370

@satyababu

This comment has been minimized.

Copy link

satyababu commented Jan 30, 2018

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

fredbi added a commit to fredbi/go-swagger that referenced this issue Mar 25, 2018

FAQ update
Updated FAQ in docs, with content gathered from "question" issues.

Corresponding issues may be now closed:
- fixes go-swagger#997
- fixes go-swagger#1334
- fixes go-swagger#1029
- fixes go-swagger#1375

fredbi added a commit to fredbi/go-swagger that referenced this issue Mar 25, 2018

FAQ update
Updated FAQ in docs, with content gathered from "question" issues.

Corresponding issues may be now closed:
- fixes go-swagger#997
- fixes go-swagger#1334
- fixes go-swagger#1029
- fixes go-swagger#1375

@fredbi fredbi referenced this issue Mar 25, 2018

Merged

FAQ update #1460

fredbi added a commit to fredbi/go-swagger that referenced this issue Mar 25, 2018

FAQ update
Updated FAQ in docs, with content gathered from "question" issues.

Corresponding issues may be now closed:
- fixes go-swagger#997
- fixes go-swagger#1334
- fixes go-swagger#1029
- fixes go-swagger#1375
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment