Skip to content

Commit ac0c35b

Browse files
authored
remove Rewriter module (#1271)
1 parent a512054 commit ac0c35b

File tree

5 files changed

+0
-804
lines changed

5 files changed

+0
-804
lines changed

packages/effect/SCHEMA.md

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4732,75 +4732,6 @@ console.log(JSON.stringify(document, null, 2))
47324732
*/
47334733
```
47344734
4735-
#### Rewriters
4736-
4737-
Sometimes you need to adapt a schema to a different target format. For example, you might convert a JSON Schema to the subset supported by OpenAI (https://platform.openai.com/docs/guides/structured-outputs/supported-schemas?type-restrictions=string-restrictions#supported-schemas).
4738-
4739-
Note: the more context that an LLM has, the more "correct" the structured output will be, so it's advised to pass the `generateDescriptions: true` option to `toJsonSchemaDocument` APIs.
4740-
4741-
**Example** (Convert to an OpenAI-compatible schema)
4742-
4743-
```ts
4744-
import { Schema } from "effect"
4745-
import { Rewriter } from "effect/unstable/jsonschema"
4746-
4747-
// Define a schema with an optional non-empty string field 'a'
4748-
const schema = Schema.Struct({
4749-
a: Schema.optionalKey(Schema.NonEmptyString)
4750-
})
4751-
4752-
const document = Schema.toJsonSchemaDocument(schema, {
4753-
generateDescriptions: true
4754-
})
4755-
4756-
console.log(JSON.stringify(document.schema, null, 2))
4757-
/*
4758-
Output (before rewrite):
4759-
{
4760-
"type": "object",
4761-
"properties": {
4762-
"a": {
4763-
"type": "string",
4764-
"allOf": [
4765-
{
4766-
"minLength": 1,
4767-
"description": "a value with a length of at least 1"
4768-
}
4769-
]
4770-
}
4771-
},
4772-
"additionalProperties": false
4773-
}
4774-
*/
4775-
4776-
// Rewrite to the OpenAI subset:
4777-
// - Make all fields required
4778-
// - Represent optionality by unioning with null (T | null)
4779-
// - Drop unsupported keywords like minLength
4780-
const rewritten = Rewriter.openAi(document)
4781-
4782-
console.log(JSON.stringify(rewritten.schema, null, 2))
4783-
/*
4784-
Output:
4785-
{
4786-
"type": "object",
4787-
"properties": {
4788-
"a": {
4789-
"type": [
4790-
"string",
4791-
"null"
4792-
],
4793-
"description": "a value with a length of at least 1"
4794-
}
4795-
},
4796-
"additionalProperties": false,
4797-
"required": [
4798-
"a"
4799-
]
4800-
}
4801-
*/
4802-
```
4803-
48044735
### Generating an Arbitrary from a Schema
48054736
48064737
Property-based testing checks your code against many randomly generated inputs. An Arbitrary is a generator that produces random values matching your schema. Schema can derive an Arbitrary automatically, so you do not need to write generators by hand.

packages/effect/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"./unstable/eventlog": "./src/unstable/eventlog/index.ts",
3939
"./unstable/http": "./src/unstable/http/index.ts",
4040
"./unstable/httpapi": "./src/unstable/httpapi/index.ts",
41-
"./unstable/jsonschema": "./src/unstable/jsonschema/index.ts",
4241
"./unstable/observability": "./src/unstable/observability/index.ts",
4342
"./unstable/persistence": "./src/unstable/persistence/index.ts",
4443
"./unstable/process": "./src/unstable/process/index.ts",

packages/effect/src/unstable/jsonschema/Rewriter.ts

Lines changed: 0 additions & 198 deletions
This file was deleted.

packages/effect/src/unstable/jsonschema/index.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)