github Effect-TS/effect @effect/schema@0.68.26

latest releases: @effect/sql-sqlite-wasm@0.20.4, @effect/typeclass@0.29.13, @effect/vitest@0.13.13...
3 months ago

Patch Changes

  • #3287 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

    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

    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 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 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

    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

    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, 4bfe4fb, 2b14d18]:

    • effect@3.5.6

Don't miss a new effect release

NewReleases is sending notifications on new releases.