diff --git a/packages/effect/src/Schema.ts b/packages/effect/src/Schema.ts index 5eecb17fbfb..cbebc763502 100644 --- a/packages/effect/src/Schema.ts +++ b/packages/effect/src/Schema.ts @@ -2993,8 +2993,6 @@ export const brand = ( const ast = AST.annotations( self.ast, toASTAnnotations({ - title: `${String(self.ast)} & Brand<${util_.formatUnknown(brand)}>`, - description: `${String(self.ast)} & Brand<${util_.formatUnknown(brand)}>`, [AST.BrandAnnotationId]: annotation, ...annotations }) diff --git a/packages/effect/src/SchemaAST.ts b/packages/effect/src/SchemaAST.ts index b22b7b423de..d151fc33560 100644 --- a/packages/effect/src/SchemaAST.ts +++ b/packages/effect/src/SchemaAST.ts @@ -2925,10 +2925,21 @@ export const rename = (ast: AST, mapping: { readonly [K in PropertyKey]?: Proper const formatKeyword = (ast: AST): string => Option.getOrElse(getExpected(ast), () => ast._tag) +function getBrands(ast: Annotated): string { + return Option.match(getBrandAnnotation(ast), { + onNone: () => "", + onSome: (brands) => brands.map((brand) => ` & Brand<${util_.formatUnknown(brand)}>`).join("") + }) +} + const getExpected = (ast: Annotated): Option.Option => { return getIdentifierAnnotation(ast).pipe( - Option.orElse(() => getTitleAnnotation(ast)), - Option.orElse(() => getDescriptionAnnotation(ast)), - Option.orElse(() => getAutoTitleAnnotation(ast)) + Option.orElse(() => + getTitleAnnotation(ast).pipe( + Option.orElse(() => getDescriptionAnnotation(ast)), + Option.orElse(() => getAutoTitleAnnotation(ast)), + Option.map((s) => s + getBrands(ast)) + ) + ) ) } diff --git a/packages/effect/test/Schema/Schema/brand.test.ts b/packages/effect/test/Schema/Schema/brand.test.ts index 8ea11fed93a..7a88f949309 100644 --- a/packages/effect/test/Schema/Schema/brand.test.ts +++ b/packages/effect/test/Schema/Schema/brand.test.ts @@ -23,12 +23,6 @@ describe("brand", () => { }) describe("annotations", () => { - it("toString / format", () => { - const schema = S.Number.pipe(S.brand("A")) - expect(String(schema)).toBe(`number & Brand<"A">`) - expect(S.format(schema)).toBe(`number & Brand<"A">`) - }) - it("using .annotations() twice", () => { const schema = S.Number.pipe(S.brand("A")) const annotatedSchema = schema.annotations({ @@ -56,15 +50,15 @@ describe("brand", () => { const schema = S.Number.pipe( S.int(), S.brand("A", { - description: "an A brand" + description: "description" }) ) + expect(String(schema)).toBe(`description & Brand<"A">`) expect(schema.ast.annotations).toEqual({ [AST.SchemaIdAnnotationId]: S.IntSchemaId, [AST.BrandAnnotationId]: ["A"], - [AST.TitleAnnotationId]: `an integer & Brand<"A">`, - [AST.DescriptionAnnotationId]: "an A brand", + [AST.DescriptionAnnotationId]: "description", [AST.JSONSchemaAnnotationId]: { type: "integer" } }) }) @@ -74,15 +68,16 @@ describe("brand", () => { S.int(), S.brand("A"), S.brand("B", { - description: "a B brand" + description: "description" }) ) + expect(String(schema)).toBe(`description & Brand<"A"> & Brand<"B">`) + expect(schema.ast.annotations).toEqual({ [AST.SchemaIdAnnotationId]: S.IntSchemaId, [AST.BrandAnnotationId]: ["A", "B"], - [AST.TitleAnnotationId]: `an integer & Brand<"A"> & Brand<"B">`, - [AST.DescriptionAnnotationId]: "a B brand", + [AST.DescriptionAnnotationId]: "description", [AST.JSONSchemaAnnotationId]: { type: "integer" } }) }) @@ -94,14 +89,16 @@ describe("brand", () => { S.int(), S.brand(A), S.brand(B, { - description: "a B brand" + description: "description" }) ) + + expect(String(schema)).toBe("description & Brand & Brand") + expect(schema.ast.annotations).toEqual({ [AST.SchemaIdAnnotationId]: S.IntSchemaId, [AST.BrandAnnotationId]: [A, B], - [AST.TitleAnnotationId]: "an integer & Brand & Brand", - [AST.DescriptionAnnotationId]: "a B brand", + [AST.DescriptionAnnotationId]: "description", [AST.JSONSchemaAnnotationId]: { type: "integer" } }) })