Skip to content

OpenAPI's "security" property is not typescript friendlyΒ #1369

@g-dobrilovic-levi9-com

Description

@g-dobrilovic-levi9-com

I tried to configure the authentication part of the openAPI documentation with the following config:

  app.use(
    '/api',
    useSofa({
      schema,
      basePath: '/api',
      openAPI: {
        components: {
          securitySchemes: {
            ApiKeyAuth: {
              type: 'apiKey',
              in: 'header',
              name: 'authorization',
            },
          },
        },
        security: [
          {
            ApiKeyAuth: [],
          },
        ],
      },
    })
  );

But typescript gives the following error:

Type '{ components: { securitySchemes: { ApiKeyAuth: { type: string; in: string; name: string; }; }; }; security: { ApiKeyAuth: never[]; }[]; }' is not assignable to type 'RouterOpenAPIOptions<any>'.
  Object literal may only specify known properties, and 'security' does not exist in type 'RouterOpenAPIOptions<any>'.ts(2322)
sofa.d.ts(37, 5): The expected type comes from property 'openAPI' which is declared here on type 'SofaConfig'

The security parameter works fine if I do some "hacking" and suppress typescript errors, so then I guess this is just the issue with types. I am on v0.18.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions