Skip to content

Commit

Permalink
chore(package): update @effect/schema to 0.68.26
Browse files Browse the repository at this point in the history
- [#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)]:
  - [email protected]

Signed-off-by: Giovanni Ravalico <[email protected]>
  • Loading branch information
suddenlyGiovanni committed Sep 3, 2024
1 parent b963073 commit a264183
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-pears-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@suddenlygiovanni/resume": patch
---

update `@effect/schema` package to v0.68.26
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@
},
"license": "UNLICENSED",
"peerDependencies": {
"@effect/schema": "~0.68.25"
"@effect/schema": "~0.68.26"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@changesets/cli": "2.27.7",
"@effect/schema": "0.68.25",
"@effect/schema": "0.68.26",
"@std/yaml": "npm:@jsr/[email protected]",
"@tsconfig/node21": "21.0.3",
"@tsconfig/strictest": "2.0.5",
"@types/json-schema": "7.0.15",
"@types/node": "22.5.2",
"@vitest/coverage-v8": "2.0.5",
"@vitest/ui": "2.0.5",
"effect": "3.5.5",
"effect": "3.5.6",
"typescript": "5.6.1-rc",
"vite-tsconfig-paths": "5.0.1",
"vitest": "2.0.5"
Expand Down
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ISODateString', () => {
expect(serializedJsonSchema).toMatchInlineSnapshot(`
"{
"$schema": "http://json-schema.org/draft-07/schema#",
"pattern": "^[0-9]{4}-((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01])|(0[469]|11)-(0[1-9]|[12][0-9]|30)|(02)-(0[1-9]|[12][0-9]))T(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9])\\\\.[0-9]{3}Z$"
"type": "string"
}"
`)
})
Expand Down
25 changes: 23 additions & 2 deletions src/schema-primitive/non-empty-string/non-empty-string.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ describe('nonEmptyString', () => {
expect(JSON.stringify(JSONSchema.make(NonEmptyString), null, '\t')).toMatchInlineSnapshot(`
"{
"$schema": "http://json-schema.org/draft-07/schema#",
"minLength": 1
"$ref": "#/$defs/NonEmptyString",
"$defs": {
"NonEmptyString": {
"type": "string",
"description": "a non empty string",
"title": "non empty string",
"examples": [
"' test string '",
"'test string'"
]
}
}
}"
`)

Expand All @@ -55,7 +66,17 @@ describe('nonEmptyString', () => {
).toMatchInlineSnapshot(`
"{
"$schema": "http://json-schema.org/draft-07/schema#",
"minLength": 1
"$ref": "#/$defs/NonEmptyString",
"$defs": {
"NonEmptyString": {
"type": "string",
"description": "DESCRIPTION",
"title": "TITLE",
"examples": [
"EXAMPLES"
]
}
}
}"
`)
})
Expand Down

0 comments on commit a264183

Please sign in to comment.