diff --git a/content/src/content/docs/docs/schema/json-schema.mdx b/content/src/content/docs/docs/schema/json-schema.mdx index f516ecf02..f3500f2a5 100644 --- a/content/src/content/docs/docs/schema/json-schema.mdx +++ b/content/src/content/docs/docs/schema/json-schema.mdx @@ -6,6 +6,8 @@ sidebar: order: 16 --- +import { Aside } from "@astrojs/starlight/components" + The `JSONSchema.make` function allows you to generate a JSON Schema from a schema. **Example** (Creating a JSON Schema for a Struct) @@ -628,17 +630,24 @@ By using identifier annotations, schemas can be reused and referenced more easil Standard JSON Schema annotations such as `title`, `description`, `default`, and `examples` are supported. These annotations allow you to enrich your schemas with metadata that can enhance readability and provide additional information about the data structure. + + **Example** (Using Annotations for Metadata) ```ts twoslash import { JSONSchema, Schema } from "effect" -const schema = Schema.String.annotations({ - description: "my custom description", - title: "my custom title", - default: "", - examples: ["a", "b"] -}) +const schema = Schema.Trim.pipe( + Schema.annotations({ + description: "my custom description", + title: "my custom title", + default: "", + examples: ["a", " b", "c"] + }) +) const jsonSchema = JSONSchema.make(schema) @@ -646,15 +655,12 @@ console.log(JSON.stringify(jsonSchema, null, 2)) /* Output: { - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string", - "description": "my custom description", - "title": "my custom title", - "examples": [ - "a", - "b" - ], - "default": "" + '$schema': 'http://json-schema.org/draft-07/schema#', + type: 'string', + description: 'my custom description', + title: 'my custom title', + default: '', + examples: [ 'a', 'c' ] } */ ```