Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-jokes-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform": patch
---

Fix HttpApi discarding annotations from Union and Literal schemas
16 changes: 7 additions & 9 deletions packages/platform/src/HttpApiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,16 @@ export const getStatusError = <A extends Schema.Schema.All>(self: A): number =>
* @internal
*/
export const extractUnionTypes = (ast: AST.AST): ReadonlyArray<AST.AST> => {
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<AST.AST> = []
process(ast)
return out
}

/** @internal */
Expand Down
34 changes: 34 additions & 0 deletions packages/platform/test/OpenApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
Loading