effect@3.14.2
·
934 commits
to main
since this release
Patch Changes
-
#4646
f87991bThanks @gcanti! - SchemaAST: add missinggetSchemaIdAnnotationAPI -
#4646
f87991bThanks @gcanti! - Arbitrary: fix bug where annotations were ignored.Before
import { Arbitrary, Schema } from "effect" const schema = Schema.Int.annotations({ arbitrary: (_, ctx) => (fc) => { console.log("context: ", ctx) return fc.integer() } }).pipe(Schema.greaterThan(0), Schema.lessThan(10)) Arbitrary.make(schema) // No output ❌
After
import { Arbitrary, Schema } from "effect" const schema = Schema.Int.annotations({ arbitrary: (_, ctx) => (fc) => { console.log("context: ", ctx) return fc.integer() } }).pipe(Schema.greaterThan(0), Schema.lessThan(10)) Arbitrary.make(schema) /* context: { maxDepth: 2, constraints: { _tag: 'NumberConstraints', constraints: { min: 0, minExcluded: true, max: 10, maxExcluded: true }, isInteger: true } } */
-
#4648
0a3e3e1Thanks @gcanti! - Schema:standardSchemaV1now includes the schema, closes #4494.This update fixes an issue where passing
Schema.standardSchemaV1(...)directly toJSONSchema.makewould throw aTypeError. The schema was missing from the returned object, causing the JSON schema generation to fail.Now
standardSchemaV1includes the schema itself, so it can be used withJSONSchema.makewithout issues.Example
import { JSONSchema, Schema } from "effect" const Person = Schema.Struct({ name: Schema.optionalWith(Schema.NonEmptyString, { exact: true }) }) const standardSchema = Schema.standardSchemaV1(Person) console.log(JSONSchema.make(standardSchema)) /* { '$schema': 'http://json-schema.org/draft-07/schema#', '$defs': { NonEmptyString: { type: 'string', description: 'a non empty string', title: 'nonEmptyString', minLength: 1 } }, type: 'object', required: [], properties: { name: { '$ref': '#/$defs/NonEmptyString' } }, additionalProperties: false } */