@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,150 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const node_perf_hooks = require('node:perf_hooks');
6
+ const changeCase = require('change-case');
7
+ const ts = require('typescript');
8
+ const ts$1 = require('../lib/ts.cjs');
9
+ const utils = require('../lib/utils.cjs');
10
+ const headerObject = require('./header-object.cjs');
11
+ const parameterObject = require('./parameter-object.cjs');
12
+ const pathItemObject = require('./path-item-object.cjs');
13
+ const requestBodyObject = require('./request-body-object.cjs');
14
+ const responseObject = require('./response-object.cjs');
15
+ const schemaObject = require('./schema-object.cjs');
16
+
17
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
18
+
19
+ function _interopNamespaceCompat(e) {
20
+ if (e && typeof e === 'object' && 'default' in e) return e;
21
+ const n = Object.create(null);
22
+ if (e) {
23
+ for (const k in e) {
24
+ n[k] = e[k];
25
+ }
26
+ }
27
+ n.default = e;
28
+ return n;
29
+ }
30
+
31
+ const changeCase__namespace = /*#__PURE__*/_interopNamespaceCompat(changeCase);
32
+ const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
33
+
34
+ function isEnumSchema(schema) {
35
+ return typeof schema === "object" && schema !== null && !Array.isArray(schema) && "enum" in schema && Array.isArray(schema.enum) && (!("type" in schema) || schema.type !== "object") && !("properties" in schema) && !("additionalProperties" in schema);
36
+ }
37
+ const transformers = {
38
+ schemas: schemaObject.default,
39
+ responses: responseObject,
40
+ parameters: parameterObject,
41
+ requestBodies: requestBodyObject,
42
+ headers: headerObject,
43
+ pathItems: pathItemObject
44
+ };
45
+ function transformComponentsObject(componentsObject, ctx) {
46
+ const type = [];
47
+ const rootTypeAliases = {};
48
+ for (const key of Object.keys(transformers)) {
49
+ const componentT = node_perf_hooks.performance.now();
50
+ const items = [];
51
+ if (componentsObject[key]) {
52
+ for (const [name, item] of utils.getEntries(componentsObject[key], ctx)) {
53
+ let subType = transformers[key](item, {
54
+ path: utils.createRef(["components", key, name]),
55
+ schema: item,
56
+ ctx
57
+ });
58
+ let hasQuestionToken = false;
59
+ if (ctx.transform) {
60
+ const result = ctx.transform(item, {
61
+ path: utils.createRef(["components", key, name]),
62
+ schema: item,
63
+ ctx
64
+ });
65
+ if (result) {
66
+ if ("schema" in result) {
67
+ subType = result.schema;
68
+ hasQuestionToken = result.questionToken;
69
+ } else {
70
+ subType = result;
71
+ }
72
+ }
73
+ }
74
+ const property = ts__default.factory.createPropertySignature(
75
+ /* modifiers */
76
+ ts$1.tsModifiers({ readonly: ctx.immutable }),
77
+ /* name */
78
+ ts$1.tsPropertyIndex(name),
79
+ /* questionToken */
80
+ hasQuestionToken ? ts$1.QUESTION_TOKEN : void 0,
81
+ /* type */
82
+ subType
83
+ );
84
+ ts$1.addJSDocComment(item, property);
85
+ items.push(property);
86
+ if (ctx.rootTypes) {
87
+ const shouldSkipEnumSchema = ctx.enum && key === "schemas" && isEnumSchema(item);
88
+ if (!shouldSkipEnumSchema) {
89
+ const componentKey = changeCase__namespace.pascalCase(singularizeComponentKey(key));
90
+ const componentName = ctx.rootTypesKeepCasing && key === "schemas" ? name : changeCase__namespace.pascalCase(name);
91
+ let aliasName = `${componentKey}${componentName}`;
92
+ let conflictCounter = 1;
93
+ while (rootTypeAliases[aliasName] !== void 0) {
94
+ conflictCounter++;
95
+ aliasName = `${componentKey}${componentName}_${conflictCounter}`;
96
+ }
97
+ const ref = ts__default.factory.createTypeReferenceNode(`components['${key}']['${name}']`);
98
+ if (ctx.rootTypesNoSchemaPrefix && key === "schemas") {
99
+ aliasName = aliasName.replace(componentKey, "");
100
+ }
101
+ const typeAlias = ts__default.factory.createTypeAliasDeclaration(
102
+ /* modifiers */
103
+ ts$1.tsModifiers({ export: true }),
104
+ /* name */
105
+ aliasName,
106
+ /* typeParameters */
107
+ void 0,
108
+ /* type */
109
+ ref
110
+ );
111
+ rootTypeAliases[aliasName] = typeAlias;
112
+ }
113
+ }
114
+ }
115
+ }
116
+ type.push(
117
+ ts__default.factory.createPropertySignature(
118
+ /* modifiers */
119
+ void 0,
120
+ /* name */
121
+ ts$1.tsPropertyIndex(key),
122
+ /* questionToken */
123
+ void 0,
124
+ /* type */
125
+ items.length ? ts__default.factory.createTypeLiteralNode(items) : ts$1.NEVER
126
+ )
127
+ );
128
+ utils.debug(`Transformed components \u2192 ${key}`, "ts", node_perf_hooks.performance.now() - componentT);
129
+ }
130
+ let rootTypes = [];
131
+ if (ctx.rootTypes) {
132
+ rootTypes = Object.keys(rootTypeAliases).map((k) => rootTypeAliases[k]);
133
+ }
134
+ return [ts__default.factory.createTypeLiteralNode(type), ...rootTypes];
135
+ }
136
+ function singularizeComponentKey(key) {
137
+ switch (key) {
138
+ // Handle special singular case
139
+ case "requestBodies":
140
+ return "requestBody";
141
+ // Default to removing the "s"
142
+ default:
143
+ return key.slice(0, -1);
144
+ }
145
+ }
146
+
147
+ exports.default = transformComponentsObject;
148
+ exports.isEnumSchema = isEnumSchema;
149
+ exports.singularizeComponentKey = singularizeComponentKey;
150
+ //# sourceMappingURL=components-object.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components-object.cjs","sources":["../../src/transform/components-object.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport * as changeCase from \"change-case\";\nimport ts from \"typescript\";\nimport { addJSDocComment, NEVER, QUESTION_TOKEN, tsModifiers, tsPropertyIndex } from \"../lib/ts.js\";\nimport { createRef, debug, getEntries } from \"../lib/utils.js\";\nimport type { ComponentsObject, GlobalContext, SchemaObject, TransformNodeOptions } from \"../types.js\";\nimport transformHeaderObject from \"./header-object.js\";\nimport transformParameterObject from \"./parameter-object.js\";\nimport transformPathItemObject from \"./path-item-object.js\";\nimport transformRequestBodyObject from \"./request-body-object.js\";\nimport transformResponseObject from \"./response-object.js\";\nimport transformSchemaObject from \"./schema-object.js\";\n\n/**\n * Determines if a schema object represents an enum type to prevent duplicate exports\n * when using --root-types and --enum flags together.\n *\n * When both flags are enabled:\n * - --enum flag generates TypeScript enums at the bottom of the file\n * - --root-types flag would normally also export these as root type aliases\n * - This results in duplicate exports (both enum and type alias for the same schema)\n *\n * This function identifies enum schemas so they can be excluded from root type generation,\n * allowing only the TypeScript enum to be generated.\n *\n * @param schema The schema object to check\n * @returns true if the schema represents an enum type\n */\nexport function isEnumSchema(schema: unknown): boolean {\n return (\n typeof schema === \"object\" &&\n schema !== null &&\n !Array.isArray(schema) &&\n \"enum\" in schema &&\n Array.isArray((schema as any).enum) &&\n (!(\"type\" in schema) || (schema as any).type !== \"object\") &&\n !(\"properties\" in schema) &&\n !(\"additionalProperties\" in schema)\n );\n}\n\ntype ComponentTransforms = keyof Omit<ComponentsObject, \"examples\" | \"securitySchemes\" | \"links\" | \"callbacks\">;\n\nconst transformers: Record<ComponentTransforms, (node: any, options: TransformNodeOptions) => ts.TypeNode> = {\n schemas: transformSchemaObject,\n responses: transformResponseObject,\n parameters: transformParameterObject,\n requestBodies: transformRequestBodyObject,\n headers: transformHeaderObject,\n pathItems: transformPathItemObject,\n};\n\n/**\n * Transform the ComponentsObject (4.8.7)\n * @see https://spec.openapis.org/oas/latest.html#components-object\n */\nexport default function transformComponentsObject(componentsObject: ComponentsObject, ctx: GlobalContext): ts.Node[] {\n const type: ts.TypeElement[] = [];\n const rootTypeAliases: { [key: string]: ts.TypeAliasDeclaration } = {};\n for (const key of Object.keys(transformers) as ComponentTransforms[]) {\n const componentT = performance.now();\n\n const items: ts.TypeElement[] = [];\n if (componentsObject[key]) {\n for (const [name, item] of getEntries<SchemaObject>(componentsObject[key], ctx)) {\n let subType = transformers[key](item, {\n path: createRef([\"components\", key, name]),\n schema: item,\n ctx,\n });\n\n let hasQuestionToken = false;\n if (ctx.transform) {\n const result = ctx.transform(item, {\n path: createRef([\"components\", key, name]),\n schema: item,\n ctx,\n });\n if (result) {\n if (\"schema\" in result) {\n subType = result.schema;\n hasQuestionToken = result.questionToken;\n } else {\n subType = result;\n }\n }\n }\n\n const property = ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: ctx.immutable }),\n /* name */ tsPropertyIndex(name),\n /* questionToken */ hasQuestionToken ? QUESTION_TOKEN : undefined,\n /* type */ subType,\n );\n addJSDocComment(item as unknown as any, property);\n items.push(property);\n\n if (ctx.rootTypes) {\n // Skip enum schemas when generating root types to prevent duplication (only when --enum flag is enabled)\n const shouldSkipEnumSchema = ctx.enum && key === \"schemas\" && isEnumSchema(item);\n\n if (!shouldSkipEnumSchema) {\n const componentKey = changeCase.pascalCase(singularizeComponentKey(key));\n const componentName = ctx.rootTypesKeepCasing && key === \"schemas\" ? name : changeCase.pascalCase(name);\n let aliasName = `${componentKey}${componentName}`;\n\n // Add counter suffix (e.g. \"_2\") if conflict in name\n let conflictCounter = 1;\n\n while (rootTypeAliases[aliasName] !== undefined) {\n conflictCounter++;\n aliasName = `${componentKey}${componentName}_${conflictCounter}`;\n }\n const ref = ts.factory.createTypeReferenceNode(`components['${key}']['${name}']`);\n if (ctx.rootTypesNoSchemaPrefix && key === \"schemas\") {\n aliasName = aliasName.replace(componentKey, \"\");\n }\n const typeAlias = ts.factory.createTypeAliasDeclaration(\n /* modifiers */ tsModifiers({ export: true }),\n /* name */ aliasName,\n /* typeParameters */ undefined,\n /* type */ ref,\n );\n rootTypeAliases[aliasName] = typeAlias;\n }\n }\n }\n }\n type.push(\n ts.factory.createPropertySignature(\n /* modifiers */ undefined,\n /* name */ tsPropertyIndex(key),\n /* questionToken */ undefined,\n /* type */ items.length ? ts.factory.createTypeLiteralNode(items) : NEVER,\n ),\n );\n\n debug(`Transformed components → ${key}`, \"ts\", performance.now() - componentT);\n }\n\n // Extract root types\n let rootTypes: ts.TypeAliasDeclaration[] = [];\n if (ctx.rootTypes) {\n rootTypes = Object.keys(rootTypeAliases).map((k) => rootTypeAliases[k]);\n }\n\n return [ts.factory.createTypeLiteralNode(type), ...rootTypes];\n}\n\nexport function singularizeComponentKey(\n key: `x-${string}` | \"schemas\" | \"responses\" | \"parameters\" | \"requestBodies\" | \"headers\" | \"pathItems\",\n): string {\n switch (key) {\n // Handle special singular case\n case \"requestBodies\":\n return \"requestBody\";\n // Default to removing the \"s\"\n default:\n return key.slice(0, -1);\n }\n}\n"],"names":["transformSchemaObject","transformResponseObject","transformParameterObject","transformRequestBodyObject","transformHeaderObject","transformPathItemObject","performance","getEntries","createRef","ts","tsModifiers","tsPropertyIndex","QUESTION_TOKEN","addJSDocComment","changeCase","NEVER","debug"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,SAAS,aAAa,MAAA,EAA0B;AACrD,EAAA,OACE,OAAO,MAAA,KAAW,QAAA,IAClB,MAAA,KAAW,IAAA,IACX,CAAC,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,IACrB,MAAA,IAAU,MAAA,IACV,KAA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,CAAC,CAAA,KAAM,eAAA,CAAgB,CAAC,CAAC,CAAA;AAAA,EACxE;AAEA,EAAA,OAAO,CAACG,WAAA,CAAG,OAAA,CAAQ,sBAAsB,IAAI,CAAA,EAAG,GAAG,SAAS,CAAA;AAC9D;AAEO,SAAS,wBACd,GAAA,EACQ;AACR,EAAA,QAAQ,GAAA;AAAK;AAAA,IAEX,KAAK,eAAA;AACH,MAAA,OAAO,aAAA;AAAA;AAAA,IAET;AACE,MAAA,OAAO,GAAA,CAAI,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA;AAE5B;;;;;;"}
@@ -0,0 +1,127 @@
1
+ import { performance } from 'node:perf_hooks';
2
+ import * as changeCase from 'change-case';
3
+ import ts from 'typescript';
4
+ import { tsModifiers, tsPropertyIndex, QUESTION_TOKEN, addJSDocComment, NEVER } from '../lib/ts.mjs';
5
+ import { getEntries, createRef, debug } from '../lib/utils.mjs';
6
+ import transformHeaderObject from './header-object.mjs';
7
+ import transformParameterObject from './parameter-object.mjs';
8
+ import transformPathItemObject from './path-item-object.mjs';
9
+ import transformRequestBodyObject from './request-body-object.mjs';
10
+ import transformResponseObject from './response-object.mjs';
11
+ import transformSchemaObject from './schema-object.mjs';
12
+
13
+ function isEnumSchema(schema) {
14
+ return typeof schema === "object" && schema !== null && !Array.isArray(schema) && "enum" in schema && Array.isArray(schema.enum) && (!("type" in schema) || schema.type !== "object") && !("properties" in schema) && !("additionalProperties" in schema);
15
+ }
16
+ const transformers = {
17
+ schemas: transformSchemaObject,
18
+ responses: transformResponseObject,
19
+ parameters: transformParameterObject,
20
+ requestBodies: transformRequestBodyObject,
21
+ headers: transformHeaderObject,
22
+ pathItems: transformPathItemObject
23
+ };
24
+ function transformComponentsObject(componentsObject, ctx) {
25
+ const type = [];
26
+ const rootTypeAliases = {};
27
+ for (const key of Object.keys(transformers)) {
28
+ const componentT = performance.now();
29
+ const items = [];
30
+ if (componentsObject[key]) {
31
+ for (const [name, item] of getEntries(componentsObject[key], ctx)) {
32
+ let subType = transformers[key](item, {
33
+ path: createRef(["components", key, name]),
34
+ schema: item,
35
+ ctx
36
+ });
37
+ let hasQuestionToken = false;
38
+ if (ctx.transform) {
39
+ const result = ctx.transform(item, {
40
+ path: createRef(["components", key, name]),
41
+ schema: item,
42
+ ctx
43
+ });
44
+ if (result) {
45
+ if ("schema" in result) {
46
+ subType = result.schema;
47
+ hasQuestionToken = result.questionToken;
48
+ } else {
49
+ subType = result;
50
+ }
51
+ }
52
+ }
53
+ const property = ts.factory.createPropertySignature(
54
+ /* modifiers */
55
+ tsModifiers({ readonly: ctx.immutable }),
56
+ /* name */
57
+ tsPropertyIndex(name),
58
+ /* questionToken */
59
+ hasQuestionToken ? QUESTION_TOKEN : void 0,
60
+ /* type */
61
+ subType
62
+ );
63
+ addJSDocComment(item, property);
64
+ items.push(property);
65
+ if (ctx.rootTypes) {
66
+ const shouldSkipEnumSchema = ctx.enum && key === "schemas" && isEnumSchema(item);
67
+ if (!shouldSkipEnumSchema) {
68
+ const componentKey = changeCase.pascalCase(singularizeComponentKey(key));
69
+ const componentName = ctx.rootTypesKeepCasing && key === "schemas" ? name : changeCase.pascalCase(name);
70
+ let aliasName = `${componentKey}${componentName}`;
71
+ let conflictCounter = 1;
72
+ while (rootTypeAliases[aliasName] !== void 0) {
73
+ conflictCounter++;
74
+ aliasName = `${componentKey}${componentName}_${conflictCounter}`;
75
+ }
76
+ const ref = ts.factory.createTypeReferenceNode(`components['${key}']['${name}']`);
77
+ if (ctx.rootTypesNoSchemaPrefix && key === "schemas") {
78
+ aliasName = aliasName.replace(componentKey, "");
79
+ }
80
+ const typeAlias = ts.factory.createTypeAliasDeclaration(
81
+ /* modifiers */
82
+ tsModifiers({ export: true }),
83
+ /* name */
84
+ aliasName,
85
+ /* typeParameters */
86
+ void 0,
87
+ /* type */
88
+ ref
89
+ );
90
+ rootTypeAliases[aliasName] = typeAlias;
91
+ }
92
+ }
93
+ }
94
+ }
95
+ type.push(
96
+ ts.factory.createPropertySignature(
97
+ /* modifiers */
98
+ void 0,
99
+ /* name */
100
+ tsPropertyIndex(key),
101
+ /* questionToken */
102
+ void 0,
103
+ /* type */
104
+ items.length ? ts.factory.createTypeLiteralNode(items) : NEVER
105
+ )
106
+ );
107
+ debug(`Transformed components \u2192 ${key}`, "ts", performance.now() - componentT);
108
+ }
109
+ let rootTypes = [];
110
+ if (ctx.rootTypes) {
111
+ rootTypes = Object.keys(rootTypeAliases).map((k) => rootTypeAliases[k]);
112
+ }
113
+ return [ts.factory.createTypeLiteralNode(type), ...rootTypes];
114
+ }
115
+ function singularizeComponentKey(key) {
116
+ switch (key) {
117
+ // Handle special singular case
118
+ case "requestBodies":
119
+ return "requestBody";
120
+ // Default to removing the "s"
121
+ default:
122
+ return key.slice(0, -1);
123
+ }
124
+ }
125
+
126
+ export { transformComponentsObject as default, isEnumSchema, singularizeComponentKey };
127
+ //# sourceMappingURL=components-object.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components-object.mjs","sources":["../../src/transform/components-object.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport * as changeCase from \"change-case\";\nimport ts from \"typescript\";\nimport { addJSDocComment, NEVER, QUESTION_TOKEN, tsModifiers, tsPropertyIndex } from \"../lib/ts.js\";\nimport { createRef, debug, getEntries } from \"../lib/utils.js\";\nimport type { ComponentsObject, GlobalContext, SchemaObject, TransformNodeOptions } from \"../types.js\";\nimport transformHeaderObject from \"./header-object.js\";\nimport transformParameterObject from \"./parameter-object.js\";\nimport transformPathItemObject from \"./path-item-object.js\";\nimport transformRequestBodyObject from \"./request-body-object.js\";\nimport transformResponseObject from \"./response-object.js\";\nimport transformSchemaObject from \"./schema-object.js\";\n\n/**\n * Determines if a schema object represents an enum type to prevent duplicate exports\n * when using --root-types and --enum flags together.\n *\n * When both flags are enabled:\n * - --enum flag generates TypeScript enums at the bottom of the file\n * - --root-types flag would normally also export these as root type aliases\n * - This results in duplicate exports (both enum and type alias for the same schema)\n *\n * This function identifies enum schemas so they can be excluded from root type generation,\n * allowing only the TypeScript enum to be generated.\n *\n * @param schema The schema object to check\n * @returns true if the schema represents an enum type\n */\nexport function isEnumSchema(schema: unknown): boolean {\n return (\n typeof schema === \"object\" &&\n schema !== null &&\n !Array.isArray(schema) &&\n \"enum\" in schema &&\n Array.isArray((schema as any).enum) &&\n (!(\"type\" in schema) || (schema as any).type !== \"object\") &&\n !(\"properties\" in schema) &&\n !(\"additionalProperties\" in schema)\n );\n}\n\ntype ComponentTransforms = keyof Omit<ComponentsObject, \"examples\" | \"securitySchemes\" | \"links\" | \"callbacks\">;\n\nconst transformers: Record<ComponentTransforms, (node: any, options: TransformNodeOptions) => ts.TypeNode> = {\n schemas: transformSchemaObject,\n responses: transformResponseObject,\n parameters: transformParameterObject,\n requestBodies: transformRequestBodyObject,\n headers: transformHeaderObject,\n pathItems: transformPathItemObject,\n};\n\n/**\n * Transform the ComponentsObject (4.8.7)\n * @see https://spec.openapis.org/oas/latest.html#components-object\n */\nexport default function transformComponentsObject(componentsObject: ComponentsObject, ctx: GlobalContext): ts.Node[] {\n const type: ts.TypeElement[] = [];\n const rootTypeAliases: { [key: string]: ts.TypeAliasDeclaration } = {};\n for (const key of Object.keys(transformers) as ComponentTransforms[]) {\n const componentT = performance.now();\n\n const items: ts.TypeElement[] = [];\n if (componentsObject[key]) {\n for (const [name, item] of getEntries<SchemaObject>(componentsObject[key], ctx)) {\n let subType = transformers[key](item, {\n path: createRef([\"components\", key, name]),\n schema: item,\n ctx,\n });\n\n let hasQuestionToken = false;\n if (ctx.transform) {\n const result = ctx.transform(item, {\n path: createRef([\"components\", key, name]),\n schema: item,\n ctx,\n });\n if (result) {\n if (\"schema\" in result) {\n subType = result.schema;\n hasQuestionToken = result.questionToken;\n } else {\n subType = result;\n }\n }\n }\n\n const property = ts.factory.createPropertySignature(\n /* modifiers */ tsModifiers({ readonly: ctx.immutable }),\n /* name */ tsPropertyIndex(name),\n /* questionToken */ hasQuestionToken ? QUESTION_TOKEN : undefined,\n /* type */ subType,\n );\n addJSDocComment(item as unknown as any, property);\n items.push(property);\n\n if (ctx.rootTypes) {\n // Skip enum schemas when generating root types to prevent duplication (only when --enum flag is enabled)\n const shouldSkipEnumSchema = ctx.enum && key === \"schemas\" && isEnumSchema(item);\n\n if (!shouldSkipEnumSchema) {\n const componentKey = changeCase.pascalCase(singularizeComponentKey(key));\n const componentName = ctx.rootTypesKeepCasing && key === \"schemas\" ? name : changeCase.pascalCase(name);\n let aliasName = `${componentKey}${componentName}`;\n\n // Add counter suffix (e.g. \"_2\") if conflict in name\n let conflictCounter = 1;\n\n while (rootTypeAliases[aliasName] !== undefined) {\n conflictCounter++;\n aliasName = `${componentKey}${componentName}_${conflictCounter}`;\n }\n const ref = ts.factory.createTypeReferenceNode(`components['${key}']['${name}']`);\n if (ctx.rootTypesNoSchemaPrefix && key === \"schemas\") {\n aliasName = aliasName.replace(componentKey, \"\");\n }\n const typeAlias = ts.factory.createTypeAliasDeclaration(\n /* modifiers */ tsModifiers({ export: true }),\n /* name */ aliasName,\n /* typeParameters */ undefined,\n /* type */ ref,\n );\n rootTypeAliases[aliasName] = typeAlias;\n }\n }\n }\n }\n type.push(\n ts.factory.createPropertySignature(\n /* modifiers */ undefined,\n /* name */ tsPropertyIndex(key),\n /* questionToken */ undefined,\n /* type */ items.length ? ts.factory.createTypeLiteralNode(items) : NEVER,\n ),\n );\n\n debug(`Transformed components → ${key}`, \"ts\", performance.now() - componentT);\n }\n\n // Extract root types\n let rootTypes: ts.TypeAliasDeclaration[] = [];\n if (ctx.rootTypes) {\n rootTypes = Object.keys(rootTypeAliases).map((k) => rootTypeAliases[k]);\n }\n\n return [ts.factory.createTypeLiteralNode(type), ...rootTypes];\n}\n\nexport function singularizeComponentKey(\n key: `x-${string}` | \"schemas\" | \"responses\" | \"parameters\" | \"requestBodies\" | \"headers\" | \"pathItems\",\n): string {\n switch (key) {\n // Handle special singular case\n case \"requestBodies\":\n return \"requestBody\";\n // Default to removing the \"s\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A,CAAA,EAAI,MAAM,WAAA,CAAY,GAAA,KAAQ,UAAU,CAAA;AAAA,EAC/E;AAGA,EAAA,IAAI,YAAuC,EAAC;AAC5C,EAAA,IAAI,IAAI,SAAA,EAAW;AACjB,IAAA,SAAA,GAAY,MAAA,CAAO,KAAK,eAAe,CAAA,CAAE,IAAI,CAAC,CAAA,KAAM,eAAA,CAAgB,CAAC,CAAC,CAAA;AAAA,EACxE;AAEA,EAAA,OAAO,CAAC,EAAA,CAAG,OAAA,CAAQ,sBAAsB,IAAI,CAAA,EAAG,GAAG,SAAS,CAAA;AAC9D;AAEO,SAAS,wBACd,GAAA,EACQ;AACR,EAAA,QAAQ,GAAA;AAAK;AAAA,IAEX,KAAK,eAAA;AACH,MAAA,OAAO,aAAA;AAAA;AAAA,IAET;AACE,MAAA,OAAO,GAAA,CAAI,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA;AAE5B;;;;"}
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ const refUtils_js = require('@redocly/openapi-core/lib/ref-utils.js');
4
+ const ts = require('typescript');
5
+ const ts$1 = require('../lib/ts.cjs');
6
+ const utils = require('../lib/utils.cjs');
7
+ const mediaTypeObject = require('./media-type-object.cjs');
8
+ const schemaObject = require('./schema-object.cjs');
9
+
10
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
11
+
12
+ const ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
13
+
14
+ function transformHeaderObject(headerObject, options) {
15
+ if (headerObject.schema) {
16
+ return schemaObject.default(headerObject.schema, options);
17
+ }
18
+ if (headerObject.content) {
19
+ const type = [];
20
+ for (const [contentType, mediaTypeObject$1] of utils.getEntries(headerObject.content ?? {}, options.ctx)) {
21
+ const nextPath = `${options.path ?? "#"}/${refUtils_js.escapePointer(contentType)}`;
22
+ const mediaType = "$ref" in mediaTypeObject$1 ? schemaObject.default(mediaTypeObject$1, {
23
+ ...options,
24
+ path: nextPath
25
+ }) : mediaTypeObject(mediaTypeObject$1, {
26
+ ...options,
27
+ path: nextPath
28
+ });
29
+ const property = ts__default.factory.createPropertySignature(
30
+ /* modifiers */
31
+ ts$1.tsModifiers({ readonly: options.ctx.immutable }),
32
+ /* name */
33
+ ts$1.tsPropertyIndex(contentType),
34
+ /* questionToken */
35
+ void 0,
36
+ /* type */
37
+ mediaType
38
+ );
39
+ ts$1.addJSDocComment(mediaTypeObject$1, property);
40
+ type.push(property);
41
+ }
42
+ return ts__default.factory.createTypeLiteralNode(type);
43
+ }
44
+ return ts$1.UNKNOWN;
45
+ }
46
+
47
+ module.exports = transformHeaderObject;
48
+ //# sourceMappingURL=header-object.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"header-object.cjs","sources":["../../src/transform/header-object.ts"],"sourcesContent":["import { escapePointer } from \"@redocly/openapi-core/lib/ref-utils.js\";\nimport ts from \"typescript\";\nimport { addJSDocComment, tsModifiers, tsPropertyIndex, UNKNOWN } from \"../lib/ts.js\";\nimport { getEntries } from \"../lib/utils.js\";\nimport type { HeaderObject, TransformNodeOptions } from \"../types.js\";\nimport transformMediaTypeObject from \"./media-type-object.js\";\nimport transformSchemaObject from \"./schema-object.js\";\n\n/**\n * Transform HeaderObject nodes (4.8.21)\n * @see https://spec.openapis.org/oas/v3.1.0#header-object\n */\nexport default function transformHeaderObject(headerObject: HeaderObject, options: TransformNodeOptions): ts.TypeNode {\n if (headerObject.schema) {\n return transformSchemaObject(headerObject.schema, options);\n }\n\n if (headerObject.content) {\n const type: ts.TypeElement[] = [];\n for (const [contentType, mediaTypeObject] of getEntries(headerObject.content ?? {}, options.ctx)) {\n const nextPath = `${options.path ?? \"#\"}/${escapePointer(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 return ts.factory.createTypeLiteralNode(type);\n }\n\n return UNKNOWN;\n}\n"],"names":["transformSchemaObject","mediaTypeObject","getEntries","escapePointer","transformMediaTypeObject","ts","tsModifiers","tsPropertyIndex","addJSDocComment","UNKNOWN"],"mappings":";;;;;;;;;;;;;AAYA,SAAwB,qBAAA,CAAsB,cAA4B,OAAA,EAA4C;AACpH,EAAA,IAAI,aAAa,MAAA,EAAQ;AACvB,IAAA,OAAOA,oBAAA,CAAsB,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA;AAAA,EAC3D;AAEA,EAAA,IAAI,aAAa,OAAA,EAAS;AACxB,IAAA,MAAM,OAAyB,EAAC;AAChC,IAAA,KAAA,MAAW,CAAC,WAAA,EAAaC,iBAAe,CAAA,IAAKC,gBAAA,CAAW,YAAA,CAAa,OAAA,IAAW,EAAC,EAAG,OAAA,CAAQ,GAAG,CAAA,EAAG;AAChG,MAAA,MAAM,QAAA,GAAW,GAAG,OAAA,CAAQ,IAAA,IAAQ,GAAG,CAAA,CAAA,EAAIC,yBAAA,CAAc,WAAW,CAAC,CAAA,CAAA;AACrE,MAAA,MAAM,SAAA,GACJ,MAAA,IAAUF,iBAAA,GACND,oBAAA,CAAsBC,iBAAA,EAAiB;AAAA,QACrC,GAAG,OAAA;AAAA,QACH,IAAA,EAAM;AAAA,OACP,CAAA,GACDG,eAAA,CAAyBH,iBAAA,EAAiB;AAAA,QACxC,GAAG,OAAA;AAAA,QACH,IAAA,EAAM;AAAA,OACP,CAAA;AACP,MAAA,MAAM,QAAA,GAAWI,YAAG,OAAA,CAAQ,uBAAA;AAAA;AAAA,QACNC,iBAAY,EAAE,QAAA,EAAU,OAAA,CAAQ,GAAA,CAAI,WAAW,CAAA;AAAA;AAAA,QAC/CC,qBAAgB,WAAW,CAAA;AAAA;AAAA,QAC3B,MAAA;AAAA;AAAA,QACA;AAAA,OACtB;AACA,MAAAC,oBAAA,CAAgBP,mBAAiB,QAAQ,CAAA;AACzC,MAAA,IAAA,CAAK,KAAK,QAAQ,CAAA;AAAA,IACpB;AACA,IAAA,OAAOI,WAAA,CAAG,OAAA,CAAQ,qBAAA,CAAsB,IAAI,CAAA;AAAA,EAC9C;AAEA,EAAA,OAAOI,YAAA;AACT;;;;"}
@@ -0,0 +1,42 @@
1
+ import { escapePointer } from '@redocly/openapi-core/lib/ref-utils.js';
2
+ import ts from 'typescript';
3
+ import { tsModifiers, tsPropertyIndex, addJSDocComment, UNKNOWN } from '../lib/ts.mjs';
4
+ import { getEntries } from '../lib/utils.mjs';
5
+ import transformMediaTypeObject from './media-type-object.mjs';
6
+ import transformSchemaObject from './schema-object.mjs';
7
+
8
+ function transformHeaderObject(headerObject, options) {
9
+ if (headerObject.schema) {
10
+ return transformSchemaObject(headerObject.schema, options);
11
+ }
12
+ if (headerObject.content) {
13
+ const type = [];
14
+ for (const [contentType, mediaTypeObject] of getEntries(headerObject.content ?? {}, options.ctx)) {
15
+ const nextPath = `${options.path ?? "#"}/${escapePointer(contentType)}`;
16
+ const mediaType = "$ref" in mediaTypeObject ? transformSchemaObject(mediaTypeObject, {
17
+ ...options,
18
+ path: nextPath
19
+ }) : transformMediaTypeObject(mediaTypeObject, {
20
+ ...options,
21
+ path: nextPath
22
+ });
23
+ const property = ts.factory.createPropertySignature(
24
+ /* modifiers */
25
+ tsModifiers({ readonly: options.ctx.immutable }),
26
+ /* name */
27
+ tsPropertyIndex(contentType),
28
+ /* questionToken */
29
+ void 0,
30
+ /* type */
31
+ mediaType
32
+ );
33
+ addJSDocComment(mediaTypeObject, property);
34
+ type.push(property);
35
+ }
36
+ return ts.factory.createTypeLiteralNode(type);
37
+ }
38
+ return UNKNOWN;
39
+ }
40
+
41
+ export { transformHeaderObject as default };
42
+ //# sourceMappingURL=header-object.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"header-object.mjs","sources":["../../src/transform/header-object.ts"],"sourcesContent":["import { escapePointer } from \"@redocly/openapi-core/lib/ref-utils.js\";\nimport ts from \"typescript\";\nimport { addJSDocComment, tsModifiers, tsPropertyIndex, UNKNOWN } from \"../lib/ts.js\";\nimport { getEntries } from \"../lib/utils.js\";\nimport type { HeaderObject, TransformNodeOptions } from \"../types.js\";\nimport transformMediaTypeObject from \"./media-type-object.js\";\nimport transformSchemaObject from \"./schema-object.js\";\n\n/**\n * Transform HeaderObject nodes (4.8.21)\n * @see https://spec.openapis.org/oas/v3.1.0#header-object\n */\nexport default function transformHeaderObject(headerObject: HeaderObject, options: TransformNodeOptions): ts.TypeNode {\n if (headerObject.schema) {\n return transformSchemaObject(headerObject.schema, options);\n }\n\n if (headerObject.content) {\n const type: ts.TypeElement[] = [];\n for (const [contentType, mediaTypeObject] of getEntries(headerObject.content ?? {}, options.ctx)) {\n const nextPath = `${options.path ?? \"#\"}/${escapePointer(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 return ts.factory.createTypeLiteralNode(type);\n }\n\n return UNKNOWN;\n}\n"],"names":[],"mappings":";;;;;;;AAYA,SAAwB,qBAAA,CAAsB,cAA4B,OAAA,EAA4C;AACpH,EAAA,IAAI,aAAa,MAAA,EAAQ;AACvB,IAAA,OAAO,qBAAA,CAAsB,YAAA,CAAa,MAAA,EAAQ,OAAO,CAAA;AAAA,EAC3D;AAEA,EAAA,IAAI,aAAa,OAAA,EAAS;AACxB,IAAA,MAAM,OAAyB,EAAC;AAChC,IAAA,KAAA,MAAW,CAAC,WAAA,EAAa,eAAe,CAAA,IAAK,UAAA,CAAW,YAAA,CAAa,OAAA,IAAW,EAAC,EAAG,OAAA,CAAQ,GAAG,CAAA,EAAG;AAChG,MAAA,MAAM,QAAA,GAAW,GAAG,OAAA,CAAQ,IAAA,IAAQ,GAAG,CAAA,CAAA,EAAI,aAAA,CAAc,WAAW,CAAC,CAAA,CAAA;AACrE,MAAA,MAAM,SAAA,GACJ,MAAA,IAAU,eAAA,GACN,qBAAA,CAAsB,eAAA,EAAiB;AAAA,QACrC,GAAG,OAAA;AAAA,QACH,IAAA,EAAM;AAAA,OACP,CAAA,GACD,wBAAA,CAAyB,eAAA,EAAiB;AAAA,QACxC,GAAG,OAAA;AAAA,QACH,IAAA,EAAM;AAAA,OACP,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,WAAW,CAAA;AAAA;AAAA,QAC3B,MAAA;AAAA;AAAA,QACA;AAAA,OACtB;AACA,MAAA,eAAA,CAAgB,iBAAiB,QAAQ,CAAA;AACzC,MAAA,IAAA,CAAK,KAAK,QAAQ,CAAA;AAAA,IACpB;AACA,IAAA,OAAO,EAAA,CAAG,OAAA,CAAQ,qBAAA,CAAsB,IAAI,CAAA;AAAA,EAC9C;AAEA,EAAA,OAAO,OAAA;AACT;;;;"}
@@ -0,0 +1,124 @@
1
+ 'use strict';
2
+
3
+ const node_perf_hooks = require('node:perf_hooks');
4
+ const ts$1 = require('typescript');
5
+ const ts = require('../lib/ts.cjs');
6
+ const utils = require('../lib/utils.cjs');
7
+ const componentsObject = require('./components-object.cjs');
8
+ const pathsEnum = require('./paths-enum.cjs');
9
+ const pathsObject = require('./paths-object.cjs');
10
+ const schemaObject = require('./schema-object.cjs');
11
+ const webhooksObject = require('./webhooks-object.cjs');
12
+
13
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
14
+
15
+ const ts__default = /*#__PURE__*/_interopDefaultCompat(ts$1);
16
+
17
+ const transformers = {
18
+ paths: pathsObject,
19
+ webhooks: webhooksObject,
20
+ components: componentsObject.default,
21
+ $defs: (node, options) => schemaObject.default(node, { path: utils.createRef(["$defs"]), ctx: options, schema: node })
22
+ };
23
+ const READ_WRITE_HELPER_TYPES = `
24
+ export type $Read<T> = { readonly $read: T };
25
+ export type $Write<T> = { readonly $write: T };
26
+ export type Readable<T> = T extends $Write<any> ? never : T extends $Read<infer U> ? Readable<U> : T extends (infer E)[] ? Readable<E>[] : T extends object ? { [K in keyof T as NonNullable<T[K]> extends $Write<any> ? never : K]: Readable<T[K]> } : T;
27
+ export type Writable<T> = T extends $Read<any> ? never : T extends $Write<infer U> ? Writable<U> : T extends (infer E)[] ? Writable<E>[] : T extends object ? { [K in keyof T as NonNullable<T[K]> extends $Read<any> ? never : K]: Writable<T[K]> } & { [K in keyof T as NonNullable<T[K]> extends $Read<any> ? K : never]?: never } : T;
28
+ `;
29
+ function transformSchema(schema, ctx) {
30
+ const type = [];
31
+ if (ctx.readWriteMarkers) {
32
+ const helperNodes = ts.stringToAST(READ_WRITE_HELPER_TYPES);
33
+ type.push(...helperNodes);
34
+ }
35
+ if (ctx.inject) {
36
+ const injectNodes = ts.stringToAST(ctx.inject);
37
+ type.push(...injectNodes);
38
+ }
39
+ for (const root of Object.keys(transformers)) {
40
+ const emptyObj = ts__default.factory.createTypeAliasDeclaration(
41
+ /* modifiers */
42
+ ts.tsModifiers({ export: true }),
43
+ /* name */
44
+ root,
45
+ /* typeParameters */
46
+ void 0,
47
+ /* type */
48
+ ts.tsRecord(ts.STRING, ts.NEVER)
49
+ );
50
+ if (schema[root] && typeof schema[root] === "object") {
51
+ const rootT = node_perf_hooks.performance.now();
52
+ const subTypes = [].concat(transformers[root](schema[root], ctx));
53
+ for (const subType of subTypes) {
54
+ if (ts__default.isTypeNode(subType)) {
55
+ if (subType.members?.length) {
56
+ type.push(
57
+ ctx.exportType ? ts__default.factory.createTypeAliasDeclaration(
58
+ /* modifiers */
59
+ ts.tsModifiers({ export: true }),
60
+ /* name */
61
+ root,
62
+ /* typeParameters */
63
+ void 0,
64
+ /* type */
65
+ subType
66
+ ) : ts__default.factory.createInterfaceDeclaration(
67
+ /* modifiers */
68
+ ts.tsModifiers({ export: true }),
69
+ /* name */
70
+ root,
71
+ /* typeParameters */
72
+ void 0,
73
+ /* heritageClauses */
74
+ void 0,
75
+ /* members */
76
+ subType.members
77
+ )
78
+ );
79
+ utils.debug(`${root} done`, "ts", node_perf_hooks.performance.now() - rootT);
80
+ } else {
81
+ type.push(emptyObj);
82
+ utils.debug(`${root} done (skipped)`, "ts", 0);
83
+ }
84
+ } else if (ts__default.isTypeAliasDeclaration(subType)) {
85
+ type.push(subType);
86
+ } else {
87
+ type.push(emptyObj);
88
+ utils.debug(`${root} done (skipped)`, "ts", 0);
89
+ }
90
+ }
91
+ } else {
92
+ type.push(emptyObj);
93
+ utils.debug(`${root} done (skipped)`, "ts", 0);
94
+ }
95
+ }
96
+ let hasOperations = false;
97
+ for (const injectedType of ctx.injectFooter) {
98
+ if (!hasOperations && injectedType?.name?.escapedText === "operations") {
99
+ hasOperations = true;
100
+ }
101
+ type.push(injectedType);
102
+ }
103
+ if (!hasOperations) {
104
+ type.push(
105
+ ts__default.factory.createTypeAliasDeclaration(
106
+ /* modifiers */
107
+ ts.tsModifiers({ export: true }),
108
+ /* name */
109
+ "operations",
110
+ /* typeParameters */
111
+ void 0,
112
+ /* type */
113
+ ts.tsRecord(ts.STRING, ts.NEVER)
114
+ )
115
+ );
116
+ }
117
+ if (ctx.makePathsEnum && schema.paths) {
118
+ type.push(pathsEnum(schema.paths));
119
+ }
120
+ return type;
121
+ }
122
+
123
+ module.exports = transformSchema;
124
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/transform/index.ts"],"sourcesContent":["import { performance } from \"node:perf_hooks\";\nimport ts, { type InterfaceDeclaration, type TypeLiteralNode } from \"typescript\";\nimport { NEVER, STRING, stringToAST, tsModifiers, tsRecord } from \"../lib/ts.js\";\nimport { createRef, debug } from \"../lib/utils.js\";\nimport type { GlobalContext, OpenAPI3 } from \"../types.js\";\nimport transformComponentsObject from \"./components-object.js\";\nimport makeApiPathsEnum from \"./paths-enum.js\";\nimport transformPathsObject from \"./paths-object.js\";\nimport transformSchemaObject from \"./schema-object.js\";\nimport transformWebhooksObject from \"./webhooks-object.js\";\n\ntype SchemaTransforms = keyof Pick<OpenAPI3, \"paths\" | \"webhooks\" | \"components\" | \"$defs\">;\n\nconst transformers: Record<SchemaTransforms, (node: any, options: GlobalContext) => ts.Node | ts.Node[]> = {\n paths: transformPathsObject,\n webhooks: transformWebhooksObject,\n components: transformComponentsObject,\n $defs: (node, options) => transformSchemaObject(node, { path: createRef([\"$defs\"]), ctx: options, schema: node }),\n};\n\n// Inline helper types for readOnly/writeOnly markers (when readWriteMarkers is enabled)\nconst READ_WRITE_HELPER_TYPES = `\nexport type $Read<T> = { readonly $read: T };\nexport type $Write<T> = { readonly $write: T };\nexport type Readable<T> = T extends $Write<any> ? never : T extends $Read<infer U> ? Readable<U> : T extends (infer E)[] ? Readable<E>[] : T extends object ? { [K in keyof T as NonNullable<T[K]> extends $Write<any> ? never : K]: Readable<T[K]> } : T;\nexport type Writable<T> = T extends $Read<any> ? never : T extends $Write<infer U> ? Writable<U> : T extends (infer E)[] ? Writable<E>[] : T extends object ? { [K in keyof T as NonNullable<T[K]> extends $Read<any> ? never : K]: Writable<T[K]> } & { [K in keyof T as NonNullable<T[K]> extends $Read<any> ? K : never]?: never } : T;\n`;\n\nexport default function transformSchema(schema: OpenAPI3, ctx: GlobalContext) {\n const type: ts.Node[] = [];\n\n // Add inline helper types for readOnly/writeOnly markers\n if (ctx.readWriteMarkers) {\n const helperNodes = stringToAST(READ_WRITE_HELPER_TYPES) as ts.Node[];\n type.push(...helperNodes);\n }\n\n if (ctx.inject) {\n const injectNodes = stringToAST(ctx.inject) as ts.Node[];\n type.push(...injectNodes);\n }\n\n for (const root of Object.keys(transformers) as SchemaTransforms[]) {\n const emptyObj = ts.factory.createTypeAliasDeclaration(\n /* modifiers */ tsModifiers({ export: true }),\n /* name */ root,\n /* typeParameters */ undefined,\n /* type */ tsRecord(STRING, NEVER),\n );\n\n if (schema[root] && typeof schema[root] === \"object\") {\n const rootT = performance.now();\n const subTypes = ([] as ts.Node[]).concat(transformers[root](schema[root], ctx));\n for (const subType of subTypes) {\n if (ts.isTypeNode(subType)) {\n if ((subType as ts.TypeLiteralNode).members?.length) {\n type.push(\n ctx.exportType\n ? ts.factory.createTypeAliasDeclaration(\n /* modifiers */ tsModifiers({ export: true }),\n /* name */ root,\n /* typeParameters */ undefined,\n /* type */ subType,\n )\n : ts.factory.createInterfaceDeclaration(\n /* modifiers */ tsModifiers({ export: true }),\n /* name */ root,\n /* typeParameters */ undefined,\n /* heritageClauses */ undefined,\n /* members */ (subType as TypeLiteralNode).members,\n ),\n );\n debug(`${root} done`, \"ts\", performance.now() - rootT);\n } else {\n type.push(emptyObj);\n debug(`${root} done (skipped)`, \"ts\", 0);\n }\n } else if (ts.isTypeAliasDeclaration(subType)) {\n type.push(subType);\n } else {\n type.push(emptyObj);\n debug(`${root} done (skipped)`, \"ts\", 0);\n }\n }\n } else {\n type.push(emptyObj);\n debug(`${root} done (skipped)`, \"ts\", 0);\n }\n }\n\n // inject\n let hasOperations = false;\n for (const injectedType of ctx.injectFooter) {\n if (!hasOperations && (injectedType as InterfaceDeclaration)?.name?.escapedText === \"operations\") {\n hasOperations = true;\n }\n type.push(injectedType);\n }\n if (!hasOperations) {\n // if no operations created, inject empty operations type\n type.push(\n ts.factory.createTypeAliasDeclaration(\n /* modifiers */ tsModifiers({ export: true }),\n /* name */ \"operations\",\n /* typeParameters */ undefined,\n /* type */ tsRecord(STRING, NEVER),\n ),\n );\n }\n\n if (ctx.makePathsEnum && schema.paths) {\n type.push(makeApiPathsEnum(schema.paths));\n }\n\n return type;\n}\n"],"names":["transformPathsObject","transformWebhooksObject","transformComponentsObject","transformSchemaObject","createRef","stringToAST","ts","tsModifiers","tsRecord","STRING","NEVER","performance","debug","makeApiPathsEnum"],"mappings":";;;;;;;;;;;;;;;;AAaA,MAAM,YAAA,GAAqG;AAAA,EACzG,KAAA,EAAOA,WAAA;AAAA,EACP,QAAA,EAAUC,cAAA;AAAA,EACV,UAAA,EAAYC,wBAAA;AAAA,EACZ,OAAO,CAAC,IAAA,EAAM,OAAA,KAAYC,oBAAA,CAAsB,MAAM,EAAE,IAAA,EAAMC,eAAA,CAAU,CAAC,OAAO,CAAC,CAAA,EAAG,KAAK,OAAA,EAAS,MAAA,EAAQ,MAAM;AAClH,CAAA;AAGA,MAAM,uBAAA,GAA0B;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA;AAOhC,SAAwB,eAAA,CAAgB,QAAkB,GAAA,EAAoB;AAC5E,EAAA,MAAM,OAAkB,EAAC;AAGzB,EAAA,IAAI,IAAI,gBAAA,EAAkB;AACxB,IAAA,MAAM,WAAA,GAAcC,eAAY,uBAAuB,CAAA;AACvD,IAAA,IAAA,CAAK,IAAA,CAAK,GAAG,WAAW,CAAA;AAAA,EAC1B;AAEA,EAAA,IAAI,IAAI,MAAA,EAAQ;AACd,IAAA,MAAM,WAAA,GAAcA,cAAA,CAAY,GAAA,CAAI,MAAM,CAAA;AAC1C,IAAA,IAAA,CAAK,IAAA,CAAK,GAAG,WAAW,CAAA;AAAA,EAC1B;AAEA,EAAA,KAAA,MAAW,IAAA,IAAQ,MAAA,CAAO,IAAA,CAAK,YAAY,CAAA,EAAyB;AAClE,IAAA,MAAM,QAAA,GAAWC,YAAG,OAAA,CAAQ,0BAAA;AAAA;AAAA,MACLC,cAAA,CAAY,EAAE,MAAA,EAAQ,IAAA,EAAM,CAAA;AAAA;AAAA,MAC5B,IAAA;AAAA;A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