Skip to content

Error when using auth: Cannot read properties of undefined #1005

@crowbait

Description

@crowbait

Describe the bug
When using BasicAuth in my spec, express-openapi-validator fails with the following message:

Cannot read properties of undefined (reading 'undefined')

Validator settings as follows:

app.use(OpenApiValidator.middleware({
  apiSpec: specYAML /* const, path to spec generated on runtime */,
  validateRequests: {
    coerceTypes: false,
    allowUnknownQueryParameters: false,
    removeAdditional: 'all'
  },
  validateResponses: {
    coerceTypes: false,
    removeAdditional: 'failing'
  }
}));

I'm using the following spec (cut for consistency):

openapi: 3.0.0
paths:
  /auth:
    get:
      operationId: auth
      description: Accepts credentials in HTTP Basic Auth and validates them. Will respond with HTTP status codes but no content.
      parameters: []
      responses:
        '200':
          description: The request has succeeded.
        '401':
          description: Access is unauthorized.
      security:
        - BasicAuth: []
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic

Using the same security scheme on any other route fails with the same message. Removing the security description from the spec "solves" the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions