-
-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Correct Handling of JSON Schema Annotations in Refinements #3284
Merged
Conversation
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
🦋 Changeset detectedLatest commit: 8f12f16 The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Merged
suddenlyGiovanni
added a commit
to suddenlyGiovanni/resume
that referenced
this pull request
Sep 3, 2024
- [#3287](Effect-TS/effect#3287) [`f0285d3`](Effect-TS/effect@f0285d3) Thanks @gcanti! - JSON Schema: change default behavior for property signatures containing `undefined` Changed the default behavior when encountering a required property signature whose type contains `undefined`. Instead of raising an exception, `undefined` is now pruned and **the field is set as optional**. Before ```ts import { JSONSchema, Schema } from "@effect/schema" const schema = Schema.Struct({ a: Schema.NullishOr(Schema.Number) }) const jsonSchema = JSONSchema.make(schema) console.log(JSON.stringify(jsonSchema, null, 2)) /* throws Error: Missing annotation at path: ["a"] details: Generating a JSON Schema for this schema requires a "jsonSchema" annotation schema (UndefinedKeyword): undefined */ ``` Now ```ts import { JSONSchema, Schema } from "@effect/schema" const schema = Schema.Struct({ a: Schema.NullishOr(Schema.Number) }) const jsonSchema = JSONSchema.make(schema) console.log(JSON.stringify(jsonSchema, null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [], // <=== empty "properties": { "a": { "anyOf": [ { "type": "number" }, { "$ref": "#/$defs/null" } ] } }, "additionalProperties": false, "$defs": { "null": { "const": null } } } */ ``` - [#3291](Effect-TS/effect#3291) [`8ec4955`](Effect-TS/effect@8ec4955) Thanks @gcanti! - remove type-level error message from `optional` signature, closes #3290 This fix eliminates the type-level error message from the `optional` function signature, which was causing issues in generic contexts. - [#3284](Effect-TS/effect#3284) [`3ac2d76`](Effect-TS/effect@3ac2d76) Thanks @gcanti! - Fix: Correct Handling of JSON Schema Annotations in Refinements Fixes an issue where the JSON schema annotation set by a refinement after a transformation was mistakenly interpreted as an override annotation. This caused the output to be incorrect, as the annotations were not applied as intended. Before ```ts import { JSONSchema, Schema } from "@effect/schema" const schema = Schema.Trim.pipe(Schema.nonEmpty()) const jsonSchema = JSONSchema.make(schema) console.log(JSON.stringify(jsonSchema, null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "minLength": 1 } */ ``` Now ```ts import { JSONSchema, Schema } from "@effect/schema" const schema = Schema.Trim.pipe(Schema.nonEmpty()) const jsonSchema = JSONSchema.make(schema) console.log(JSON.stringify(jsonSchema, null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "type": "string" } */ ``` - Updated dependencies [[`cc327a1`](Effect-TS/effect@cc327a1), [`4bfe4fb`](Effect-TS/effect@4bfe4fb), [`2b14d18`](Effect-TS/effect@2b14d18)]: - effect@3.5.6 Signed-off-by: Giovanni Ravalico <15946771+suddenlyGiovanni@users.noreply.github.com>
suddenlyGiovanni
added a commit
to suddenlyGiovanni/resume
that referenced
this pull request
Sep 3, 2024
- [#3287](Effect-TS/effect#3287) [`f0285d3`](Effect-TS/effect@f0285d3) - JSON Schema: change default behavior for property signatures containing `undefined` Changed the default behavior when encountering a required property signature whose type contains `undefined`. Instead of raising an exception, `undefined` is now pruned and **the field is set as optional**. Before ```ts import { JSONSchema, Schema } from "@effect/schema" const schema = Schema.Struct({ a: Schema.NullishOr(Schema.Number) }) const jsonSchema = JSONSchema.make(schema) console.log(JSON.stringify(jsonSchema, null, 2)) /* throws Error: Missing annotation at path: ["a"] details: Generating a JSON Schema for this schema requires a "jsonSchema" annotation schema (UndefinedKeyword): undefined */ ``` Now ```ts import { JSONSchema, Schema } from "@effect/schema" const schema = Schema.Struct({ a: Schema.NullishOr(Schema.Number) }) const jsonSchema = JSONSchema.make(schema) console.log(JSON.stringify(jsonSchema, null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [], // <=== empty "properties": { "a": { "anyOf": [ { "type": "number" }, { "$ref": "#/$defs/null" } ] } }, "additionalProperties": false, "$defs": { "null": { "const": null } } } */ ``` - [#3291](Effect-TS/effect#3291) [`8ec4955`](Effect-TS/effect@8ec4955) - remove type-level error message from `optional` signature, closes #3290 This fix eliminates the type-level error message from the `optional` function signature, which was causing issues in generic contexts. - [#3284](Effect-TS/effect#3284) [`3ac2d76`](Effect-TS/effect@3ac2d76) - Fix: Correct Handling of JSON Schema Annotations in Refinements Fixes an issue where the JSON schema annotation set by a refinement after a transformation was mistakenly interpreted as an override annotation. This caused the output to be incorrect, as the annotations were not applied as intended. Before ```ts import { JSONSchema, Schema } from "@effect/schema" const schema = Schema.Trim.pipe(Schema.nonEmpty()) const jsonSchema = JSONSchema.make(schema) console.log(JSON.stringify(jsonSchema, null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "minLength": 1 } */ ``` Now ```ts import { JSONSchema, Schema } from "@effect/schema" const schema = Schema.Trim.pipe(Schema.nonEmpty()) const jsonSchema = JSONSchema.make(schema) console.log(JSON.stringify(jsonSchema, null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "type": "string" } */ ``` - Updated dependencies [[`cc327a1`](Effect-TS/effect@cc327a1), [`4bfe4fb`](Effect-TS/effect@4bfe4fb), [`2b14d18`](Effect-TS/effect@2b14d18)]: - effect@3.5.6 Signed-off-by: Giovanni Ravalico <15946771+suddenlyGiovanni@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes an issue where the JSON schema annotation set by a refinement after a transformation was mistakenly interpreted as an override annotation. This caused the output to be incorrect, as the annotations were not applied as intended.
Before
Now