Skip to content

Conversation

@kricsleo
Copy link
Member

πŸ”— Linked issue

resolves #3892

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@kricsleo kricsleo requested a review from pi0 as a code owner December 22, 2025 15:57
@vercel
Copy link

vercel bot commented Dec 22, 2025

@kricsleo is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Dec 22, 2025

πŸ“ Walkthrough

Walkthrough

Fixes a bug where falsy enum values (like 0 and empty strings) were excluded from OpenAPI definitions. Modifies the array filtering logic in the route metadata plugin to remove only undefined values instead of all falsy values, while updating test fixtures and snapshots to verify the fix.

Changes

Cohort / File(s) Change Summary
Core Fix
src/build/plugins/route-meta.ts
Changed ArrayExpression filter from .filter(Boolean) to .filter((obj) => obj !== undefined) to preserve falsy values (0, false, empty string, null) in enum definitions while removing only undefined results.
Test Updates
test/fixture/server/routes/api/meta/test.ts, test/presets/nitro-dev.test.ts
Added new query parameter "val" with integer type and enum [0, 1] to test fixture and updated corresponding OpenAPI snapshot to verify falsy enum values are now included.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Focus on the logic change in route-meta.ts to confirm the filter correctly excludes only undefined while preserving other falsy values
  • Verify test fixture accurately demonstrates the fix for falsy enum values (specifically value 0)
  • Confirm snapshot changes reflect the expected OpenAPI output with the new parameter

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
βœ… Passed checks (4 passed)
Check name Status Explanation
Title check βœ… Passed The title follows conventional commits format with 'fix' type and a clear, descriptive description of the change.
Description check βœ… Passed The description provides a linked issue reference and identifies the change type as a bug fix, clearly relating to the code modifications.
Linked Issues check βœ… Passed The code changes directly address issue #3892 by modifying the array filtering logic to preserve falsy values like 0 and empty strings in OpenAPI enum definitions.
Out of Scope Changes check βœ… Passed All changes focus on fixing the OpenAPI enum filtering issue; the test updates properly document the new 'val' parameter behavior and are within scope.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
test/fixture/server/routes/api/meta/test.ts (1)

7-14: Good test coverage for the falsy value bug, consider expanding.

The new parameter with enum: [0, 1] effectively tests that the falsy value 0 is now correctly preserved in the OpenAPI output, directly addressing the reported issue.

Consider adding test coverage for other falsy values like empty strings (""), false, or edge cases to ensure comprehensive validation of the fix.

πŸ”Ž Example: Additional test parameter with empty string enum
{
  in: "query",
  name: "status",
  schema: { type: "string", enum: ["", "active", "inactive"] },
}
πŸ“œ Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 0f3740d and e9d1b7c.

πŸ“’ Files selected for processing (3)
  • src/build/plugins/route-meta.ts
  • test/fixture/server/routes/api/meta/test.ts
  • test/presets/nitro-dev.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: tests-rollup (windows-latest)
  • GitHub Check: tests-rollup (ubuntu-latest)
  • GitHub Check: tests-rolldown (windows-latest)
  • GitHub Check: tests-rolldown (ubuntu-latest)
πŸ”‡ Additional comments (2)
test/presets/nitro-dev.test.ts (1)

48-58: LGTM! Snapshot correctly reflects the fix.

The updated snapshot confirms that the falsy value 0 now correctly appears in the OpenAPI enum, validating that the fix works end-to-end from route metadata definition to OpenAPI output.

src/build/plugins/route-meta.ts (1)

106-108: The fix correctly preserves null values in arraysβ€”this is intentional.

The change from .filter(Boolean) to .filter((obj) => obj !== undefined) is the correct fix. According to commit e9d1b7c, this was specifically designed to "only filter undefined from array nodes," preserving legitimate falsy values like 0, "", false, and null that may appear in route metadata. This prevents legitimate data from being lost during OpenAPI metadata extraction.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 22, 2025

Open in StackBlitz

npm i https://pkg.pr.new/nitrojs/nitro@3894

commit: e9d1b7c

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pi0 pi0 merged commit fb6b85d into nitrojs:main Dec 24, 2025
10 of 11 checks passed
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

Successfully merging this pull request may close these issues.

defineRouteMeta excludes falsy enum values ​​from OpenAPI definition

2 participants