Skip to content

Commit

Permalink
Throw if responseKey is undefined (#109)
Browse files Browse the repository at this point in the history
* Throw is responseKey is undefined

* Add x-response-key to fixtures
  • Loading branch information
razor-x authored Oct 7, 2024
1 parent ac806fe commit 888b33a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/lib/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,15 +719,24 @@ const createResponse = (
}

const description = okResponse.description ?? ''

if (!('x-response-key' in parsedOperation)) {
throw new Error(`Missing responseKey for ${path}`)
}

const responseKey = parsedOperation['x-response-key']

if (responseKey == null) {
if (responseKey === null) {
return {
responseType: 'void',
description,
}
}

if (responseKey == null) {
throw new Error(`Missing responseKey for ${path}`)
}

const content = 'content' in okResponse ? okResponse.content : null
if (typeof content !== 'object' || content === null) {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/openapi-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const OpenapiOperationSchema = z.object({
.optional(),
responses: ResponseSchema,
deprecated: z.boolean().default(false),
'x-response-key': z.string().nullable().default(null),
'x-response-key': z.string().nullable().optional(),
'x-title': z.string().default(''),
'x-undocumented': z.string().default(''),
'x-deprecated': z.string().default(''),
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/types/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export default {
security: [],
summary: '/deprecated/undocumented/endpoint',
tags: ['/deprecated/undocumented'],
'x-response-key': null,
'x-undocumented': 'true',
'x-title': 'Deprecated and undocumented endpoint',
},
Expand All @@ -272,6 +273,7 @@ export default {
security: [],
summary: '/draft/endpoint',
tags: ['/draft'],
'x-response-key': null,
'x-draft': 'true',
'x-title': 'Draft endpoint',
},
Expand Down

0 comments on commit 888b33a

Please sign in to comment.