@depup/openapi-typescript 7.13.0-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/CHANGELOG.md +1162 -0
  2. package/CONTRIBUTING.md +149 -0
  3. package/LICENSE +21 -0
  4. package/README.md +32 -0
  5. package/bin/cli.js +297 -0
  6. package/changes.json +14 -0
  7. package/dist/index.cjs +152 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.d.cts +517 -0
  10. package/dist/index.d.mts +515 -0
  11. package/dist/index.d.ts +517 -0
  12. package/dist/index.mjs +85 -0
  13. package/dist/index.mjs.map +1 -0
  14. package/dist/lib/redoc.cjs +129 -0
  15. package/dist/lib/redoc.cjs.map +1 -0
  16. package/dist/lib/redoc.mjs +122 -0
  17. package/dist/lib/redoc.mjs.map +1 -0
  18. package/dist/lib/ts.cjs +470 -0
  19. package/dist/lib/ts.cjs.map +1 -0
  20. package/dist/lib/ts.mjs +431 -0
  21. package/dist/lib/ts.mjs.map +1 -0
  22. package/dist/lib/utils.cjs +295 -0
  23. package/dist/lib/utils.cjs.map +1 -0
  24. package/dist/lib/utils.mjs +278 -0
  25. package/dist/lib/utils.mjs.map +1 -0
  26. package/dist/transform/components-object.cjs +150 -0
  27. package/dist/transform/components-object.cjs.map +1 -0
  28. package/dist/transform/components-object.mjs +127 -0
  29. package/dist/transform/components-object.mjs.map +1 -0
  30. package/dist/transform/header-object.cjs +48 -0
  31. package/dist/transform/header-object.cjs.map +1 -0
  32. package/dist/transform/header-object.mjs +42 -0
  33. package/dist/transform/header-object.mjs.map +1 -0
  34. package/dist/transform/index.cjs +124 -0
  35. package/dist/transform/index.cjs.map +1 -0
  36. package/dist/transform/index.mjs +118 -0
  37. package/dist/transform/index.mjs.map +1 -0
  38. package/dist/transform/media-type-object.cjs +14 -0
  39. package/dist/transform/media-type-object.cjs.map +1 -0
  40. package/dist/transform/media-type-object.mjs +12 -0
  41. package/dist/transform/media-type-object.mjs.map +1 -0
  42. package/dist/transform/operation-object.cjs +105 -0
  43. package/dist/transform/operation-object.cjs.map +1 -0
  44. package/dist/transform/operation-object.mjs +96 -0
  45. package/dist/transform/operation-object.mjs.map +1 -0
  46. package/dist/transform/parameter-object.cjs +11 -0
  47. package/dist/transform/parameter-object.cjs.map +1 -0
  48. package/dist/transform/parameter-object.mjs +9 -0
  49. package/dist/transform/parameter-object.mjs.map +1 -0
  50. package/dist/transform/parameters-array.cjs +120 -0
  51. package/dist/transform/parameters-array.cjs.map +1 -0
  52. package/dist/transform/parameters-array.mjs +114 -0
  53. package/dist/transform/parameters-array.mjs.map +1 -0
  54. package/dist/transform/path-item-object.cjs +84 -0
  55. package/dist/transform/path-item-object.cjs.map +1 -0
  56. package/dist/transform/path-item-object.mjs +78 -0
  57. package/dist/transform/path-item-object.mjs.map +1 -0
  58. package/dist/transform/paths-enum.cjs +35 -0
  59. package/dist/transform/paths-enum.cjs.map +1 -0
  60. package/dist/transform/paths-enum.mjs +33 -0
  61. package/dist/transform/paths-enum.mjs.map +1 -0
  62. package/dist/transform/paths-object.cjs +134 -0
  63. package/dist/transform/paths-object.cjs.map +1 -0
  64. package/dist/transform/paths-object.mjs +128 -0
  65. package/dist/transform/paths-object.mjs.map +1 -0
  66. package/dist/transform/request-body-object.cjs +68 -0
  67. package/dist/transform/request-body-object.cjs.map +1 -0
  68. package/dist/transform/request-body-object.mjs +62 -0
  69. package/dist/transform/request-body-object.mjs.map +1 -0
  70. package/dist/transform/response-object.cjs +123 -0
  71. package/dist/transform/response-object.cjs.map +1 -0
  72. package/dist/transform/response-object.mjs +117 -0
  73. package/dist/transform/response-object.mjs.map +1 -0
  74. package/dist/transform/responses-object.cjs +36 -0
  75. package/dist/transform/responses-object.cjs.map +1 -0
  76. package/dist/transform/responses-object.mjs +30 -0
  77. package/dist/transform/responses-object.mjs.map +1 -0
  78. package/dist/transform/schema-object.cjs +502 -0
  79. package/dist/transform/schema-object.cjs.map +1 -0
  80. package/dist/transform/schema-object.mjs +493 -0
  81. package/dist/transform/schema-object.mjs.map +1 -0
  82. package/dist/transform/webhooks-object.cjs +37 -0
  83. package/dist/transform/webhooks-object.cjs.map +1 -0
  84. package/dist/transform/webhooks-object.mjs +31 -0
  85. package/dist/transform/webhooks-object.mjs.map +1 -0
  86. package/package.json +102 -0
  87. package/src/index.ts +108 -0
  88. package/src/lib/redoc.ts +164 -0
  89. package/src/lib/ts.ts +616 -0
  90. package/src/lib/utils.ts +394 -0
  91. package/src/transform/components-object.ts +161 -0
  92. package/src/transform/header-object.ts +45 -0
  93. package/src/transform/index.ts +116 -0
  94. package/src/transform/media-type-object.ts +18 -0
  95. package/src/transform/operation-object.ts +104 -0
  96. package/src/transform/parameter-object.ts +15 -0
  97. package/src/transform/parameters-array.ts +129 -0
  98. package/src/transform/path-item-object.ts +102 -0
  99. package/src/transform/paths-enum.ts +43 -0
  100. package/src/transform/paths-object.ts +134 -0
  101. package/src/transform/request-body-object.ts +59 -0
  102. package/src/transform/response-object.ts +112 -0
  103. package/src/transform/responses-object.ts +36 -0
  104. package/src/transform/schema-object.ts +737 -0
  105. package/src/transform/webhooks-object.ts +27 -0
  106. package/src/types.ts +735 -0
