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

Multiple security schemes not supported #1647

Open
2 tasks done
nzapponi opened this issue Apr 29, 2024 · 0 comments
Open
2 tasks done

Multiple security schemes not supported #1647

nzapponi opened this issue Apr 29, 2024 · 0 comments
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@nzapponi
Copy link
Contributor

Description

When defining multiple security schemes, the package fails to parse the spec, as it expects all security schemes to be defined in the security section.

According to the OpenAPI 3.0 spec, however, this is not required: https://swagger.io/docs/specification/authentication/ .

Conversion of type '{ openapi: string; info: { title: string; version: string; }; servers: { url: string; }[]; security: ({ sessionCookie: never[]; sessionToken?: undefined; } | { sessionToken: never[]; sessionC@dctr/api-spec:watch: ]; components: { ...; }; paths: { ...; }; }' to type 'Document' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Types of property 'security' are incompatible.
Type '({ sessionCookie: never[]; sessionToken?: undefined; } | { sessionToken: never[]; sessionCookie?: undefined; })[]' is not comparable to type 'SecurityRequirementObject[]'.
Type '{ sessionCookie: never[]; sessionToken?: undefined; } | { sessionToken: never[]; sessionCookie?: undefined; }' is not comparable to type 'SecurityRequirementObject'.
Type '{ sessionToken: never[]; sessionCookie?: undefined; }' is not comparable to type 'SecurityRequirementObject'.
Property '"sessionCookie"' is incompatible with index signature.
Type 'undefined' is not comparable to type 'string[]'.
31       apiSpec: spec as OpenAPIV3.Document,
Name Version
openapi-typescript 6.7.4

Reproduction

Define this securitySchemes components:

"securitySchemes": {
      "sessionToken": {
        "type": "http",
        "scheme": "bearer"
      },
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "my_session"
      }
    }

And set:

"security": [
    {
      "sessionCookie": []
    },
    {
      "sessionToken": []
    }
  ]

The intended behavior is that clients can use either security scheme.

Expected result

For the spec to successfully be typed.

Checklist

@nzapponi nzapponi added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

1 participant