go-openapi / runtime

openapi runtime interfaces
Apache License 2.0
248 stars 148 forks source link

How to disable `try it out` option for the swagger-ui #318

Closed sheikhasim closed 7 months ago

sheikhasim commented 7 months ago

I'm using the middleware.SwaggerUI to serve openapi spec over the swaggerUI. I want to disable the try it out option for all endpoints. Is there a way to do that ?

fredbi commented 7 months ago

There are a few options to the UI templates. If this option is configurable in the JS asset, you can provide your own template with this setting using the middleware.WithUITemplate({template string}) option.

The default template that configures the UI widget is there: https://github.com/go-openapi/runtime/blob/5a6846cd279829a24dd000c1648e6ba9b5356787/middleware/swaggerui.go#L112

sheikhasim commented 7 months ago

I tried kind of same , passing custom Template with the SwaggerUIOpts, but it gives error unknown field Template.

`

            opts := middleware.SwaggerUIOpts{
    SpecURL:  fmt.Sprintf(swaggerSpecURL, version),
    BasePath: swaggerUIBasePath,
    Path:     version,
    Template: customSwaggerUITemplate,
}
swaggerUI := middleware.SwaggerUI(opts, nil)

error:unknown field Template in struct literal of type middleware.SwaggerUIOpts `

Update: Resolved with the above, there was some issue with the code Thank You!!