diff --git a/src/lib/blueprint.ts b/src/lib/blueprint.ts index f7921635..71e494fb 100644 --- a/src/lib/blueprint.ts +++ b/src/lib/blueprint.ts @@ -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 { diff --git a/src/lib/openapi-schema.ts b/src/lib/openapi-schema.ts index 564f88fa..0431e558 100644 --- a/src/lib/openapi-schema.ts +++ b/src/lib/openapi-schema.ts @@ -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(''), diff --git a/test/fixtures/types/openapi.ts b/test/fixtures/types/openapi.ts index f6c993fa..d84a2505 100644 --- a/test/fixtures/types/openapi.ts +++ b/test/fixtures/types/openapi.ts @@ -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', }, @@ -272,6 +273,7 @@ export default { security: [], summary: '/draft/endpoint', tags: ['/draft'], + 'x-response-key': null, 'x-draft': 'true', 'x-title': 'Draft endpoint', },