Patch Changes
-
#4019
9f5a6f7
Thanks @gcanti! - Add missingjsonSchema
annotations to the following filters:lowercased
capitalized
uncapitalized
uppercased
Before
import { JSONSchema, Schema } from "effect" const schema = Schema.Struct({ a: Schema.Uppercased }) console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* throws: Error: Missing annotation details: Generating a JSON Schema for this schema requires a "jsonSchema" annotation schema (Refinement): Uppercased */
After
import { JSONSchema, Schema } from "effect" const schema = Schema.Uppercased console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* Output: { "$ref": "#/$defs/Uppercased", "$schema": "http://json-schema.org/draft-07/schema#", "$defs": { "Uppercased": { "type": "string", "description": "an uppercase string", "title": "Uppercased", "pattern": "^[^a-z]*$" } } } */
-
#4111
22905cf
Thanks @gcanti! - JSONSchema: merge refinement fragments instead of just overwriting them.Before
import { JSONSchema, Schema } from "effect" export const schema = Schema.String.pipe( Schema.startsWith("a"), // <= overwritten! Schema.endsWith("c") ) console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "description": "a string ending with \"c\"", "pattern": "^.*c$" // <= overwritten! } */
After
import { JSONSchema, Schema } from "effect" export const schema = Schema.String.pipe( Schema.startsWith("a"), // <= preserved! Schema.endsWith("c") ) console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* { "type": "string", "description": "a string ending with \"c\"", "pattern": "^.*c$", "allOf": [ { "pattern": "^a" // <= preserved! } ], "$schema": "http://json-schema.org/draft-07/schema#" } */
-
#4019
9f5a6f7
Thanks @gcanti! - JSONSchema: Correct the output order when generating a JSON Schema from a Union that includes literals and primitive schemas.Before
import { JSONSchema, Schema } from "effect" const schema = Schema.Union(Schema.Literal(1, 2), Schema.String) console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "anyOf": [ { "type": "string" }, { "enum": [ 1, 2 ] } ] } */
After
import { JSONSchema, Schema } from "effect" const schema = Schema.Union(Schema.Literal(1, 2), Schema.String) console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "anyOf": [ { "enum": [ 1, 2 ] }, { "type": "string" } ] } */
-
#4107
1e59e4f
Thanks @tim-smart! - remove FnEffect type to improve return type of Effect.fn -
#4108
8d914e5
Thanks @gcanti! - JSONSchema: representnever
as{"not":{}}
Before
import { JSONSchema, Schema } from "effect" const schema = Schema.Never console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* throws: Error: Missing annotation details: Generating a JSON Schema for this schema requires a "jsonSchema" annotation schema (NeverKeyword): never */
After
import { JSONSchema, Schema } from "effect" const schema = Schema.Never console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* { "$id": "/schemas/never", "not": {}, "title": "never", "$schema": "http://json-schema.org/draft-07/schema#" } */
-
#4115
03bb00f
Thanks @tim-smart! - avoid using non-namespaced "async" internally -
#4019
9f5a6f7
Thanks @gcanti! - JSONSchema: fix special case inparseJson
handling to target the "to" side of the transformation only at the top level.Before
import { JSONSchema, Schema } from "effect" const schema = Schema.parseJson( Schema.Struct({ a: Schema.parseJson( Schema.Struct({ b: Schema.String }) ) }) ) console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [ "a" ], "properties": { "a": { "type": "object", "required": [ "b" ], "properties": { "b": { "type": "string" } }, "additionalProperties": false } }, "additionalProperties": false } */
After
import { JSONSchema, Schema } from "effect" const schema = Schema.parseJson( Schema.Struct({ a: Schema.parseJson( Schema.Struct({ b: Schema.String }) ) }) ) console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* { "type": "object", "required": [ "a" ], "properties": { "a": { "type": "string", "contentMediaType": "application/json" } }, "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } */
-
#4101
14e1149
Thanks @gcanti! - Schema: align themake
constructor of structs with the behavior of the Class API constructors when all fields have a default.Before
import { Schema } from "effect" const schema = Schema.Struct({ a: Schema.propertySignature(Schema.Number).pipe( Schema.withConstructorDefault(() => 0) ) }) // TypeScript error: Expected 1-2 arguments, but got 0.ts(2554) console.log(schema.make())
After
import { Schema } from "effect" const schema = Schema.Struct({ a: Schema.propertySignature(Schema.Number).pipe( Schema.withConstructorDefault(() => 0) ) }) console.log(schema.make()) // Output: { a: 0 }
-
#4019
9f5a6f7
Thanks @gcanti! - JSONSchema: Fix issue whereidentifier
is ignored when a refinement is applied to a schema, closes #4012Before
import { JSONSchema, Schema } from "effect" const schema = Schema.NonEmptyString console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "description": "a non empty string", "title": "NonEmptyString", "minLength": 1 } */
After
import { JSONSchema, Schema } from "effect" const schema = Schema.NonEmptyString console.log(JSON.stringify(JSONSchema.make(schema), null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "$ref": "#/$defs/NonEmptyString", "$defs": { "NonEmptyString": { "type": "string", "description": "a non empty string", "title": "NonEmptyString", "minLength": 1 } } } */
-
#4019
9f5a6f7
Thanks @gcanti! - JSONSchema: Use identifier with Class APIs to create a$ref
instead of inlining the schema.Before
import { JSONSchema, Schema } from "effect" class A extends Schema.Class<A>("A")({ a: Schema.String }) {} console.log(JSON.stringify(JSONSchema.make(A), null, 2)) /* { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [ "a" ], "properties": { "a": { "type": "string" } }, "additionalProperties": false } */
After
import { JSONSchema, Schema } from "effect" class A extends Schema.Class<A>("A")({ a: Schema.String }) {} console.log(JSON.stringify(JSONSchema.make(A), null, 2)) /* { "$ref": "#/$defs/A", "$schema": "http://json-schema.org/draft-07/schema#", "$defs": { "A": { "type": "object", "required": [ "a" ], "properties": { "a": { "type": "string" } }, "additionalProperties": false } } } */