Skip to content

v11.0.0-alpha.10

Choose a tag to compare

@DZakh DZakh released this 13 Jul 07:03
c5e9346

What's Changed

Standard JSON Schema

The ~standard property implements the Standard JSON Schema spec, exposing a jsonSchema converter for the schema's input and output types. Call S.enableStandardJSONSchema() once to enable it:

S.enableStandardJSONSchema();

const schema = S.string.with(S.to, S.number);

schema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
// { $schema: "https://json-schema.org/draft/2020-12/schema", type: "string" }
schema["~standard"].jsonSchema.output({ target: "draft-2020-12" });
// { $schema: "https://json-schema.org/draft/2020-12/schema", type: "number" }

It also adds a dedicated StandardSchema.res binding for ReScript users + multiple targets support for S.toJSONSchema.

By @DZakh in #267

Fixes & Improvements

  • Fix S.pattern TS type declaration by @DZakh in #283
  • Fix S.merge TS returned schema input type by @DZakh in #291
  • S.void is now a separate schema with its own name by @DZakh in #292
  • Improved TS type performance by around 10x by @DZakh in #293
  • Fix issue #284 by @DZakh in #290
  • Fix JSON encoding of nested unions with flattened tagged objects by @DZakh in #297
  • TS: Support S.object({...}) besides advanced callback form by @DZakh in #299
  • TS: Support S.tuple([...]) besides advanced callback form by @DZakh in #309
  • TS: Support S.literal to help AI using Zod knowledge - this is just an alias for S.schema by @DZakh in #309
  • TS: Object schema inferred types now have optional fields at the end to match Zod behavior.
  • TS: S.schema now automatically infers object literal fields without a need for as const.

Internal Changes

Full Changelog: v11.0.0-alpha.9...v11.0.0-alpha.10