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

latest releases: @effect/typeclass@0.24.40, @effect/printer@0.33.40, @effect/printer-ansi@0.33.40...
10 days ago

Patch Changes

  • #3087 d71c192 Thanks @gcanti! - Special case S.parseJson to generate JSON Schemas by targeting the "to" side of transformations, closes #3086

    Resolved an issue where JSONSchema.make improperly generated JSON Schemas for schemas defined with S.parseJson(<real schema>). Previously, invoking JSONSchema.make on these transformed schemas produced a JSON Schema corresponding to a string type rather than the underlying real schema.

    Before

    import { JSONSchema, Schema } from "@effect/schema";
    
    // Define a schema that parses a JSON string into a structured object
    const schema = Schema.parseJson(
      Schema.Struct({
        a: Schema.parseJson(Schema.NumberFromString), // Nested parsing from JSON string to number
      }),
    );
    
    console.log(JSONSchema.make(schema));
    /*
    {
      '$schema': 'http://json-schema.org/draft-07/schema#',
      '$ref': '#/$defs/JsonString',
      '$defs': {
        JsonString: {
          type: 'string',
          description: 'a JSON string',
          title: 'JsonString'
        }
      }
    }
    */

    Now

    import { JSONSchema, Schema } from "@effect/schema";
    
    // Define a schema that parses a JSON string into a structured object
    const schema = Schema.parseJson(
      Schema.Struct({
        a: Schema.parseJson(Schema.NumberFromString), // Nested parsing from JSON string to number
      }),
    );
    
    console.log(JSONSchema.make(schema));
    /*
    {
      '$schema': 'http://json-schema.org/draft-07/schema#',
      type: 'object',
      required: [ 'a' ],
      properties: { a: { type: 'string', description: 'a string', title: 'string' } },
      additionalProperties: false
    }
    */
  • Updated dependencies [72638e3, d7dde2b, 9b2fc3b]:

    • effect@3.4.4

Don't miss a new effect release

NewReleases is sending notifications on new releases.