elysiajs / elysia-swagger

A plugin for Elysia to auto-generate Swagger page
MIT License
86 stars 47 forks source link

components.securitySchemes is missing from the generated openapi.json #160

Open amritk opened 2 weeks ago

amritk commented 2 weeks ago

As seen in this ticket, when you specify security on an endpoint, how can you get the securityScheme added to the components.securitySchemes in the openapi.json?

periabyte commented 1 week ago

@amritk I had the same problem, but based on this #8 component.securitySchemes should be placed inside the documentation property like

new Elysia().use(
  swagger({
    documentation: {
      components: {
        securitySchemes: {
          BearerAuth: {
            type: 'http',
            scheme: 'bearer',
            bearerFormat: 'JWT',
          },
        },
      },
    },
    scalarConfig: {
      authentication: {
        preferredSecurityScheme: 'BearerAuth',
      },
    },
  }),
).get(
  '/endpoint',
  () => 'endpoint',
  { detail: { security: [{ BearerAuth: [] }] }
);

this should be detailed in the documentation, took me a while to find out the proper configuration