Skip to content

fix(schema-typescript): handle numeric and boolean enum/const values#73

Merged
pyramation merged 1 commit intomainfrom
devin/1774556936-fix-numeric-enum-const
Mar 26, 2026
Merged

fix(schema-typescript): handle numeric and boolean enum/const values#73
pyramation merged 1 commit intomainfrom
devin/1774556936-fix-numeric-enum-const

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

@pyramation pyramation commented Mar 26, 2026

Summary

getTypeForProp() previously passed all enum and const values to t.stringLiteral(), which crashes on numbers and booleans (e.g. enum: [2, 3, 4] in a PostGIS dimension field). This PR adds type-aware literal creation using t.numericLiteral() and t.booleanLiteral() where appropriate.

Also fixes a subtle bug: const used a truthy check (if (prop.const)), which silently skipped const: false and const: 0. Changed to prop.const !== undefined.

The JSONSchema type is widened to match the JSON Schema spec: enum accepts (string | number | boolean)[] and const accepts string | number | boolean.

Review & Testing Checklist for Human

  • Verify the const !== undefined check doesn't regress on const: undefined or missing const — the old truthy check and the new check should behave identically for those cases, but worth a sanity check
  • Confirm the JSONSchema type widening (enum?: string[](string | number | boolean)[]) doesn't break any downstream consumers that depend on the narrower type
  • Run pnpm test in packages/schema-typescript — all 13 suites (22 tests) should pass with no snapshot changes to existing tests

Notes

  • All 17 existing snapshots are unchanged — string-only enums produce identical output
  • 5 new snapshots added covering: numeric enum, boolean enum, mixed enum, numeric const, boolean const
  • The String(enumValue) fallback in the string branch is safe since number/boolean are handled first; only actual strings reach it

Link to Devin session: https://app.devin.ai/sessions/ce1b2dafd42341bea5d7793b0c05ba6c
Requested by: @pyramation


Open with Devin

Previously, enum and const handling in getTypeForProp() only supported
string values, passing all values to t.stringLiteral(). This crashed
when encountering numeric enums (e.g. dimension: { enum: [2, 3, 4] })
or boolean enums/consts.

Changes:
- Update JSONSchema type: enum accepts (string | number | boolean)[],
  const accepts string | number | boolean
- Fix getTypeForProp() enum handling: use t.numericLiteral() for numbers,
  t.booleanLiteral() for booleans, t.stringLiteral() for strings
- Fix getTypeForProp() const handling: same type-aware literal creation
- Change const check from truthy to !== undefined (handles false/0)
- Add tests for numeric, boolean, and mixed enum/const values
@devin-ai-integration
Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 1dc881b into main Mar 26, 2026
36 checks passed
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

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.

1 participant