Skip to content

Express v5: Array query params with bracket notation fail validation #1196

@sanderhmn

Description

@sanderhmn

Describe the bug
express-openapi-validator fails to validate query parameters when Express v5's default query parser is used with array notation (bracket syntax). Express v5 changed its default query parser from "extended" (qs library) to "simple" (Node's querystring module), which handles bracket notation differently.

To Reproduce

  1. Set up Express v5 with default settings (no custom query parser configuration)
  2. Configure express-openapi-validator with an OpenAPI spec that defines an array query parameter
  3. Make a request with bracket notation: ?tags[]=foo&tags[]=bar
  4. OpenAPI validation fails

Actual behavior
Express v5's default "simple" query parser (Node's querystring module) does not strip brackets from query parameter keys:

  • ?tags[]=foo&tags[]=bar is parsed as { 'tags[]': ['foo', 'bar'] }
  • OpenAPI schema expects the key tags, but receives tags[]
  • Validation fails because the parameter name doesn't match the schema

Expected behavior
express-openapi-validator should successfully validate array query parameters regardless of Express's query parser setting. Either:

  • Strip brackets from parameter names before validation, or
  • Document that Express v5 users must explicitly configure the "extended" query parser for bracket notation support

Examples and context
OpenAPI schema:

  parameters:
    - name: tags
      in: query
      schema:
        type: array
        items:
          type: string

Express v4 vs v5 parsing behavior:
// Express v4 (default: extended parser using qs library)
// GET /items?tags[]=foo&tags[]=bar
// req.query = { tags: ['foo', 'bar'] } ✓ Validation passes

// Express v5 (default: simple parser using querystring module)
// GET /items?tags[]=foo&tags[]=bar
// req.query = { 'tags[]': ['foo', 'bar'] } ✗ Validation fails

Workaround:
// Explicitly configure Express v5 to use extended query parser
app.set('query parser', 'extended');

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