Skip to content

effect@3.18.3

Choose a tag to compare

@github-actions github-actions released this 06 Oct 08:22
· 5266 commits to main since this release
c8fef45

Patch Changes

  • #5612 25fab81 Thanks @gcanti! - Fix JSON Schema generation with topLevelReferenceStrategy: "skip", closes #5611

    This patch fixes a bug that occurred when generating JSON Schemas with nested schemas that had identifiers, while using topLevelReferenceStrategy: "skip".

    Previously, the generator would still output $ref entries even though references were supposed to be skipped, leaving unresolved definitions.

    Before

    import { JSONSchema, Schema } from "effect"
    
    const A = Schema.Struct({ value: Schema.String }).annotations({
      identifier: "A"
    })
    const B = Schema.Struct({ a: A }).annotations({ identifier: "B" })
    
    const definitions = {}
    console.log(
      JSON.stringify(
        JSONSchema.fromAST(B.ast, {
          definitions,
          topLevelReferenceStrategy: "skip"
        }),
        null,
        2
      )
    )
    /*
    {
      "type": "object",
      "required": ["a"],
      "properties": {
        "a": {
          "$ref": "#/$defs/A"
        }
      },
      "additionalProperties": false
    }
    */
    console.log(definitions)
    /*
    {
      A: {
        type: "object",
        required: ["value"],
        properties: { value: [Object] },
        additionalProperties: false
      }
    }
    */

    After

    import { JSONSchema, Schema } from "effect"
    
    const A = Schema.Struct({ value: Schema.String }).annotations({
      identifier: "A"
    })
    const B = Schema.Struct({ a: A }).annotations({ identifier: "B" })
    
    const definitions = {}
    console.log(
      JSON.stringify(
        JSONSchema.fromAST(B.ast, {
          definitions,
          topLevelReferenceStrategy: "skip"
        }),
        null,
        2
      )
    )
    /*
    {
      "type": "object",
      "required": ["a"],
      "properties": {
        "a": {
          "type": "object",
          "required": ["value"],
          "properties": {
            "value": { "type": "string" }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
    */
    console.log(definitions)
    /*
    {}
    */

    Now schemas are correctly inlined, and no leftover $ref entries or unused definitions remain.