elysiajs / elysia-swagger

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

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

Open amritk opened 1 month ago

amritk commented 1 month 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 month 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