diff --git a/.changeset/fluffy-jokes-repair.md b/.changeset/fluffy-jokes-repair.md new file mode 100644 index 00000000000..c07db41ac3d --- /dev/null +++ b/.changeset/fluffy-jokes-repair.md @@ -0,0 +1,5 @@ +--- +"@effect/platform": patch +--- + +Fix HttpApi discarding annotations from Union and Literal schemas diff --git a/packages/platform/src/HttpApiSchema.ts b/packages/platform/src/HttpApiSchema.ts index 5001e3d045f..64d3df752fb 100644 --- a/packages/platform/src/HttpApiSchema.ts +++ b/packages/platform/src/HttpApiSchema.ts @@ -221,18 +221,16 @@ export const getStatusError = (self: A): number => * @internal */ export const extractUnionTypes = (ast: AST.AST): ReadonlyArray => { - function process(ast: AST.AST): void { - if (AST.isUnion(ast)) { - for (const type of ast.types) { - process(type) - } + if (AST.isUnion(ast)) { + const types = ast.types.flatMap((type) => extractUnionTypes(type)) + if (Reflect.ownKeys(ast.annotations).length === 0) { + return types } else { - out.push(ast) + return [AST.Union.make(types, ast.annotations)] } + } else { + return [ast] } - const out: Array = [] - process(ast) - return out } /** @internal */ diff --git a/packages/platform/test/OpenApi.test.ts b/packages/platform/test/OpenApi.test.ts index a067798a7b4..31001394de5 100644 --- a/packages/platform/test/OpenApi.test.ts +++ b/packages/platform/test/OpenApi.test.ts @@ -938,6 +938,40 @@ describe("OpenApi", () => { } }) }) + + it("Schema.Literal annotations", () => { + const api = HttpApi.make("Api").add( + HttpApiGroup.make("group").add( + HttpApiEndpoint.get("endpoint")`/` + .addSuccess(Schema.Literal("a", "b").annotations({ title: "Letter" })) + ) + ) + expectSpecPaths(api, { + "/": { + "get": { + "tags": ["group"], + "operationId": "group.endpoint", + "parameters": [], + "security": [], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "string", + "enum": ["a", "b"], + "title": "Letter" + } + } + } + }, + "400": HttpApiDecodeError + } + } + } + }) + }) }) describe("addSuccess + withEncoding", () => {