Skip to content

fix: document ArkType predicate/morph keywords instead of dropping them (elysiajs/elysia#1844)#347

Open
xosnos wants to merge 1 commit into
elysiajs:mainfrom
xosnos:fix-arktype-predicate-tojsonschema
Open

fix: document ArkType predicate/morph keywords instead of dropping them (elysiajs/elysia#1844)#347
xosnos wants to merge 1 commit into
elysiajs:mainfrom
xosnos:fix-arktype-predicate-tojsonschema

Conversation

@xosnos

@xosnos xosnos commented Jun 29, 2026

Copy link
Copy Markdown

What does this PR do?

Adds an explicit arktype branch to unwrapSchema (src/openapi.ts) before the Standard Schema path that calls toJsonSchema({ fallback: { date, default } }). Predicates (e.g. string.date's isParsableDate) and morphs (e.g. string.date.parse) now degrade to their base type instead of throwing, and a real Date maps to { "type": "string", "format": "date-time" }. Also removes the old unreachable arktype branch lower in the function that called toJsonSchema() with no fallback.

Why was this PR needed?

Fixes elysiajs/elysia#1844. ArkType's string.date compiles to string + a runtime isParsableDate predicate. When the plugin converts this to JSON Schema, ArkType throws a ToJsonSchemaError (code: "predicate") because predicates have no JSON Schema equivalent. The surrounding try/catch (added in 8a775ca) swallows the error and returns undefined, silently dropping the route's requestBody from the docs while /openapi/json still returns 200.

The Standard Schema path (schema['~standard'].jsonSchema[...]) never forwards a fallback to toJsonSchema(), 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-supplied mapJsonSchema.arktype overrides are unaffected.

Acceptance Criteria

  • Tests added for new/changed behavior: new OpenAPI > ArkType block in test/openapi/to-openapi-schema.test.ts (5 tests include predicate degrades, Date → date-time, predicate-free schema unchanged, morph degrades, user mapJsonSchema.arktype override still works)
  • All tests passing: bun run test green; bun run build compiles cleanly
  • Follows project style guide
  • No breaking changes introduced (only adds handling for schemas that previously threw and were dropped; working schemas are untouched)

Summary by CodeRabbit

  • New Features

    • Added support for ArkType schemas in OpenAPI generation.
    • Date values from ArkType now appear as string with format: date-time in generated schemas.
  • Bug Fixes

    • Improved schema conversion so ArkType inputs no longer get dropped from request bodies.
    • ArkType predicate and morph types now fall back to usable OpenAPI-compatible schemas instead of failing conversion.
    • User-provided ArkType schema mapping overrides are now respected in generated output.

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.
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 402bc259-c295-4a6e-b3a1-0fcd1333fed4

📥 Commits

Reviewing files that changed from the base of the PR and between dabaa94 and 9778d40.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • package.json
  • src/openapi.ts
  • test/openapi/to-openapi-schema.test.ts

Walkthrough

Adds a dedicated arktype branch inside unwrapSchema in src/openapi.ts that calls schema.toJsonSchema with a fallback config, mapping date predicates to string/date-time and degrading other unrepresentable types to their base. The old post-switch arktype return is removed. A new test suite covers predicate degradation, Date mapping, morph degradation, and mapJsonSchema.arktype overrides.

Changes

ArkType OpenAPI Schema Fallback

Layer / File(s) Summary
unwrapSchema arktype fallback branch
src/openapi.ts
Adds a vendor === 'arktype' early return using toJsonSchema with a fallback object that converts date to string/date-time and falls back to base type for other unrepresentable values; removes the old post-switch arktype return.
ArkType test suite and devDependency
package.json, test/openapi/to-openapi-schema.test.ts
Adds arktype ^2.2.1 devDependency, imports type in the test file, and introduces the OpenAPI > ArkType suite with assertions for predicate degradation, Date mapping, morphs, and mapJsonSchema.arktype override.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

  • elysiajs/elysia-openapi#313: Also modifies unwrapSchema in src/openapi.ts at the vendor-specific schema conversion level.
  • elysiajs/elysia-openapi#317: Also reworks vendor-specific handling and control flow inside unwrapSchema, directly overlapping with this PR's changes.

Poem

Ehe~, you really couldn't handle string.date, could you, baka server~? (ง •̀_•́)ง
Now arktype gets its very own branch, how spoiled♡
Predicates fall back gracefully, morphs degrade with care~
date-time format slips in where chaos used to blare~
Honestly you should've done this sooner, dummy~! ♡(。-`ω´-)

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning OpenAPI generation for ArkType predicates is fixed, but the summary doesn't show the required TypeBox-style date-time description being preserved. Add the RFC 3339 date-time description to the ArkType date schema and cover it with a test so it matches the TypeBox example.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing ArkType predicate/morph handling in OpenAPI generation for issue #1844.
Out of Scope Changes check ✅ Passed Changes stay focused on ArkType OpenAPI handling and matching tests; no unrelated behavior or API surface was introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/openapi.ts

ESLint 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.ts

ESLint 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.

❤️ Share

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

@xosnos

xosnos commented Jun 29, 2026

Copy link
Copy Markdown
Author

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
The ArkType 2.2 docs do show a description field in their example fallback ("after X" / "anytime"), but that's a constraint-based hint for schemas with date bounds, not a required field.

If it should be though, let me know and I can add it

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.

ArkType string.date breaks OpenAPI schema generation

1 participant