
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
ReScript PPX to generate Sury schema from types.
🧠 It's 100% opt-in. You can use Sury without ppx.
npm install sury sury-ppx
Then update your rescript.json config:
{
...
+ "bs-dependencies": ["sury"],
+ "ppx-flags": ["sury-ppx/bin"],
}
// 1. Define a type and add @schema attribute
@schema
type rating =
| @as("G") GeneralAudiences
| @as("PG") ParentalGuidanceSuggested
| @as("PG13") ParentalStronglyCautioned
| @as("R") Restricted
@schema
type film = {
@as("Id")
id: float,
@as("Title")
title: string,
@as("Tags")
tags: @s.default([]) array<string>,
@as("Rating")
rating: rating,
@as("Age")
deprecatedAgeRestriction: @s.deprecated("Use rating instead") option<int>,
}
// 2. Generated by PPX ⬇️
let ratingSchema = S.union([
S.literal(GeneralAudiences),
S.literal(ParentalGuidanceSuggested),
S.literal(ParentalStronglyCautioned),
S.literal(Restricted),
])
let filmSchema = S.object(s => {
id: s.field("Id", S.float),
title: s.field("Title", S.string),
tags: s.fieldOr("Tags", S.array(S.string), []),
rating: s.field("Rating", ratingSchema),
deprecatedAgeRestriction: s.field("Age", S.option(S.int)->S.deprecated("Use rating instead")),
})
// 3. Parse data using the schema
// The data is validated and transformed to a convenient format
%raw(`{
"Id": 1,
"Title": "My first film",
"Rating": "R",
"Age": 17
}`)->S.parseOrThrow(filmSchema)
// Ok({
// id: 1.,
// title: "My first film",
// tags: [],
// rating: Restricted,
// deprecatedAgeRestriction: Some(17),
// })
// 4. Transform data back using the same schema
{
id: 2.,
tags: ["Loved"],
title: "Sad & sed",
rating: ParentalStronglyCautioned,
deprecatedAgeRestriction: None,
}->S.reverseConvertOrThrow(filmSchema)
// Ok(%raw(`{
// "Id": 2,
// "Title": "Sad & sed",
// "Rating": "PG13",
// "Tags": ["Loved"],
// "Age": undefined,
// }`))
// 5. Use schema as a building block for other tools
// For example, create a JSON schema and use it for OpenAPI generation
let filmJSONSchema = filmSchema->S.toJSONSchema
🧠 Read more about schema usage in the ReScript Schema for ReScript users documentation.
@schemaApplies to: type declarations, type signatures
Indicates that a schema should be generated for the given type.
@s.matches(S.t<'value>)Applies to: type expressions
Specifies custom schema for the type.
@schema
type t = @s.matches(S.string->S.url) string
// Generated by PPX ⬇️
let schema = S.string->S.url
@s.nullApplies 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.nullableApplies to: option type expressions
Tells to use S.nullableAsOption for the option schema constructor.
@schema
type t = @s.nullable option<string>
// Generated by PPX ⬇️
let schema = S.nullableAsOption(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 also be used together with @s.null:
@schema
type t = @s.null @s.default("Unknown") string
// Generated by PPX ⬇️
let schema = S.null(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.defaultit might be used together with@s.null
@s.meta(S.meta)Applies to: type expressions
Adds metadata to the generated schema.
@schema
type t = @s.meta({description: "A useful bit of text, if you know what to do with it."}) string
// Generated by PPX ⬇️
let schema = S.string->S.meta({description: "A useful bit of text, if you know what to do with it."}})
This can be useful for documenting, JSON Schema creation, etc.
schema->S.toJSONSchema
// {
// "type": "string",
// "description": "A useful bit of text, if you know what to do with it."
// }
Read more about S.meta in the Sury documentation.
There's also support for @s.noValidation, @s.strict, @s.strip, @s.deepStrict and @s.deepStrip attributes. Create a PR if you need more.
FAQs
⚙️ ReScript PPX to generate Sury schema from types
The npm package sury-ppx receives a total of 756 weekly downloads. As such, sury-ppx popularity was classified as not popular.
We found that sury-ppx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.