Search code examples
swagger-ui

How to generate curl commands with the '-k' argument in Swagger UI?


I'm wondering if there's a way to change the default generated CURL command in Swagger UI. It generates

 CURL -X

and I would like to change it to

CURL -k

Is there a way to do this?


Solution

  • This is supported in Swagger UI 3.35.0 and later.

    You need to modify your Swagger UI configuration code (located e.g. in index.html) and add the following requestInterceptor. In the interceptor, use req.curlOptions to specify additional arguments for the generated curl commands.

    const ui = SwaggerUIBundle({
      dom_id: "#swagger-ui",
      url: "https://petstore.swagger.io/v2/swagger.json",
      ...
      requestInterceptor: (req) => {
        req.curlOptions = ["-k"];   // <-----------
        return req;
      }
    })