Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoranD1 opened this issue Aug 28, 2023 · 2 comments
Open

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

GoranD1 opened this issue Aug 28, 2023 · 2 comments

Comments

@GoranD1
Copy link

GoranD1 commented Aug 28, 2023

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.

@C-D-Lewis
Copy link

@GoranD1 I'm affected by this too - what was your workaround?

@GoranD1
Copy link
Author

GoranD1 commented Feb 26, 2024

@C-D-Lewis Adding //@ts-ignore should do the trick and if @typescript/eslint is giving you troubles for it add the //eslint-disable-next-line @typescript-eslint/ban-ts-comment as well.

So in the end it would be something like this:

  app.use(
    '/api',
    useSofa({
      schema,
      basePath: '/api',
      openAPI: {
        components: {
          securitySchemes: {
            ApiKeyAuth: {
              type: 'apiKey',
              in: 'header',
              name: 'authorization',
            },
          },
        },
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        security: [
          {
            ApiKeyAuth: [],
          },
        ],
      },
    })
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants