scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.41k stars 225 forks source link

Is it possible to enable withCredentials #299

Open JonMoore46 opened 2 years ago

JonMoore46 commented 2 years ago

As far as I can tell it should be possible to now enable auth cookies to be sent with requests via swagger-ui - https://github.com/swagger-api/swagger-js/issues/1163.

However I can't seem to work out how to enable this.

I have tried

const swaggerOptions: swaggerJSDoc.OAS3Options = {
  definition: {
    openapi: "3.0.0",
    info: {
      title: "Service",
      version: "0.0.0",
    },
    components: {
      securitySchemes: {
        exampleCookie: {
          name: "example",
          type: "apiKey",
          in: "cookie",
        },
      },
    },
  },
  apis: [path.join(__dirname, "../routes/*.js")],
};

export const openApiSpecification = swaggerJsdoc(swaggerOptions);

Then in my main app.js file

app.use(
    "/api/api-docs",
    swaggerUi.serve,
    swaggerUi.setup(openApiSpecification, { swaggerOptions: { withCredentials: true } })
  );

But with no luck and can't seem to figure it out.

Any help appreciated.

scottie1984 commented 2 years ago

Not familiar with this setting however setting it through to swaggerOptions should work

airedwin commented 2 years ago

I think I have the same question, I want to enable authenticated requests in the "Try it out". Right now it's not sending my bearer auth info when I "Execute". I tried the withCredentials: true as well.

sophie-pan commented 10 months ago

any update ?