Skip to content
Merged
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/yellow-kids-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tim-smart/openapi-gen": patch
---

Support resolving nested response object references and empty responses
10 changes: 9 additions & 1 deletion src/OpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface ParsedOperation {
readonly pathTemplate: string
readonly successSchemas: ReadonlyMap<string, string>
readonly errorSchemas: ReadonlyMap<string, string>
readonly voidSchemas: ReadonlySet<string>
}

export const make = Effect.gen(function* () {
Expand Down Expand Up @@ -123,6 +124,7 @@ export const make = Effect.gen(function* () {
payloadFormData: false,
successSchemas: new Map(),
errorSchemas: new Map(),
voidSchemas: new Set(),
paramsOptional: true,
}
const schemaId = identifier(operation.operationId ?? path)
Expand Down Expand Up @@ -198,7 +200,7 @@ export const make = Effect.gen(function* () {
let defaultSchema: string | undefined
Object.entries(operation.responses ?? {}).forEach(
([status, response]) => {
if ("$ref" in response) {
while ("$ref" in response) {
response = resolveRef(response.$ref as string)
}
if (response.content?.["application/json"]?.schema) {
Expand All @@ -222,6 +224,9 @@ export const make = Effect.gen(function* () {
op.errorSchemas.set(statusLower, schemaName)
}
}
if (!response.content) {
op.voidSchemas.add(status.toLowerCase())
}
},
)
if (op.successSchemas.size === 0 && defaultSchema) {
Expand Down Expand Up @@ -397,6 +402,9 @@ ${clientErrorSource(name)}`
operation.errorSchemas.forEach((schema, status) => {
decodes.push(`"${status}": decodeError("${schema}", ${schema})`)
})
operation.voidSchemas.forEach((status) => {
decodes.push(`"${status}": () => Effect.void`)
})
decodes.push(`orElse: unexpectedStatus`)

pipeline.push(`withResponse(HttpClientResponse.matchStatus({
Expand Down