Skip to content

defineRouteMeta excludes falsy enum values ​​from OpenAPI definition #3892

Closed

Description

@nogic1008

Environment

  • Node.js: 24.11.1
  • Nuxt: 4.2.2
  • nitropack: 2.12.9

Reproduction

  1. Enable OpenAPI feature (set experimental.openAPI to true)
  2. Write OpenAPI meta within defineRouteMeta that contains falsy value (ex. 0, "") in enum
    defineRouteMeta({
      openAPI: {
        parameters: [
          {
            in: 'query',
            name: 'val',
            schema: { type: 'integer', enum: [0, 1, 2, 3, 4] },
          },
        ],
      },
    });
  3. Launch server and access to /_openapi.json

https://stackblitz.com/edit/github-fxzr4xvy?file=server%2Froutes%2Findex.ts

Describe the bug

OpenAPI json does not contain falsy value in enum.

{
  "openapi": "3.1.0",
  "info": {
    "title": "Nitro Server Routes"
  },
  "servers": [
    {
      "url": "http://localhost:3000",
      "description": "Local Development Server",
      "variables": {}
    }
  ],
  "paths": {
    "/": {
      "get": {
        "tags": [
          "App Routes"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "val",
            "schema": {
              "type": "integer",
              "enum": [
                // missing 0!!!
                1,
                2,
                3,
                4
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
    // snipped...
  }
}

Additional context

This bug is caused by using filter(Boolean) for filtering in the astToObject function.

function astToObject(node: Expression | Literal): any {
  switch (node.type) {
    case "ObjectExpression": {
      const obj: Record<string, any> = {};
      for (const prop of node.properties) {
        if (prop.type === "Property") {
          const key = (prop.key as any).name ?? (prop.key as any).value;
          obj[key] = astToObject(prop.value as any);
        }
      }
      return obj;
    }
    case "ArrayExpression": {
      // filter(Boolean) rejects all falsy value (0, "", NaN...)
      return node.elements.map((el) => astToObject(el as any)).filter(Boolean);
      // To exclude null and undefined only, use:
      return node.elements.map((el) => astToObject(el as any)).filter(o => o != null);
    }
    case "Literal": {
      return node.value;
    }
    // No default
  }
}

Logs

Activity

  1. added
    pending triage
    on Dec 22, 2025
  2. coderabbitai commented on Dec 22, 2025

    @coderabbitai
    Contributor
    🔗 Similar Issues

    Related Issues

    👤 Suggested Assignees

    Enable issue planning

    To enable issue planning, add the following to your .coderabbit.yaml:

    issue_enrichment:
      planning:
        enabled: true

    You can then request a plan by commenting @coderabbitai plan on any issue.

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord or schedule a call!

  3. nogic1008 commented on Jan 19, 2026

    @nogic1008
    Author

    @pi0 Please reopen this issue because #3895 (PR for v2) has not merged yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions