feat(effect): improve JSON Schema converter with caching and options - #2175
Conversation
Generate JSON Schema with Effect's built-in `Schema.toJsonSchemaDocument` instead of going through `Schema.toStandardJSONSchemaV1`, which mutated the schema's `~standard` property and accepted no options. - Forward Effect's `ToJsonSchemaOptions` (`onExcessProperty`, `generateDescriptions`, `includeAnnotationKey`, `referencePolicy`) - Add the `cache` option, matching the other converters - Only match actual Effect schemas in `condition` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016FEE7vGy6NSSU3yy1GLtMR
Collapse the option-forwarding tests into one table, drop a $defs test covered by the recursion test, hoist a repeated schema, and stop mutating the shared Schema.Unknown instance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016FEE7vGy6NSSU3yy1GLtMR
Let errors from `Schema.toJsonSchemaDocument` reach the caller instead of silently replacing the whole schema with an empty optional one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016FEE7vGy6NSSU3yy1GLtMR
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
orpc | affa9da | Commit Preview URL Branch Preview URL |
Oct 04 2026, 07:43 AM |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/bun
@orpc/client
@orpc/cloudflare
@orpc/contract
@orpc/experimental-effect
@orpc/evlog
@orpc/hibernation
@orpc/json-schema
@orpc/experimental-lock
@orpc/experimental-msw
@orpc/nest
@orpc/next
@orpc/node
@orpc/openapi
@orpc/opentelemetry
@orpc/pinia-colada
@orpc/pino
@orpc/publisher
@orpc/ratelimit
@orpc/server
@orpc/shared
@orpc/swr
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/zod
commit: |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — reimplementation of EffectSchemaToJsonSchemaConverter against Effect 4's Schema.toJsonSchemaDocument, plus expanded tests and docs.
- Direct Effect conversion —
convertnow callsSchema.toJsonSchemaDocument, usingSchema.toType(schema)for theoutputdirection and merging returneddefinitionsinto the root as$defs. - Optionality — now computed via
isStandardSchemaOptionalon the standard-schema wrapper;conditionadditionally requiresEffectSchema.isSchema(schema). - Options forwarding —
EffectSchemaToJsonSchemaConverterOptionsextendsSchema.ToJsonSchemaOptions(onExcessProperty,generateDescriptions,includeAnnotationKey,referencePolicy) and adds an opt-incache(per-direction WeakMaps). - Error propagation — Effect conversion errors now surface instead of being swallowed to
{}. - Tests + docs — 24 tests and
effect.mdxupdates for options,$defs, andcache.
I compared the new output against the base implementation for a spread of schemas (transforms like NumberFromString/Date/Trim, structs, classes, optionals, NullOr, recursive Category, record, union, tuple) in both directions: JSON Schema is byte-identical. The only behavioral delta is that Schema.UndefinedOr(Schema.String) on input is now optional: true (base said false) — a correctness fix, since UndefinedOr accepts undefined and the new path validates the real Effect standard schema. $defs output matches what OpenAPIComponentRegistry.hoistDefs expects, and cache is off by default so there is no default-path regression. type:check and eslint pass, and converter.test.ts is green (24/24).
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Refactors
EffectSchemaToJsonSchemaConverterto directly use Effect'sSchema.toJsonSchemaDocumentAPI instead of wrapping the standard JSON schema converter, enabling better support for Effect-specific features and improved test coverage.Key Changes
Schema.toJsonSchemaDocumentdirectly, which properly handles Effect schemas with identifiers, class definitions, and recursive schemas by preserving them in$defsSchema.ToJsonSchemaOptions(e.g.,onExcessProperty,generateDescriptions,includeAnnotationKey,referencePolicy) to Effect's convertercacheparameter to reuse conversion results per schema instance and direction via WeakMap, improving performance for repeated conversionsisStandardSchemaOptionalhelper for consistent optional field detection across input/output directionsDocumentation Updates
Updated integration docs to reflect the new converter capabilities, including examples of using options and guidance on the
cacheoption for performance optimization.https://claude.ai/code/session_016FEE7vGy6NSSU3yy1GLtMR