openapi-typescript
Version:
Convert OpenAPI 3.0 & 3.1 schemas to TypeScript
1 lines • 2.28 kB
Source Map (JSON)
{"version":3,"file":"responses-object.mjs","sources":["../../src/transform/responses-object.ts"],"sourcesContent":["import ts from \"typescript\";\nimport { NEVER, addJSDocComment, tsModifiers, oapiRef, 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":[],"mappings":";;;;;AAUwB,SAAA,wBAAA,CACtB,iBACA,OACa,EAAA;AACb,EAAA,MAAM,OAAyB,EAAC;AAEhC,EAAW,KAAA,MAAA,CAAC,cAAc,cAAc,CAAA,IAAK,WAAW,eAAiB,EAAA,OAAA,CAAQ,GAAG,CAAG,EAAA;AACrF,IAAM,MAAA,YAAA,GACJ,UAAU,cACN,GAAA,OAAA,CAAQ,eAAe,IAAI,CAAA,GAC3B,wBAAwB,cAAgB,EAAA;AAAA,MACtC,GAAG,OAAA;AAAA,MACH,MAAM,SAAU,CAAA,CAAC,QAAQ,IAAM,EAAA,WAAA,EAAa,YAAY,CAAC;AAAA,KAC1D,CAAA;AACP,IAAM,MAAA,QAAA,GAAW,GAAG,OAAQ,CAAA,uBAAA;AAAA;AAAA,MACN,YAAY,EAAE,QAAA,EAAU,OAAQ,CAAA,GAAA,CAAI,WAAW,CAAA;AAAA;AAAA,MAC/C,gBAAgB,YAAY,CAAA;AAAA;AAAA,MAC5B,MAAA;AAAA;AAAA,MACA;AAAA,KACtB;AACA,IAAA,eAAA,CAAgB,gBAAgB,QAAQ,CAAA;AACxC,IAAA,IAAA,CAAK,KAAK,QAAQ,CAAA;AAAA;AAGpB,EAAA,OAAO,KAAK,MAAS,GAAA,EAAA,CAAG,OAAQ,CAAA,qBAAA,CAAsB,IAAI,CAAI,GAAA,KAAA;AAChE;;;;"}