UNPKG

openapi-typescript

Version:

Convert OpenAPI 3.0 & 3.1 schemas to TypeScript

1 lines 2.45 kB
{"version":3,"file":"responses-object.cjs","sources":["../../src/transform/responses-object.ts"],"sourcesContent":["import ts from \"typescript\";\nimport { addJSDocComment, NEVER, oapiRef, tsModifiers, tsPropertyIndex } from \"../lib/ts.js\";\nimport { createRef, getEntries } from \"../lib/utils.js\";\nimport type { ResponsesObject, TransformNodeOptions } from \"../types.js\";\nimport transformResponseObject from \"./response-object.js\";\n\n/**\n * Transform ResponsesObject nodes (4.8.16)\n * @see https://spec.openapis.org/oas/v3.1.0#responses-object\n */\nexport default function transformResponsesObject(\n responsesObject: ResponsesObject,\n options: TransformNodeOptions,\n): ts.TypeNode {\n const type: ts.TypeElement[] = [];\n\n for (const [responseCode, responseObject] of getEntries(responsesObject, options.ctx)) {\n const responseType =\n \"$ref\" in responseObject\n ? oapiRef(responseObject.$ref)\n : transformResponseObject(responseObject, {\n ...options,\n path: createRef([options.path, \"responses\", responseCode]),\n });\n const property = ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),\n /* name */ tsPropertyIndex(responseCode),\n /* questionToken */ undefined,\n /* type */ responseType,\n );\n addJSDocComment(responseObject, property);\n type.push(property);\n }\n\n return type.length ? ts.factory.createTypeLiteralNode(type) : NEVER;\n}\n"],"names":["responseObject","getEntries","oapiRef","transformResponseObject","createRef","ts","tsModifiers","tsPropertyIndex","addJSDocComment","NEVER"],"mappings":";;;;;;;;;;;AAUA,SAAwB,wBAAA,CACtB,iBACA,OAAA,EACa;AACb,EAAA,MAAM,OAAyB,EAAC;AAEhC,EAAA,KAAA,MAAW,CAAC,cAAcA,gBAAc,CAAA,IAAKC,iBAAW,eAAA,EAAiB,OAAA,CAAQ,GAAG,CAAA,EAAG;AACrF,IAAA,MAAM,YAAA,GACJ,UAAUD,gBAAA,GACNE,UAAA,CAAQF,iBAAe,IAAI,CAAA,GAC3BG,eAAwBH,gBAAA,EAAgB;AAAA,MACtC,GAAG,OAAA;AAAA,MACH,MAAMI,eAAA,CAAU,CAAC,QAAQ,IAAA,EAAM,WAAA,EAAa,YAAY,CAAC;AAAA,KAC1D,CAAA;AACP,IAAA,MAAM,QAAA,GAAWC,YAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,MACNC,eAAY,EAAE,QAAA,EAAU,OAAA,CAAQ,GAAA,CAAI,WAAW,CAAA;AAAA;AAAA,MAC/CC,mBAAgB,YAAY,CAAA;AAAA;AAAA,MAC5B,MAAA;AAAA;AAAA,MACA;AAAA,KACtB;AACA,IAAAC,kBAAA,CAAgBR,kBAAgB,QAAQ,CAAA;AACxC,IAAA,IAAA,CAAK,KAAK,QAAQ,CAAA;AAAA,EACpB;AAEA,EAAA,OAAO,KAAK,MAAA,GAASK,WAAA,CAAG,OAAA,CAAQ,qBAAA,CAAsB,IAAI,CAAA,GAAII,QAAA;AAChE;;;;"}