@@ -0,0 +1,128 @@
1
+ import { performance } from 'node:perf_hooks';
2
+ import ts from 'typescript';
3
+ import { tsModifiers, tsPropertyIndex, oapiRef, addJSDocComment, stringToAST } from '../lib/ts.mjs';
4
+ import { getEntries, createRef, debug } from '../lib/utils.mjs';
5
+ import transformPathItemObject from './path-item-object.mjs';
6
+
7
+ const PATH_PARAM_RE = /\{[^}]+\}/g;
8
+ function transformPathsObject(pathsObject, ctx) {
9
+ const type = [];
10
+ for (const [url, pathItemObject] of getEntries(pathsObject, ctx)) {
11
+ if (!pathItemObject || typeof pathItemObject !== "object") {
12
+ continue;
13
+ }
14
+ const pathT = performance.now();
15
+ if ("$ref" in pathItemObject) {
16
+ const property = ts.factory.createPropertySignature(
17
+ /* modifiers */
18
+ tsModifiers({ readonly: ctx.immutable }),
19
+ /* name */
20
+ tsPropertyIndex(url),
21
+ /* questionToken */
22
+ void 0,
23
+ /* type */
24
+ oapiRef(pathItemObject.$ref)
25
+ );
26
+ addJSDocComment(pathItemObject, property);
27
+ type.push(property);
28
+ } else {
29
+ const pathItemType = transformPathItemObject(pathItemObject, {
30
+ path: createRef(["paths", url]),
31
+ ctx
32
+ });
33
+ if (ctx.pathParamsAsTypes && url.includes("{")) {
34
+ const pathParams = extractPathParams(pathItemObject, ctx);
35
+ const matches = url.match(PATH_PARAM_RE);
36
+ let rawPath = `\`${url}\``;
37
+ if (matches) {
38
+ for (const match of matches) {
39
+ const paramName = match.slice(1, -1);
40
+ const param = pathParams[paramName];
41
+ switch (param?.schema?.type) {
42
+ case "number":
43
+ case "integer":
44
+ rawPath = rawPath.replace(match, "${number}");
45
+ break;
46
+ case "boolean":
47
+ rawPath = rawPath.replace(match, "${boolean}");
48
+ break;
49
+ default:
50
+ rawPath = rawPath.replace(match, "${string}");
51
+ break;
52
+ }
53
+ }
54
+ const pathType = stringToAST(rawPath)[0]?.expression;
55
+ if (pathType) {
56
+ type.push(
57
+ ts.factory.createIndexSignature(
58
+ /* modifiers */
59
+ tsModifiers({ readonly: ctx.immutable }),
60
+ /* parameters */
61
+ [
62
+ ts.factory.createParameterDeclaration(
63
+ /* modifiers */
64
+ void 0,
65
+ /* dotDotDotToken */
66
+ void 0,
67
+ /* name */
68
+ "path",
69
+ /* questionToken */
70
+ void 0,
71
+ /* type */
72
+ pathType,
73
+ /* initializer */
74
+ void 0
75
+ )
76
+ ],
77
+ /* type */
78
+ pathItemType
79
+ )
80
+ );
81
+ continue;
82
+ }
83
+ }
84
+ }
85
+ type.push(
86
+ ts.factory.createPropertySignature(
87
+ /* modifiers */
88
+ tsModifiers({ readonly: ctx.immutable }),
89
+ /* name */
90
+ tsPropertyIndex(url),
91
+ /* questionToken */
92
+ void 0,
93
+ /* type */
94
+ pathItemType
95
+ )
96
+ );
97
+ debug(`Transformed path "${url}"`, "ts", performance.now() - pathT);
98
+ }
99
+ }
100
+ return ts.factory.createTypeLiteralNode(type);
101
+ }
102
+ function extractPathParams(pathItemObject, ctx) {
103
+ const params = {};
104
+ for (const p of pathItemObject.parameters ?? []) {
105
+ const resolved = "$ref" in p && p.$ref ? ctx.resolve(p.$ref) : p;
106
+ if (resolved && resolved.in === "path") {
107
+ params[resolved.name] = resolved;
108
+ }
109
+ }
110
+ for (const method of ["get", "put", "post", "delete", "options", "head", "patch", "trace"]) {
111
+ if (!(method in pathItemObject)) {
112
+ continue;
113
+ }
114
+ const resolvedMethod = pathItemObject[method].$ref ? ctx.resolve(pathItemObject[method].$ref) : pathItemObject[method];
115
+ if (resolvedMethod?.parameters) {
116
+ for (const p of resolvedMethod.parameters) {
117
+ const resolvedParam = "$ref" in p && p.$ref ? ctx.resolve(p.$ref) : p;
118
+ if (resolvedParam && resolvedParam.in === "path") {
119
+ params[resolvedParam.name] = resolvedParam;
120
+ }
121
+ }
122
+ }
123
+ }
124
+ return params;
125
+ }
126
+
127
+ export { transformPathsObject as default };
128
+ //# sourceMappingURL=paths-object.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths-object.mjs","sources":["../../src/transform/paths-object.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport ts from \"typescript\";\nimport { addJSDocComment, oapiRef, stringToAST, tsModifiers, tsPropertyIndex } from \"../lib/ts.js\";\nimport { createRef, debug, getEntries } from \"../lib/utils.js\";\nimport type {\n GlobalContext,\n OperationObject,\n ParameterObject,\n PathItemObject,\n PathsObject,\n ReferenceObject,\n} from \"../types.js\";\nimport transformPathItemObject, { type Method } from \"./path-item-object.js\";\n\nconst PATH_PARAM_RE = /\\{[^}]+\\}/g;\n\n/**\n * Transform the PathsObject node (4.8.8)\n * @see https://spec.openapis.org/oas/v3.1.0#operation-object\n */\nexport default function transformPathsObject(pathsObject: PathsObject, ctx: GlobalContext): ts.TypeNode {\n const type: ts.TypeElement[] = [];\n for (const [url, pathItemObject] of getEntries(pathsObject, ctx)) {\n if (!pathItemObject || typeof pathItemObject !== \"object\") {\n continue;\n }\n\n const pathT = performance.now();\n\n // handle $ref\n if (\"$ref\" in pathItemObject) {\n const property = ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: ctx.immutable }),\n /* name */ tsPropertyIndex(url),\n /* questionToken */ undefined,\n /* type */ oapiRef(pathItemObject.$ref),\n );\n addJSDocComment(pathItemObject, property);\n type.push(property);\n } else {\n const pathItemType = transformPathItemObject(pathItemObject, {\n path: createRef([\"paths\", url]),\n ctx,\n });\n\n // pathParamsAsTypes\n if (ctx.pathParamsAsTypes && url.includes(\"{\")) {\n const pathParams = extractPathParams(pathItemObject, ctx);\n const matches = url.match(PATH_PARAM_RE);\n let rawPath = `\\`${url}\\``;\n if (matches) {\n for (const match of matches) {\n const paramName = match.slice(1, -1);\n const param = pathParams[paramName];\n switch (param?.schema?.type) {\n case \"number\":\n case \"integer\":\n rawPath = rawPath.replace(match, \"${number}\");\n break;\n case \"boolean\":\n rawPath = rawPath.replace(match, \"${boolean}\");\n break;\n default:\n rawPath = rawPath.replace(match, \"${string}\");\n break;\n }\n }\n // note: creating a string template literal’s AST manually is hard!\n // just pass an arbitrary string to TS\n const pathType = (stringToAST(rawPath)[0] as any)?.expression;\n if (pathType) {\n type.push(\n ts.factory.createIndexSignature(\n /* modifiers */ tsModifiers({ readonly: ctx.immutable }),\n /* parameters */ [\n ts.factory.createParameterDeclaration(\n /* modifiers */ undefined,\n /* dotDotDotToken */ undefined,\n /* name */ \"path\",\n /* questionToken */ undefined,\n /* type */ pathType,\n /* initializer */ undefined,\n ),\n ],\n /* type */ pathItemType,\n ),\n );\n continue;\n }\n }\n }\n\n type.push(\n ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: ctx.immutable }),\n /* name */ tsPropertyIndex(url),\n /* questionToken */ undefined,\n /* type */ pathItemType,\n ),\n );\n\n debug(`Transformed path \"${url}\"`, \"ts\", performance.now() - pathT);\n }\n }\n\n return ts.factory.createTypeLiteralNode(type);\n}\n\nfunction extractPathParams(pathItemObject: PathItemObject, ctx: GlobalContext) {\n const params: Record<string, ParameterObject> = {};\n for (const p of pathItemObject.parameters ?? []) {\n const resolved = \"$ref\" in p && p.$ref ? ctx.resolve<ParameterObject>(p.$ref) : (p as ParameterObject);\n if (resolved && resolved.in === \"path\") {\n params[resolved.name] = resolved;\n }\n }\n for (const method of [\"get\", \"put\", \"post\", \"delete\", \"options\", \"head\", \"patch\", \"trace\"] as Method[]) {\n if (!(method in pathItemObject)) {\n continue;\n }\n const resolvedMethod = (pathItemObject[method] as ReferenceObject).$ref\n ? ctx.resolve<OperationObject>((pathItemObject[method] as ReferenceObject).$ref)\n : (pathItemObject[method] as OperationObject);\n if (resolvedMethod?.parameters) {\n for (const p of resolvedMethod.parameters) {\n const resolvedParam = \"$ref\" in p && p.$ref ? ctx.resolve<ParameterObject>(p.$ref) : (p as ParameterObject);\n if (resolvedParam && resolvedParam.in === \"path\") {\n params[resolvedParam.name] = resolvedParam;\n }\n }\n }\n }\n return params;\n}\n"],"names":[],"mappings":";;;;;;AAcA,MAAM,aAAA,GAAgB,YAAA;AAMtB,SAAwB,oBAAA,CAAqB,aAA0B,GAAA,EAAiC;AACtG,EAAA,MAAM,OAAyB,EAAC;AAChC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,cAAc,KAAK,UAAA,CAAW,WAAA,EAAa,GAAG,CAAA,EAAG;AAChE,IAAA,IAAI,CAAC,cAAA,IAAkB,OAAO,cAAA,KAAmB,QAAA,EAAU;AACzD,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,KAAA,GAAQ,YAAY,GAAA,EAAI;AAG9B,IAAA,IAAI,UAAU,cAAA,EAAgB;AAC5B,MAAA,MAAM,QAAA,GAAW,GAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,QACN,WAAA,CAAY,EAAE,QAAA,EAAU,GAAA,CAAI,WAAW,CAAA;AAAA;AAAA,QACv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,OAAO,GAAA,CAAI,OAAA,CAAyB,CAAA,CAAE,IAAI,CAAA,GAAK,CAAA;AACjF,IAAA,IAAI,QAAA,IAAY,QAAA,CAAS,EAAA,KAAO,MAAA,EAAQ;AACtC,MAAA,MAAA,CAAO,QAAA,CAAS,IAAI,CAAA,GAAI,QAAA;AAAA,IAC1B;AAAA,EACF;AACA,EAAA,KAAA,MAAW,MAAA,IAAU,CAAC,KAAA,EAAO,KAAA,EAAO,MAAA,EAAQ,UAAU,SAAA,EAAW,MAAA,EAAQ,OAAA,EAAS,OAAO,CAAA,EAAe;AACtG,IAAA,IAAI,EAAE,UAAU,cAAA,CAAA,EAAiB;AAC/B,MAAA;AAAA,IACF;AACA,IAAA,MAAM,cAAA,GAAkB,cAAA,CAAe,MAAM,CAAA,CAAsB,IAAA,GAC/D,GAAA,CAAI,OAAA,CAA0B,cAAA,CAAe,MAAM,CAAA,CAAsB,IAAI,CAAA,GAC5E,eAAe,MAAM,CAAA;AAC1B,IAAA,IAAI,gBAAgB,UAAA,EAAY;AAC9B,MAAA,KAAA,MAAW,CAAA,IAAK,eAAe,UAAA,EAAY;AACzC,QAAA,MAAM,aAAA,GAAgB,UAAU,CAAA,IAAK,CAAA,CAAE,OAAO,GAAA,CAAI,OAAA,CAAyB,CAAA,CAAE,IAAI,CAAA,GAAK,CAAA;AACtF,QAAA,IAAI,aAAA,IAAiB,aAAA,CAAc,EAAA,KAAO,MAAA,EAAQ;AAChD,UAAA,MAAA,CAAO,aAAA,CAAc,IAAI,CAAA,GAAI,aAAA;AAAA,QAC/B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;;;;"}
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ const ts = require('typescript');
4
+ const ts$1 = require('../lib/ts.cjs');
5
+ const utils = require('../lib/utils.cjs');
6
+ const mediaTypeObject = require('./media-type-object.cjs');
7
+ const schemaObject = require('./schema-object.cjs');
8
+
9
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
10
+
11
+ const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
12
+
13
+ function transformRequestBodyObject(requestBodyObject, options) {
14
+ const type = [];
15
+ for (const [contentType, mediaTypeObject$1] of utils.getEntries(requestBodyObject.content ?? {}, options.ctx)) {
16
+ const nextPath = utils.createRef([options.path, "content", contentType]);
17
+ const mediaType = "$ref" in mediaTypeObject$1 ? schemaObject.default(mediaTypeObject$1, {
18
+ ...options,
19
+ path: nextPath
20
+ }) : mediaTypeObject(mediaTypeObject$1, {
21
+ ...options,
22
+ path: nextPath
23
+ });
24
+ const property = ts__default.factory.createPropertySignature(
25
+ /* modifiers */
26
+ ts$1.tsModifiers({ readonly: options.ctx.immutable }),
27
+ /* name */
28
+ ts$1.tsPropertyIndex(contentType),
29
+ /* questionToken */
30
+ void 0,
31
+ /* type */
32
+ mediaType
33
+ );
34
+ ts$1.addJSDocComment(mediaTypeObject$1, property);
35
+ type.push(property);
36
+ }
37
+ return ts__default.factory.createTypeLiteralNode([
38
+ ts__default.factory.createPropertySignature(
39
+ /* modifiers */
40
+ ts$1.tsModifiers({ readonly: options.ctx.immutable }),
41
+ /* name */
42
+ ts$1.tsPropertyIndex("content"),
43
+ /* questionToken */
44
+ void 0,
45
+ /* type */
46
+ ts__default.factory.createTypeLiteralNode(
47
+ type.length ? type : (
48
+ // add `"*/*": never` if no media types are defined
49
+ [
50
+ ts__default.factory.createPropertySignature(
51
+ /* modifiers */
52
+ void 0,
53
+ /* name */
54
+ ts$1.tsPropertyIndex("*/*"),
55
+ /* questionToken */
56
+ ts$1.QUESTION_TOKEN,
57
+ /* type */
58
+ ts$1.NEVER
59
+ )
60
+ ]
61
+ )
62
+ )
63
+ )
64
+ ]);
65
+ }
66
+
67
+ module.exports = transformRequestBodyObject;
68
+ //# sourceMappingURL=request-body-object.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-body-object.cjs","sources":["../../src/transform/request-body-object.ts"],"sourcesContent":["import ts from \"typescript\";\nimport { addJSDocComment, NEVER, QUESTION_TOKEN, tsModifiers, tsPropertyIndex } from \"../lib/ts.js\";\nimport { createRef, getEntries } from \"../lib/utils.js\";\nimport type { RequestBodyObject, TransformNodeOptions } from \"../types.js\";\nimport transformMediaTypeObject from \"./media-type-object.js\";\nimport transformSchemaObject from \"./schema-object.js\";\n\n/**\n * Transform RequestBodyObject nodes (4.8.13)\n * @see https://spec.openapis.org/oas/v3.1.0#request-body-object\n */\nexport default function transformRequestBodyObject(\n requestBodyObject: RequestBodyObject,\n options: TransformNodeOptions,\n): ts.TypeNode {\n const type: ts.TypeElement[] = [];\n for (const [contentType, mediaTypeObject] of getEntries(requestBodyObject.content ?? {}, options.ctx)) {\n const nextPath = createRef([options.path, \"content\", contentType]);\n const mediaType =\n \"$ref\" in mediaTypeObject\n ? transformSchemaObject(mediaTypeObject, {\n ...options,\n path: nextPath,\n })\n : transformMediaTypeObject(mediaTypeObject, {\n ...options,\n path: nextPath,\n });\n const property = ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),\n /* name */ tsPropertyIndex(contentType),\n /* questionToken */ undefined,\n /* type */ mediaType,\n );\n addJSDocComment(mediaTypeObject, property);\n type.push(property);\n }\n\n return ts.factory.createTypeLiteralNode([\n ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),\n /* name */ tsPropertyIndex(\"content\"),\n /* questionToken */ undefined,\n /* type */ ts.factory.createTypeLiteralNode(\n type.length\n ? type\n : // add `\"*/*\": never` if no media types are defined\n [\n ts.factory.createPropertySignature(\n /* modifiers */ undefined,\n /* name */ tsPropertyIndex(\"*/*\"),\n /* questionToken */ QUESTION_TOKEN,\n /* type */ NEVER,\n ),\n ],\n ),\n ),\n ]);\n}\n"],"names":["mediaTypeObject","getEntries","createRef","transformSchemaObject","transformMediaTypeObject","ts","tsModifiers","tsPropertyIndex","addJSDocComment","QUESTION_TOKEN","NE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,GACD,IAAA;AAAA;AAAA,UAEA;AAAA,YACEA,YAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,cACW,MAAA;AAAA;AAAA,cACAE,qBAAgB,KAAK,CAAA;AAAA;AAAA,cACrBE,mBAAA;AAAA;AAAA,cACAC;AAAA;AACtB;AACF;AAAA;AACN;AACF,GACD,CAAA;AACH;;;;"}
@@ -0,0 +1,62 @@
1
+ import ts from 'typescript';
2
+ import { tsModifiers, tsPropertyIndex, addJSDocComment, QUESTION_TOKEN, NEVER } from '../lib/ts.mjs';
3
+ import { getEntries, createRef } from '../lib/utils.mjs';
4
+ import transformMediaTypeObject from './media-type-object.mjs';
5
+ import transformSchemaObject from './schema-object.mjs';
6
+
7
+ function transformRequestBodyObject(requestBodyObject, options) {
8
+ const type = [];
9
+ for (const [contentType, mediaTypeObject] of getEntries(requestBodyObject.content ?? {}, options.ctx)) {
10
+ const nextPath = createRef([options.path, "content", contentType]);
11
+ const mediaType = "$ref" in mediaTypeObject ? transformSchemaObject(mediaTypeObject, {
12
+ ...options,
13
+ path: nextPath
14
+ }) : transformMediaTypeObject(mediaTypeObject, {
15
+ ...options,
16
+ path: nextPath
17
+ });
18
+ const property = ts.factory.createPropertySignature(
19
+ /* modifiers */
20
+ tsModifiers({ readonly: options.ctx.immutable }),
21
+ /* name */
22
+ tsPropertyIndex(contentType),
23
+ /* questionToken */
24
+ void 0,
25
+ /* type */
26
+ mediaType
27
+ );
28
+ addJSDocComment(mediaTypeObject, property);
29
+ type.push(property);
30
+ }
31
+ return ts.factory.createTypeLiteralNode([
32
+ ts.factory.createPropertySignature(
33
+ /* modifiers */
34
+ tsModifiers({ readonly: options.ctx.immutable }),
35
+ /* name */
36
+ tsPropertyIndex("content"),
37
+ /* questionToken */
38
+ void 0,
39
+ /* type */
40
+ ts.factory.createTypeLiteralNode(
41
+ type.length ? type : (
42
+ // add `"*/*": never` if no media types are defined
43
+ [
44
+ ts.factory.createPropertySignature(
45
+ /* modifiers */
46
+ void 0,
47
+ /* name */
48
+ tsPropertyIndex("*/*"),
49
+ /* questionToken */
50
+ QUESTION_TOKEN,
51
+ /* type */
52
+ NEVER
53
+ )
54
+ ]
55
+ )
56
+ )
57
+ )
58
+ ]);
59
+ }
60
+
61
+ export { transformRequestBodyObject as default };
62
+ //# sourceMappingURL=request-body-object.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-body-object.mjs","sources":["../../src/transform/request-body-object.ts"],"sourcesContent":["import ts from \"typescript\";\nimport { addJSDocComment, NEVER, QUESTION_TOKEN, tsModifiers, tsPropertyIndex } from \"../lib/ts.js\";\nimport { createRef, getEntries } from \"../lib/utils.js\";\nimport type { RequestBodyObject, TransformNodeOptions } from \"../types.js\";\nimport transformMediaTypeObject from \"./media-type-object.js\";\nimport transformSchemaObject from \"./schema-object.js\";\n\n/**\n * Transform RequestBodyObject nodes (4.8.13)\n * @see https://spec.openapis.org/oas/v3.1.0#request-body-object\n */\nexport default function transformRequestBodyObject(\n requestBodyObject: RequestBodyObject,\n options: TransformNodeOptions,\n): ts.TypeNode {\n const type: ts.TypeElement[] = [];\n for (const [contentType, mediaTypeObject] of getEntries(requestBodyObject.content ?? {}, options.ctx)) {\n const nextPath = createRef([options.path, \"content\", contentType]);\n const mediaType =\n \"$ref\" in mediaTypeObject\n ? transformSchemaObject(mediaTypeObject, {\n ...options,\n path: nextPath,\n })\n : transformMediaTypeObject(mediaTypeObject, {\n ...options,\n path: nextPath,\n });\n const property = ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),\n /* name */ tsPropertyIndex(contentType),\n /* questionToken */ undefined,\n /* type */ mediaType,\n );\n addJSDocComment(mediaTypeObject, property);\n type.push(property);\n }\n\n return ts.factory.createTypeLiteralNode([\n ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),\n /* name */ tsPropertyIndex(\"content\"),\n /* questionToken */ undefined,\n /* type */ ts.factory.createTypeLiteralNode(\n type.length\n ? type\n : // add `\"*/*\": never` if no media types are defined\n [\n ts.factory.createPropertySignature(\n /* modifiers */ undefined,\n /* name */ tsPropertyIndex(\"*/*\"),\n /* questionToken */ QUESTION_TOKEN,\n /* type */ NEVER,\n ),\n ],\n ),\n ),\n ]);\n}\n"],"names":[],"mappings":";;;;;;AAWA,SAAwB,0BAAA,CACtB,mBACA,OAAA,EACa;AACb,EAAA,MAAM,OAAyB,EAAC;AAChC,EAAA,KAAA,MAAW,CAAC,WAAA,EAAa,eAAe,CAAA,IAAK,UAAA,CAAW,iBAAA,CAAkB,OAAA,IAAW,EAAC,EAAG,OAAA,CAAQ,GAAG,CAAA,EAAG;AACrG,IAAA,MAAM,WAAW,SAAA,CAAU,CAAC,QAAQ,IAAA,EAAM,SAAA,EAAW,WAAW,CAAC,CAAA;AACjE,IAAA,MAAM,SAAA,GACJ,MAAA,IAAU,eAAA,GACN,qBAAA,CAAsB,eAAA,EAAiB;AAAA,MACrC,GAAG,OAAA;AAAA,MACH,IAAA,EAAM;AAAA,KACP,CAAA,GACD,wBAAA,CAAyB,eAAA,EAAiB;AAAA,MACxC,GAAG,OAAA;AAAA,MACH,IAAA,EAAM;AAAA,KACP,CAAA;AACP,IAAA,MAAM,QAAA,GAAW,GAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,MACN,YAAY,EAAE,QAAA,EAAU,OAAA,CAAQ,GAAA,CAAI,WAAW,CAAA;AAAA;AAAA,MAC/C,gBAAgB,WAAW,CAAA;AAAA;AAAA,MAC3B,MAAA;AAAA;AAAA,MACA;AAAA,KACtB;AACA,IAAA,eAAA,CAAgB,iBAAiB,QAAQ,CAAA;AACzC,IAAA,IAAA,CAAK,KAAK,QAAQ,CAAA;AAAA,EACpB;AAEA,EAAA,OAAO,EAAA,CAAG,QAAQ,qBAAA,CAAsB;AAAA,IACtC,GAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,MACW,YAAY,EAAE,QAAA,EAAU,OAAA,CAAQ,GAAA,CAAI,WAAW,CAAA;AAAA;AAAA,MAC/C,gBAAgB,SAAS,CAAA;AAAA;AAAA,MACzB,MAAA;AAAA;AAAA,MACA,GAAG,OAAA,CAAQ,qBAAA;AAAA,QAC7B,KAAK,MAAA,GACD,IAAA;AAAA;AAAA,UAEA;AAAA,YACE,GAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,cACW,MAAA;AAAA;AAAA,cACA,gBAAgB,KAAK,CAAA;AAAA;AAAA,cACrB,cAAA;AAAA;AAAA,cACA;AAAA;AACtB;AACF;AAAA;AACN;AACF,GACD,CAAA;AACH;;;;"}
@@ -0,0 +1,123 @@
1
+ 'use strict';
2
+
3
+ const ts$1 = require('typescript');
4
+ const ts = require('../lib/ts.cjs');
5
+ const utils = require('../lib/utils.cjs');
6
+ const headerObject = require('./header-object.cjs');
7
+ const mediaTypeObject = require('./media-type-object.cjs');
8
+
9
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
10
+
11
+ const ts__default = /*#__PURE__*/_interopDefaultCompat(ts$1);
12
+
13
+ function transformResponseObject(responseObject, options) {
14
+ const type = [];
15
+ const headersObject = [];
16
+ if (responseObject.headers) {
17
+ for (const [name, headerObject$1] of utils.getEntries(responseObject.headers, options.ctx)) {
18
+ const optional = "$ref" in headerObject$1 || headerObject$1.required ? void 0 : ts.QUESTION_TOKEN;
19
+ const subType = "$ref" in headerObject$1 ? ts.oapiRef(headerObject$1.$ref) : headerObject(headerObject$1, {
20
+ ...options,
21
+ path: utils.createRef([options.path, "headers", name])
22
+ });
23
+ const property = ts__default.factory.createPropertySignature(
24
+ /* modifiers */
25
+ ts.tsModifiers({ readonly: options.ctx.immutable }),
26
+ /* name */
27
+ ts.tsPropertyIndex(name),
28
+ /* questionToken */
29
+ optional,
30
+ /* type */
31
+ subType
32
+ );
33
+ ts.addJSDocComment(headerObject$1, property);
34
+ headersObject.push(property);
35
+ }
36
+ }
37
+ headersObject.push(
38
+ ts__default.factory.createIndexSignature(
39
+ /* modifiers */
40
+ ts.tsModifiers({ readonly: options.ctx.immutable }),
41
+ /* parameters */
42
+ [
43
+ ts__default.factory.createParameterDeclaration(
44
+ /* modifiers */
45
+ void 0,
46
+ /* dotDotDotToken */
47
+ void 0,
48
+ /* name */
49
+ ts__default.factory.createIdentifier("name"),
50
+ /* questionToken */
51
+ void 0,
52
+ /* type */
53
+ ts.STRING
54
+ )
55
+ ],
56
+ /* type */
57
+ ts.UNKNOWN
58
+ )
59
+ );
60
+ type.push(
61
+ ts__default.factory.createPropertySignature(
62
+ /* modifiers */
63
+ void 0,
64
+ /* name */
65
+ ts.tsPropertyIndex("headers"),
66
+ /* questionToken */
67
+ void 0,
68
+ /* type */
69
+ ts__default.factory.createTypeLiteralNode(headersObject)
70
+ )
71
+ );
72
+ const contentObject = [];
73
+ if (responseObject.content) {
74
+ for (const [contentType, mediaTypeObject$1] of utils.getEntries(responseObject.content ?? {}, options.ctx)) {
75
+ const property = ts__default.factory.createPropertySignature(
76
+ /* modifiers */
77
+ ts.tsModifiers({ readonly: options.ctx.immutable }),
78
+ /* name */
79
+ ts.tsPropertyIndex(contentType),
80
+ /* questionToken */
81
+ void 0,
82
+ /* type */
83
+ mediaTypeObject(mediaTypeObject$1, {
84
+ ...options,
85
+ path: utils.createRef([options.path, "content", contentType])
86
+ })
87
+ );
88
+ ts.addJSDocComment(mediaTypeObject$1, property);
89
+ contentObject.push(property);
90
+ }
91
+ }
92
+ if (contentObject.length) {
93
+ type.push(
94
+ ts__default.factory.createPropertySignature(
95
+ /* modifiers */
96
+ void 0,
97
+ /* name */
98
+ ts.tsPropertyIndex("content"),
99
+ /* questionToken */
100
+ void 0,
101
+ /* type */
102
+ ts__default.factory.createTypeLiteralNode(contentObject)
103
+ )
104
+ );
105
+ } else {
106
+ type.push(
107
+ ts__default.factory.createPropertySignature(
108
+ /* modifiers */
109
+ void 0,
110
+ /* name */
111
+ ts.tsPropertyIndex("content"),
112
+ /* questionToken */
113
+ ts.QUESTION_TOKEN,
114
+ /* type */
115
+ ts.NEVER
116
+ )
117
+ );
118
+ }
119
+ return ts__default.factory.createTypeLiteralNode(type);
120
+ }
121
+
122
+ module.exports = transformResponseObject;
123
+ //# sourceMappingURL=response-object.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-object.cjs","sources":["../../src/transform/response-object.ts"],"sourcesContent":["import ts from \"typescript\";\nimport {\n addJSDocComment,\n NEVER,\n oapiRef,\n QUESTION_TOKEN,\n STRING,\n tsModifiers,\n tsPropertyIndex,\n UNKNOWN,\n} from \"../lib/ts.js\";\nimport { createRef, getEntries } from \"../lib/utils.js\";\nimport type { ResponseObject, TransformNodeOptions } from \"../types.js\";\nimport transformHeaderObject from \"./header-object.js\";\nimport transformMediaTypeObject from \"./media-type-object.js\";\n\n/**\n * Transform ResponseObject nodes (4.8.17)\n * @see https://spec.openapis.org/oas/v3.1.0#response-object\n */\nexport default function transformResponseObject(\n responseObject: ResponseObject,\n options: TransformNodeOptions,\n): ts.TypeNode {\n const type: ts.TypeElement[] = [];\n\n // headers\n const headersObject: ts.TypeElement[] = [];\n if (responseObject.headers) {\n for (const [name, headerObject] of getEntries(responseObject.headers, options.ctx)) {\n const optional = \"$ref\" in headerObject || headerObject.required ? undefined : QUESTION_TOKEN;\n const subType =\n \"$ref\" in headerObject\n ? oapiRef(headerObject.$ref)\n : transformHeaderObject(headerObject, {\n ...options,\n path: createRef([options.path, \"headers\", name]),\n });\n const property = ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),\n /* name */ tsPropertyIndex(name),\n /* questionToken */ optional,\n /* type */ subType,\n );\n addJSDocComment(headerObject, property);\n headersObject.push(property);\n }\n }\n // allow additional unknown headers\n headersObject.push(\n ts.factory.createIndexSignature(\n /* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),\n /* parameters */ [\n ts.factory.createParameterDeclaration(\n /* modifiers */ undefined,\n /* dotDotDotToken */ undefined,\n /* name */ ts.factory.createIdentifier(\"name\"),\n /* questionToken */ undefined,\n /* type */ STRING,\n ),\n ],\n /* type */ UNKNOWN,\n ),\n );\n type.push(\n ts.factory.createPropertySignature(\n /* modifiers */ undefined,\n /* name */ tsPropertyIndex(\"headers\"),\n /* questionToken */ undefined,\n /* type */ ts.factory.createTypeLiteralNode(headersObject),\n ),\n );\n\n // content\n const contentObject: ts.TypeElement[] = [];\n if (responseObject.content) {\n for (const [contentType, mediaTypeObject] of getEntries(responseObject.content ?? {}, options.ctx)) {\n const property = ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),\n /* name */ tsPropertyIndex(contentType),\n /* questionToken */ undefined,\n /* type */ transformMediaTypeObject(mediaTypeObject, {\n ...options,\n path: createRef([options.path, \"content\", contentType]),\n }),\n );\n addJSDocComment(mediaTypeObject, property);\n contentObject.push(property);\n }\n }\n if (contentObject.length) {\n type.push(\n ts.factory.createPropertySignature(\n /* modifiers */ undefined,\n /* name */ tsPropertyIndex(\"content\"),\n /* questionToken */ undefined,\n /* type */ ts.factory.createTypeLiteralNode(contentObject),\n ),\n );\n } else {\n type.push(\n ts.factory.createPropertySignature(\n /* modifiers */ undefined,\n /* name */ tsPropertyIndex(\"content\"),\n /* questionToken */ QUESTION_TOKEN,\n /* type */ NEVER,\n ),\n );\n }\n\n return ts.factory.createTypeLiteralNode(type);\n}\n"],"names":["headerObject","getEntries","QUESTION_TOKEN","oapiRef","transformHeaderObject","createRef","ts","tsModifiers","tsPropertyIndex","addJSDocComment","STRING","UNKNOWN","mediaTypeObject","transformMediaTypeObject","NEVER"],"mappings":";;;;;;;;;;;;AAoBA,SAAwB,uBAAA,CACtB,gBACA,OAAA,EACa;AACb,EAAA,MAAM,OAAyB,EAAC;AAGhC,EAAA,MAAM,gBAAkC,EAAC;AACzC,EAAA,IAAI,eAAe,OAAA,EAAS;AAC1B,IAAA,KAAA,MAAW,CAAC,MAAMA,cAAY,CAAA,IAAKC,iBAAW,cAAA,CAAe,OAAA,EAAS,OAAA,CAA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CAAA;AAAA;AAAA,QACzBN,iBAAA;AAAA;AAAA,QACAY;AAAA;AACtB,KACF;AAAA,EACF;AAEA,EAAA,OAAOR,WAAA,CAAG,OAAA,CAAQ,qBAAA,CAAsB,IAAI,CAAA;AAC9C;;;;"}
@@ -0,0 +1,117 @@
1
+ import ts from 'typescript';
2
+ import { QUESTION_TOKEN, oapiRef, tsModifiers, tsPropertyIndex, addJSDocComment, STRING, UNKNOWN, NEVER } from '../lib/ts.mjs';
3
+ import { getEntries, createRef } from '../lib/utils.mjs';
4
+ import transformHeaderObject from './header-object.mjs';
5
+ import transformMediaTypeObject from './media-type-object.mjs';
6
+
7
+ function transformResponseObject(responseObject, options) {
8
+ const type = [];
9
+ const headersObject = [];
10
+ if (responseObject.headers) {
11
+ for (const [name, headerObject] of getEntries(responseObject.headers, options.ctx)) {
12
+ const optional = "$ref" in headerObject || headerObject.required ? void 0 : QUESTION_TOKEN;
13
+ const subType = "$ref" in headerObject ? oapiRef(headerObject.$ref) : transformHeaderObject(headerObject, {
14
+ ...options,
15
+ path: createRef([options.path, "headers", name])
16
+ });
17
+ const property = ts.factory.createPropertySignature(
18
+ /* modifiers */
19
+ tsModifiers({ readonly: options.ctx.immutable }),
20
+ /* name */
21
+ tsPropertyIndex(name),
22
+ /* questionToken */
23
+ optional,
24
+ /* type */
25
+ subType
26
+ );
27
+ addJSDocComment(headerObject, property);
28
+ headersObject.push(property);
29
+ }
30
+ }
31
+ headersObject.push(
32
+ ts.factory.createIndexSignature(
33
+ /* modifiers */
34
+ tsModifiers({ readonly: options.ctx.immutable }),
35
+ /* parameters */
36
+ [
37
+ ts.factory.createParameterDeclaration(
38
+ /* modifiers */
39
+ void 0,
40
+ /* dotDotDotToken */
41
+ void 0,
42
+ /* name */
43
+ ts.factory.createIdentifier("name"),
44
+ /* questionToken */
45
+ void 0,
46
+ /* type */
47
+ STRING
48
+ )
49
+ ],
50
+ /* type */
51
+ UNKNOWN
52
+ )
53
+ );
54
+ type.push(
55
+ ts.factory.createPropertySignature(
56
+ /* modifiers */
57
+ void 0,
58
+ /* name */
59
+ tsPropertyIndex("headers"),
60
+ /* questionToken */
61
+ void 0,
62
+ /* type */
63
+ ts.factory.createTypeLiteralNode(headersObject)
64
+ )
65
+ );
66
+ const contentObject = [];
67
+ if (responseObject.content) {
68
+ for (const [contentType, mediaTypeObject] of getEntries(responseObject.content ?? {}, options.ctx)) {
69
+ const property = ts.factory.createPropertySignature(
70
+ /* modifiers */
71
+ tsModifiers({ readonly: options.ctx.immutable }),
72
+ /* name */
73
+ tsPropertyIndex(contentType),
74
+ /* questionToken */
75
+ void 0,
76
+ /* type */
77
+ transformMediaTypeObject(mediaTypeObject, {
78
+ ...options,
79
+ path: createRef([options.path, "content", contentType])
80
+ })
81
+ );
82
+ addJSDocComment(mediaTypeObject, property);
83
+ contentObject.push(property);
84
+ }
85
+ }
86
+ if (contentObject.length) {
87
+ type.push(
88
+ ts.factory.createPropertySignature(
89
+ /* modifiers */
90
+ void 0,
91
+ /* name */
92
+ tsPropertyIndex("content"),
93
+ /* questionToken */
94
+ void 0,
95
+ /* type */
96
+ ts.factory.createTypeLiteralNode(contentObject)
97
+ )
98
+ );
99
+ } else {
100
+ type.push(
101
+ ts.factory.createPropertySignature(
102
+ /* modifiers */
103
+ void 0,
104
+ /* name */
105
+ tsPropertyIndex("content"),
106
+ /* questionToken */
107
+ QUESTION_TOKEN,
108
+ /* type */
109
+ NEVER
110
+ )
111
+ );
112
+ }
113
+ return ts.factory.createTypeLiteralNode(type);
114
+ }
115
+
116
+ export { transformResponseObject as default };
117
+ //# sourceMappingURL=response-object.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-object.mjs","sources":["../../src/transform/response-object.ts"],"sourcesContent":["import ts from \"typescript\";\nimport {\n addJSDocComment,\n NEVER,\n oapiRef,\n QUESTION_TOKEN,\n STRING,\n tsModifiers,\n tsPropertyIndex,\n UNKNOWN,\n} from \"../lib/ts.js\";\nimport { createRef, getEntries } from \"../lib/utils.js\";\nimport type { ResponseObject, TransformNodeOptions } from \"../types.js\";\nimport transformHeaderObject from \"./header-object.js\";\nimport transformMediaTypeObject from \"./media-type-object.js\";\n\n/**\n * Transform ResponseObject nodes (4.8.17)\n * @see https://spec.openapis.org/oas/v3.1.0#response-object\n */\nexport default function transformResponseObject(\n responseObject: ResponseObject,\n options: TransformNodeOptions,\n): ts.TypeNode {\n const type: ts.TypeElement[] = [];\n\n // headers\n const headersObject: ts.TypeElement[] = [];\n if (responseObject.headers) {\n for (const [name, headerObject] of getEntries(responseObject.headers, options.ctx)) {\n const optional = \"$ref\" in headerObject || headerObject.required ? undefined : QUESTION_TOKEN;\n const subType =\n \"$ref\" in headerObject\n ? oapiRef(headerObject.$ref)\n : transformHeaderObject(headerObject, {\n ...options,\n path: createRef([options.path, \"headers\", name]),\n });\n const property = ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),\n /* name */ tsPropertyIndex(name),\n /* questionToken */ optional,\n /* type */ subType,\n );\n addJSDocComment(headerObject, property);\n headersObject.push(property);\n }\n }\n // allow additional unknown headers\n headersObject.push(\n ts.factory.createIndexSignature(\n /* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),\n /* parameters */ [\n ts.factory.createParameterDeclaration(\n /* modifiers */ undefined,\n /* dotDotDotToken */ undefined,\n /* name */ ts.factory.createIdentifier(\"name\"),\n /* questionToken */ undefined,\n /* type */ STRING,\n ),\n ],\n /* type */ UNKNOWN,\n ),\n );\n type.push(\n ts.factory.createPropertySignature(\n /* modifiers */ undefined,\n /* name */ tsPropertyIndex(\"headers\"),\n /* questionToken */ undefined,\n /* type */ ts.factory.createTypeLiteralNode(headersObject),\n ),\n );\n\n // content\n const contentObject: ts.TypeElement[] = [];\n if (responseObject.content) {\n for (const [contentType, mediaTypeObject] of getEntries(responseObject.content ?? {}, options.ctx)) {\n const property = ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: options.ctx.immutable }),\n /* name */ tsPropertyIndex(contentType),\n /* questionToken */ undefined,\n /* type */ transformMediaTypeObject(mediaTypeObject, {\n ...options,\n path: createRef([options.path, \"content\", contentType]),\n }),\n );\n addJSDocComment(mediaTypeObject, property);\n contentObject.push(property);\n }\n }\n if (contentObject.length) {\n type.push(\n ts.factory.createPropertySignature(\n /* modifiers */ undefined,\n /* name */ tsPropertyIndex(\"content\"),\n /* questionToken */ undefined,\n /* type */ ts.factory.createTypeLiteralNode(contentObject),\n ),\n );\n } else {\n type.push(\n ts.factory.createPropertySignature(\n /* modifiers */ undefined,\n /* name */ tsPropertyIndex(\"content\"),\n /* questionToken */ QUESTION_TOKEN,\n /* type */ NEVER,\n ),\n );\n }\n\n return ts.factory.createTypeLiteralNode(type);\n}\n"],"names":[],"mappings":";;;;;;AAoBA,SAAwB,uBAAA,CACtB,gBACA,OAAA,EACa;AACb,EAAA,MAAM,OAAyB,EAAC;AAGhC,EAAA,MAAM,gBAAkC,EAAC;AACzC,EAAA,IAAI,eAAe,OAAA,EAAS;AAC1B,IAAA,KAAA,MAAW,CAAC,MAAM,YAAY,CAAA,IAAK,WAAW,cAAA,CAAe,OAAA,EAAS,OAAA,CAAQ,GAAG,CAAA,EAAG;AAClF,MAAA,MAAM,QAAA,GAAW,MAAA,IAAU,YAAA,IAAgB,YAAA,CAAa,WAAW,MAAA,GAAY,cAAA;AAC/E,MAAA,MAAM,OAAA,GACJ,UAAU,YAAA,GACN,OAAA,CAAQ,aAAa,IAAI,CAAA,GACzB,sBAAsB,YAAA,EAAc;AAAA,QAClC,GAAG,OAAA;AAAA,QACH,MAAM,SAAA,CAAU,CAAC,QAAQ,IAAA,EAAM,SAAA,EAAW,IAAI,CAAC;AAAA,OAChD,CAAA;AACP,MAAA,MAAM,QAAA,GAAW,GAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,QACN,YAAY,EAAE,QAAA,EAAU,OAAA,CAAQ,GAAA,CAAI,WAAW,CAAA;AAAA;AAAA,QAC/C,gBAAgB,IAAI,C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,yBAAyB,eAAA,EAAiB;AAAA,UAC5D,GAAG,OAAA;AAAA,UACH,MAAM,SAAA,CAAU,CAAC,QAAQ,IAAA,EAAM,SAAA,EAAW,WAAW,CAAC;AAAA,SACvD;AAAA,OACH;AACA,MAAA,eAAA,CAAgB,iBAAiB,QAAQ,CAAA;AACzC,MAAA,aAAA,CAAc,KAAK,QAAQ,CAAA;AAAA,IAC7B;AAAA,EACF;AACA,EAAA,IAAI,cAAc,MAAA,EAAQ;AACxB,IAAA,IAAA,CAAK,IAAA;AAAA,MACH,GAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,QACW,MAAA;AAAA;AAAA,QACA,gBAAgB,SAAS,CAAA;AAAA;AAAA,QACzB,MAAA;AAAA;AAAA,QACA,EAAA,CAAG,OAAA,CAAQ,qBAAA,CAAsB,aAAa;AAAA;AACpE,KACF;AAAA,EACF,CAAA,MAAO;AACL,IAAA,IAAA,CAAK,IAAA;AAAA,MACH,GAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,QACW,MAAA;AAAA;AAAA,QACA,gBAAgB,SAAS,CAAA;AAAA;AAAA,QACzB,cAAA;AAAA;AAAA,QACA;AAAA;AACtB,KACF;AAAA,EACF;AAEA,EAAA,OAAO,EAAA,CAAG,OAAA,CAAQ,qBAAA,CAAsB,IAAI,CAAA;AAC9C;;;;"}
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ const ts$1 = require('typescript');
4
+ const ts = require('../lib/ts.cjs');
5
+ const utils = require('../lib/utils.cjs');
6
+ const responseObject = require('./response-object.cjs');
7
+
8
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
+
10
+ const ts__default = /*#__PURE__*/_interopDefaultCompat(ts$1);
11
+
12
+ function transformResponsesObject(responsesObject, options) {
13
+ const type = [];
14
+ for (const [responseCode, responseObject$1] of utils.getEntries(responsesObject, options.ctx)) {
15
+ const responseType = "$ref" in responseObject$1 ? ts.oapiRef(responseObject$1.$ref) : responseObject(responseObject$1, {
16
+ ...options,
17
+ path: utils.createRef([options.path, "responses", responseCode])
18
+ });
19
+ const property = ts__default.factory.createPropertySignature(
20
+ /* modifiers */
21
+ ts.tsModifiers({ readonly: options.ctx.immutable }),
22
+ /* name */
23
+ ts.tsPropertyIndex(responseCode),
24
+ /* questionToken */
25
+ void 0,
26
+ /* type */
27
+ responseType
28
+ );
29
+ ts.addJSDocComment(responseObject$1, property);
30
+ type.push(property);
31
+ }
32
+ return type.length ? ts__default.factory.createTypeLiteralNode(type) : ts.NEVER;
33
+ }
34
+
35
+ module.exports = transformResponsesObject;
36
+ //# sourceMappingURL=responses-object.cjs.map
@@ -0,0 +1 @@
1
+ {"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;;;;"}
@@ -0,0 +1,30 @@
1
+ import ts from 'typescript';
2
+ import { oapiRef, tsModifiers, tsPropertyIndex, addJSDocComment, NEVER } from '../lib/ts.mjs';
3
+ import { getEntries, createRef } from '../lib/utils.mjs';
4
+ import transformResponseObject from './response-object.mjs';
5
+
6
+ function transformResponsesObject(responsesObject, options) {
7
+ const type = [];
8
+ for (const [responseCode, responseObject] of getEntries(responsesObject, options.ctx)) {
9
+ const responseType = "$ref" in responseObject ? oapiRef(responseObject.$ref) : transformResponseObject(responseObject, {
10
+ ...options,
11
+ path: createRef([options.path, "responses", responseCode])
12
+ });
13
+ const property = ts.factory.createPropertySignature(
14
+ /* modifiers */
15
+ tsModifiers({ readonly: options.ctx.immutable }),
16
+ /* name */
17
+ tsPropertyIndex(responseCode),
18
+ /* questionToken */
19
+ void 0,
20
+ /* type */
21
+ responseType
22
+ );
23
+ addJSDocComment(responseObject, property);
24
+ type.push(property);
25
+ }
26
+ return type.length ? ts.factory.createTypeLiteralNode(type) : NEVER;
27
+ }
28
+
29
+ export { transformResponsesObject as default };
30
+ //# sourceMappingURL=responses-object.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses-object.mjs","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":[],"mappings":";;;;;AAUA,SAAwB,wBAAA,CACtB,iBACA,OAAA,EACa;AACb,EAAA,MAAM,OAAyB,EAAC;AAEhC,EAAA,KAAA,MAAW,CAAC,cAAc,cAAc,CAAA,IAAK,WAAW,eAAA,EAAiB,OAAA,CAAQ,GAAG,CAAA,EAAG;AACrF,IAAA,MAAM,YAAA,GACJ,UAAU,cAAA,GACN,OAAA,CAAQ,eAAe,IAAI,CAAA,GAC3B,wBAAwB,cAAA,EAAgB;AAAA,MACtC,GAAG,OAAA;AAAA,MACH,MAAM,SAAA,CAAU,CAAC,QAAQ,IAAA,EAAM,WAAA,EAAa,YAAY,CAAC;AAAA,KAC1D,CAAA;AACP,IAAA,MAAM,QAAA,GAAW,GAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,MACN,YAAY,EAAE,QAAA,EAAU,OAAA,CAAQ,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,EACpB;AAEA,EAAA,OAAO,KAAK,MAAA,GAAS,EAAA,CAAG,OAAA,CAAQ,qBAAA,CAAsB,IAAI,CAAA,GAAI,KAAA;AAChE;;;;"}