fix(schema-typescript): handle numeric and boolean enum/const values#73
Merged
pyramation merged 1 commit intomainfrom Mar 26, 2026
Merged
Conversation
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 EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getTypeForProp()previously passed allenumandconstvalues tot.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 usingt.numericLiteral()andt.booleanLiteral()where appropriate.Also fixes a subtle bug:
constused a truthy check (if (prop.const)), which silently skippedconst: falseandconst: 0. Changed toprop.const !== undefined.The
JSONSchematype is widened to match the JSON Schema spec:enumaccepts(string | number | boolean)[]andconstacceptsstring | number | boolean.Review & Testing Checklist for Human
const !== undefinedcheck doesn't regress onconst: undefinedor missingconst— the old truthy check and the new check should behave identically for those cases, but worth a sanity checkJSONSchematype widening (enum?: string[]→(string | number | boolean)[]) doesn't break any downstream consumers that depend on the narrower typepnpm testinpackages/schema-typescript— all 13 suites (22 tests) should pass with no snapshot changes to existing testsNotes
String(enumValue)fallback in the string branch is safe since number/boolean are handled first; only actual strings reach itLink to Devin session: https://app.devin.ai/sessions/ce1b2dafd42341bea5d7793b0c05ba6c
Requested by: @pyramation