Skip to content

v6.3.0

Choose a tag to compare

@DZakh DZakh released this 08 Dec 22:23
· 512 commits to main since this release

🚀 API additions

  • Added space option to the S.jsonString utility schema. It allows to control the JSON format on serializing.
  • Added S.nullable schema (or S.nullish in JS/TS API). Nullable/Nullish schemas will accept both undefined and null

💥 Bug fixes

  • Fix union operations failing with some item schemas being invalid even before trying to run an operation with other item schemas (which are valid). Note that the bug was introduced in V5.

⚙️ New PPX attributes

@s.matches(S.t<'value>)

⚠️ It was previously @schema(S.t<'value>), which is now deprecated and will be completely removed in v7.

Applies to: type expressions

Specifies custom schema for the type.

@schema
type t = @s.matches(S.string->S.String.url) string

// Generated by PPX ⬇️
let schema = S.string->S.String.url

@s.null

Applies to: option type expressions

Tells to use S.null for the option schema constructor.

@schema
type t = @s.null option<string>

// Generated by PPX ⬇️
let schema = S.null(S.string)

@s.nullable

Applies to: option type expressions

Tells to use S.nullable for the option schema constructor.

@schema
type t = @s.nullable option<string>

// Generated by PPX ⬇️
let schema = S.nullable(S.string)

@s.default('value)

Applies to: type expressions

Wraps the type expression schema into an option with the provided default value.

@schema
type t = @s.default("Unknown") string

// Generated by PPX ⬇️
let schema = S.option(S.string)->S.Option.getOr("Unknown")

It might be used together with @s.null or @s.nullable:

@schema
type t = @s.nullable @s.default("Unknown") string

// Generated by PPX ⬇️
let schema = S.nullable(S.string)->S.Option.getOr("Unknown")

@s.defaultWith(unit => 'value)

Applies to: type expressions

Wraps the type expression schema into an option with callback to get the default value.

@schema
type t = @s.defaultWith(() => []) array<string>

// Generated by PPX ⬇️
let schema = S.option(S.array(S.string))->S.Option.getOrWith(() => [])

🧠 The same as @s.default it might be used together with @s.null or @s.nullable

@s.describe(string)

Applies to: type expressions

Adds description property to the generated schema.

@schema
type t = @s.describe("A useful bit of text, if you know what to do with it.") string

// Generated by PPX ⬇️
let schema = S.string->S.describe("A useful bit of text, if you know what to do with it.")

This can be useful for documenting a field, for example in a JSON Schema using a library like rescript-json-schema.

@s.deprecate(string)

Applies to: type expressions

Adds deprecation property to the generated schema.

@schema
type t = @s.deprecate("Will be removed in APIv2") string

// Generated by PPX ⬇️
let schema = S.string->S.deprecate("Will be removed in APIv2")

This can be useful for documenting a field, for example in a JSON Schema using a library like rescript-json-schema.

Full Changelog: v6.2.0...v6.3.0