Add t.Union/t.Intersection handling in property enumerations/checks#1719
Add t.Union/t.Intersection handling in property enumerations/checks#1719SaltyAom merged 6 commits intoelysiajs:mainfrom
Conversation
WalkthroughIntroduces getSchemaProperties(schema) and refactors modules to use it instead of direct schema.properties access, updating schema traversal across unions/intersects, adjusting related getters, and adding tests for composite-schema property handling, file uploads, and query validation in union contexts. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
| hasAdditionalProperties(schema)) | ||
| }, | ||
| get hasDefault() { | ||
| if ('~hasDefault' in this) return this['~hasDefault'] |
There was a problem hiding this comment.
Drive-by fix, not sure if it's something in my setup but typescript was complaining about this, the other methods had ! so I added it in
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/schema.ts`:
- Around line 1071-1091: getSchemaProperties currently merges properties from
schema.allOf and schema.anyOf but ignores schema.oneOf, causing inconsistent
behavior with helpers like hasProperty/hasType/hasRef/hasTransform; update
getSchemaProperties to include schema.oneOf in the same merge logic (e.g., treat
members = schema.allOf ?? schema.anyOf ?? schema.oneOf) so that properties from
oneOf unions are also collected when calling getSchemaProperties(schema).
🧹 Nitpick comments (1)
test/schema/schema-utils.test.ts (1)
86-89: Consider adding test coverage foroneOfschemas.The
hasPropertyfunction handlesoneOf(as tested on lines 145-154), butgetSchemaPropertiesdoes not per the implementation insrc/schema.ts. Consider adding a test to document the expected behavior whengetSchemaPropertiesencounters aoneOfschema:it('returns undefined for oneOf schema (not supported)', () => { expect(getSchemaProperties({ oneOf: [ t.Object({ name: t.String() }), t.Object({ age: t.Number() }) ]} as any)).toBeUndefined() })Alternatively, if
oneOfshould be supported, the implementation insrc/schema.tswould need to be updated to handle it alongsideallOf/anyOf.
Hit this error:
Looking into it, realized elysia is doing naive
.properties-based checks and iteration in a couple of places, which meant that routes usingt.Union/t.Intersectwould either crash (my case) or silently behave incorrectly.Also the files code was handling
.anyOfbut not.allOfor.oneOf.Summary by CodeRabbit
Bug Fixes
Tests