reactjsreduxswaggerswagger-ui

Selectively disable "Try it out" in swaggerUI


Although there is a long discussion on the topic here: https://github.com/swagger-api/swagger-ui/issues/156

I have not found a cleaner way to 'selectively' disable the "Try it out" button. I want to disable it for all the POST methods of my API.

Thank you in advance


Solution

  • Swagger UI 3.10.0+ and 2.x provide the supportedSubmitMethods option to control which HTTP methods have "try it out" enabled (default = all).

    To disable "try it out" for POST (but not PATCH/PUT):

    // index.html (Swagger UI 3.10+)
    
    const ui = SwaggerUIBundle({
      url: "http://my.api.com/openapi.yaml",
      supportedSubmitMethods: ["get", "delete", "options", "head", "patch", "trace"], // No "post"
      ...
    })
    

    To disable "try it out" for all methods except GET and HEAD:

      supportedSubmitMethods: ["get", "head"],