fix: document ArkType predicate/morph keywords instead of dropping them (elysiajs/elysia#1844)#347
Conversation
ArkType `string.date` expands to `string` + an `isParsableDate` predicate, so its `toJsonSchema()` throws; the plugin's try/catch (8a775ca) swallows it and the route body is silently dropped. Handle the `arktype` vendor before the Standard Schema path with a `{ date, default }` fallback: predicates and morphs degrade to their base type, `Date` maps to `string`/`date-time`, and a user-supplied `mapJsonSchema.arktype` override still wins. Adds an `OpenAPI > ArkType` test block and `arktype` to devDependencies.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
WalkthroughAdds a dedicated ChangesArkType OpenAPI Schema Fallback
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/openapi.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. test/openapi/to-openapi-schema.test.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. 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 |
|
CodeRabbit's warning seems to be a false positive. The "RFC 3339 date-time description" requirement it cites doesn't look like it exists in this codebase and the format: "date-time" already implies RFC 3339 compliance per the OpenAPI spec itself. https://arktype.io/docs/blog/2.2 If it should be though, let me know and I can add it |
What does this PR do?
Adds an explicit
arktypebranch tounwrapSchema(src/openapi.ts) before the Standard Schema path that callstoJsonSchema({ fallback: { date, default } }). Predicates (e.g.string.date'sisParsableDate) and morphs (e.g.string.date.parse) now degrade to their base type instead of throwing, and a realDatemaps to{ "type": "string", "format": "date-time" }. Also removes the old unreachablearktypebranch lower in the function that calledtoJsonSchema()with no fallback.Why was this PR needed?
Fixes elysiajs/elysia#1844. ArkType's
string.datecompiles tostring+ a runtimeisParsableDatepredicate. When the plugin converts this to JSON Schema, ArkType throws aToJsonSchemaError(code: "predicate") because predicates have no JSON Schema equivalent. The surroundingtry/catch(added in 8a775ca) swallows the error and returnsundefined, silently dropping the route'srequestBodyfrom the docs while/openapi/jsonstill returns200.The Standard Schema path (
schema['~standard'].jsonSchema[...]) never forwards afallbacktotoJsonSchema(), so it always throws on predicate- and morph-bearing types. The fix handles ArkType before that path using the{ date, default }fallback shape ArkType's own docs recommend. Predicate-free schemas and user-suppliedmapJsonSchema.arktypeoverrides are unaffected.Acceptance Criteria
OpenAPI > ArkTypeblock intest/openapi/to-openapi-schema.test.ts(5 tests include predicate degrades,Date→ date-time, predicate-free schema unchanged, morph degrades, usermapJsonSchema.arktypeoverride still works)bun run testgreen;bun run buildcompiles cleanlySummary by CodeRabbit
New Features
stringwithformat: date-timein generated schemas.Bug Fixes