-
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSONSchema: merge refinement fragments instead of just overwriting th…
…em (#4111)
- Loading branch information
Showing
10 changed files
with
554 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
"@effect/platform": patch | ||
"effect": patch | ||
--- | ||
|
||
JSONSchema: merge refinement fragments instead of just overwriting them. | ||
|
||
Before | ||
|
||
```ts | ||
import { JSONSchema, Schema } from "effect" | ||
|
||
export const schema = Schema.String.pipe( | ||
Schema.startsWith("a"), // <= overwritten! | ||
Schema.endsWith("c") | ||
) | ||
|
||
console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) | ||
/* | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "string", | ||
"description": "a string ending with \"c\"", | ||
"pattern": "^.*c$" // <= overwritten! | ||
} | ||
*/ | ||
``` | ||
|
||
After | ||
|
||
```ts | ||
import { JSONSchema, Schema } from "effect" | ||
|
||
export const schema = Schema.String.pipe( | ||
Schema.startsWith("a"), // <= preserved! | ||
Schema.endsWith("c") | ||
) | ||
|
||
console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) | ||
/* | ||
{ | ||
"type": "string", | ||
"description": "a string ending with \"c\"", | ||
"pattern": "^.*c$", | ||
"allOf": [ | ||
{ | ||
"pattern": "^a" // <= preserved! | ||
} | ||
], | ||
"$schema": "http://json-schema.org/draft-07/schema#" | ||
} | ||
*/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.