go-swagger / go-swagger

Swagger 2.0 implementation for go
https://goswagger.io
Apache License 2.0
9.48k stars 1.25k forks source link

How examples/server-complete implements swaggerUI? #2754

Open Icarus9913 opened 2 years ago

Icarus9913 commented 2 years ago

Hello! I checked examples/tutorials/todo-list/server-complete source codes and did not find api property useSwaggerUI set to be true or method func (o *TodoListAPI) UseSwaggerUI() is called. But I still can visit swaggerUI with route /docs. How does it possible? Is there any flags did it which I ignored?

Environment

swagger version: 42c184c0 OS: darwin

casualjim commented 2 years ago

The UseSwaggerUI is a toggle between a redoc docs site and a swagger ui docs site.

https://github.com/go-swagger/go-swagger/blob/922497f70e5bde7fa3e0a1e34f104845ffa322f6/examples/tutorials/todo-list/server-complete/restapi/operations/todo_list_api.go#L123-L131

if you want to disable /docs you can use a global middleware that returns not found for the /docs path.

Icarus9913 commented 2 years ago

Copied by @casualjim : A server project built by go-swagger owns the capability to provide a UI. And the property 'useSwaggerUI' is a toggle between a redoc docs site and a swagger ui docs site, which could be thought as a UI theme.

The UI is very small, it's a single js you include in a basic html5 page. All the capability provided by 'go-openapi' project.

For details, you can find below: https://github.com/go-openapi/runtime/blob/master/middleware/redoc.go https://github.com/go-openapi/runtime/blob/master/middleware/swaggerui.go