Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
58814bc
Refactor SchemaRepresentation
gcanti Jul 16, 2026
a12b9c6
test(schema): reorganize representation tests
gcanti Jul 16, 2026
4fefb75
remove typeConstructor annotation
gcanti Jul 16, 2026
d21dbd9
chore
gcanti Jul 16, 2026
6c235e8
remove generation annotation
gcanti Jul 16, 2026
a7f2a9d
rename SchemaRepresentation artifact generation to code
gcanti Jul 16, 2026
43bc115
simplify schema representation internals
gcanti Jul 16, 2026
5ad7379
simplify schema representation persistence
gcanti Jul 17, 2026
4e38827
chore
gcanti Jul 17, 2026
a6c5e08
split schema representation internals
gcanti Jul 17, 2026
44f84ec
simplify schema representation lowering
gcanti Jul 17, 2026
9f4b69a
simplify JSON Schema representation compiler
gcanti Jul 17, 2026
c70089e
simplify JSON Schema representation importer
gcanti Jul 17, 2026
4bc3d39
simplify schema code document compiler
gcanti Jul 17, 2026
dba6955
split schema representation JSON codec
gcanti Jul 17, 2026
c670ef2
simplify schema representation JSON codecs
gcanti Jul 17, 2026
3674a0d
improve representationJson
gcanti Jul 17, 2026
f6277f5
fix fromRepresentation
gcanti Jul 17, 2026
70924e5
fix(SchemaRepresentation): preserve identifiers in generated code
gcanti Jul 18, 2026
bb938a0
centralize excluded annotations
gcanti Jul 18, 2026
ee6b6b0
refactor(Schema): simplify declaration representations
gcanti Jul 18, 2026
9223bc3
Treat contentSchema as a JSON Schema annotation
gcanti Jul 18, 2026
1283814
Remove derived JSON string identifiers
gcanti Jul 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/schema-representation-refactoring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"effect": patch
---

Refactor the `SchemaRepresentation` module to improve clarity and maintainability.

Add constructors for declaration, filter, and filter group revivers that infer their payload type from `payloadSchema`.
2 changes: 1 addition & 1 deletion migration/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ v4
```ts
import { Schema, SchemaRepresentation } from "effect"

const doc = SchemaRepresentation.fromAST(Schema.String.ast)
const doc = SchemaRepresentation.toRepresentation(Schema.String.ast)
const multi = SchemaRepresentation.toMultiDocument(doc)
const codeDoc = SchemaRepresentation.toCodeDocument(multi)
console.log(codeDoc.codes[0].Type)
Expand Down
28 changes: 14 additions & 14 deletions packages/effect/SCHEMA.md
Original file line number Diff line number Diff line change
Expand Up @@ -6150,26 +6150,26 @@ Use it when you need to:

At a high level:

- `fromAST` / `fromASTs` turn a schema AST into a `Document` / `MultiDocument`
- `DocumentFromJson` (schema) round-trip that document through JSON
- `toSchema` rebuilds a runtime `Schema` from the stored representation
- `toRepresentation` / `toRepresentations` turn a schema AST into a `Document` / `MultiDocument`
- `toJson` / `fromJson` round-trip that document through JSON
- `fromRepresentation` rebuilds a runtime `Schema` from the stored representation
- `toJsonSchemaDocument` produces a Draft 2020-12 JSON Schema document
- `toCodeDocument` prepares data for code generation (via `toMultiDocument`)

```mermaid
flowchart TD
S[Schema] -->|fromAST|D{"SchemaRepresentation.Document"}
S -->|fromASTs|MD{"SchemaRepresentation.MultiDocument"}
S[Schema] -->|toRepresentation|D{"SchemaRepresentation.Document"}
S -->|toRepresentations|MD{"SchemaRepresentation.MultiDocument"}
JS["JSON Schema (draft-07, draft-2020-12, openapi-3.0, openapi-3.1)"] -->JSD
JD --> JS
JD["JsonSchema.Document"] -->|fromJsonSchemaDocument|D
D <--> |"DocumentFromJson (schema)"|JSON
D <--> |"toJson / fromJson"|JSON
D --> |toJsonSchemaDocument|JD
D --> |toSchema|S
D --> |fromRepresentation|S
MD --> |toCodeDocument|CodeDocument["CodeDocument"]
D --> |toMultiDocument|MD
MD --> |toJsonSchemaMultiDocument|JMD[JsonSchema.MultiDocument]
MD <--> |"MultiDocumentFromJson (schema)"|JSON
MD <--> |"toJsonMultiDocument / fromJsonMultiDocument"|JSON
```

## The data model
Expand Down Expand Up @@ -6211,7 +6211,7 @@ Schemas that rely on transformations cannot be round-tripped, including:
- `Schema.encodeTo(...)`
- custom codecs or any schema that changes how values are encoded/decoded

If you serialize a transformed schema, the transformation logic will be lost. When you rebuild it with `toSchema`, you will only get the structural schema.
If you serialize a transformed schema, the transformation logic will be lost. When you rebuild it with `fromRepresentation`, you will only get the structural schema.

> **Aside** (Why transformations are excluded)
>
Expand Down Expand Up @@ -6245,15 +6245,15 @@ In practice, documentation annotations like `title` and `description` are preser

Some runtime schemas are represented as `Declaration` nodes. Rebuilding them requires a "reviver" function.

`toSchema` ships with a default reviver (`toSchemaDefaultReviver`) that recognizes a fixed set of constructors, including:
`fromRepresentation` ships with a default reviver (`toSchemaDefaultReviver`) that recognizes a fixed set of constructors, including:

- `effect/Option`, `effect/Result`, `effect/Exit`, ...
- `ReadonlyMap`, `ReadonlySet`
- `RegExp`, `URL`, `Date`
- `FormData`, `URLSearchParams`, `Uint8Array`
- `DateTime.Utc`, `effect/Duration`

If your document contains other declarations, pass a custom `reviver` to `toSchema`.
If your document contains other declarations, pass a custom `reviver` to `fromRepresentation`.

## JSON round-tripping

Expand All @@ -6266,9 +6266,9 @@ Internally, these functions use a canonical JSON codec for `Document$`. This is

## Rebuilding runtime schemas

### `toSchema`
### `fromRepresentation`

`toSchema(document)` walks the representation tree and recreates a runtime schema.
`fromRepresentation(document)` walks the representation tree and recreates a runtime schema.

What it does:

Expand All @@ -6281,7 +6281,7 @@ What it does:
If you need custom handling for declarations:

```ts
SchemaRepresentation.toSchema(document, {
SchemaRepresentation.fromRepresentation(document, {
reviver: (declaration, recur) => {
// Return a runtime schema to override how a Declaration is rebuilt.
// Return undefined to fall back to the default behavior.
Expand Down
Loading
Loading