@sdk-it/spec 0.22.0 → 0.23.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 (91) hide show
  1. package/dist/index.d.ts +7 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +19 -2629
  4. package/dist/index.js.map +4 -4
  5. package/dist/lib/find-polymorphic-varients.d.ts +1 -1
  6. package/dist/lib/find-polymorphic-varients.d.ts.map +1 -1
  7. package/dist/lib/find-polymorphic-varients.js +291 -0
  8. package/dist/lib/find-polymorphic-varients.js.map +7 -0
  9. package/dist/lib/find-polymorphic-varients.test.js +615 -0
  10. package/dist/lib/find-polymorphic-varients.test.js.map +7 -0
  11. package/dist/lib/find-unique-schema-name.js +16 -0
  12. package/dist/lib/find-unique-schema-name.js.map +7 -0
  13. package/dist/lib/for-each-operation.d.ts +3 -0
  14. package/dist/lib/for-each-operation.d.ts.map +1 -0
  15. package/dist/lib/for-each-operation.js +30 -0
  16. package/dist/lib/for-each-operation.js.map +7 -0
  17. package/dist/lib/format-name.js +86 -0
  18. package/dist/lib/format-name.js.map +7 -0
  19. package/dist/lib/get-ref-usage.d.ts +1 -1
  20. package/dist/lib/get-ref-usage.d.ts.map +1 -1
  21. package/dist/lib/get-ref-usage.js +52 -0
  22. package/dist/lib/get-ref-usage.js.map +7 -0
  23. package/dist/lib/is-primitive-schema.js +12 -0
  24. package/dist/lib/is-primitive-schema.js.map +7 -0
  25. package/dist/lib/is.d.ts +14 -0
  26. package/dist/lib/is.d.ts.map +1 -0
  27. package/dist/lib/is.js +71 -0
  28. package/dist/lib/is.js.map +7 -0
  29. package/dist/lib/loaders/load-spec.js +25 -0
  30. package/dist/lib/loaders/load-spec.js.map +7 -0
  31. package/dist/lib/loaders/local-loader.js +20 -0
  32. package/dist/lib/loaders/local-loader.js.map +7 -0
  33. package/dist/lib/loaders/postman/postman-converter.js +483 -0
  34. package/dist/lib/loaders/postman/postman-converter.js.map +7 -0
  35. package/dist/lib/loaders/postman/spec-types.js +1 -0
  36. package/dist/lib/loaders/postman/spec-types.js.map +7 -0
  37. package/dist/lib/loaders/remote-loader.js +29 -0
  38. package/dist/lib/loaders/remote-loader.js.map +7 -0
  39. package/dist/lib/metadata.js +51 -0
  40. package/dist/lib/metadata.js.map +7 -0
  41. package/dist/lib/operation.d.ts +4 -75
  42. package/dist/lib/operation.d.ts.map +1 -1
  43. package/dist/lib/operation.js +402 -0
  44. package/dist/lib/operation.js.map +7 -0
  45. package/dist/lib/operation.test.js +261 -0
  46. package/dist/lib/operation.test.js.map +7 -0
  47. package/dist/lib/options.d.ts +30 -0
  48. package/dist/lib/options.d.ts.map +1 -0
  49. package/dist/lib/options.js +54 -0
  50. package/dist/lib/options.js.map +7 -0
  51. package/dist/lib/overview-docs.d.ts +4 -0
  52. package/dist/lib/overview-docs.d.ts.map +1 -0
  53. package/dist/lib/overview-docs.js +276 -0
  54. package/dist/lib/overview-docs.js.map +7 -0
  55. package/dist/lib/pagination/pagination-result.js +235 -0
  56. package/dist/lib/pagination/pagination-result.js.map +7 -0
  57. package/dist/lib/pagination/pagination-result.test.js +548 -0
  58. package/dist/lib/pagination/pagination-result.test.js.map +7 -0
  59. package/dist/lib/pagination/pagination.d.ts +1 -1
  60. package/dist/lib/pagination/pagination.d.ts.map +1 -1
  61. package/dist/lib/pagination/pagination.js +222 -0
  62. package/dist/lib/pagination/pagination.js.map +7 -0
  63. package/dist/lib/pagination/pagination.test.js +378 -0
  64. package/dist/lib/pagination/pagination.test.js.map +7 -0
  65. package/dist/lib/reserved-keywords.d.ts +6 -0
  66. package/dist/lib/reserved-keywords.d.ts.map +1 -0
  67. package/dist/lib/reserved-keywords.js +71 -0
  68. package/dist/lib/reserved-keywords.js.map +7 -0
  69. package/dist/lib/security.d.ts +6 -4
  70. package/dist/lib/security.d.ts.map +1 -1
  71. package/dist/lib/security.js +75 -0
  72. package/dist/lib/security.js.map +7 -0
  73. package/dist/lib/sidebar.d.ts +5 -3
  74. package/dist/lib/sidebar.d.ts.map +1 -1
  75. package/dist/lib/sidebar.js +79 -0
  76. package/dist/lib/sidebar.js.map +7 -0
  77. package/dist/lib/tag.d.ts +19 -0
  78. package/dist/lib/tag.d.ts.map +1 -0
  79. package/dist/lib/tag.js +132 -0
  80. package/dist/lib/tag.js.map +7 -0
  81. package/dist/lib/tune.d.ts +1 -1
  82. package/dist/lib/tune.d.ts.map +1 -1
  83. package/dist/lib/tune.js +291 -0
  84. package/dist/lib/tune.js.map +7 -0
  85. package/dist/lib/tune.test.js +60 -0
  86. package/dist/lib/tune.test.js.map +7 -0
  87. package/dist/lib/types.d.ts +37 -0
  88. package/dist/lib/types.d.ts.map +1 -0
  89. package/dist/lib/types.js +1 -0
  90. package/dist/lib/types.js.map +7 -0
  91. package/package.json +4 -3
@@ -0,0 +1,291 @@
1
+ import { merge, uniq } from "lodash-es";
2
+ import assert from "node:assert";
3
+ import {
4
+ isEmpty,
5
+ isRef,
6
+ joinSkipDigits,
7
+ notRef,
8
+ pascalcase,
9
+ resolveRef,
10
+ snakecase
11
+ } from "@sdk-it/core";
12
+ import { findVarients } from "./find-polymorphic-varients.js";
13
+ import { findUniqueSchemaName } from "./find-unique-schema-name.js";
14
+ import { formatName } from "./format-name.js";
15
+ import { isPrimitiveSchema } from "./is-primitive-schema.js";
16
+ function fixSpec(spec, schemas, visited = /* @__PURE__ */ new Set()) {
17
+ for (const schema of schemas) {
18
+ if (isRef(schema)) continue;
19
+ if (!isEmpty(schema.properties)) {
20
+ schema.type = "object";
21
+ delete schema.oneOf;
22
+ delete schema.anyOf;
23
+ fixSpec(spec, Object.values(schema.properties), visited);
24
+ for (const [key, value] of Object.entries(schema.properties)) {
25
+ if (notRef(value) && isPrimitiveSchema(value)) {
26
+ value.default ??= schema.default?.[key];
27
+ delete schema.default?.[key];
28
+ }
29
+ }
30
+ delete schema.default;
31
+ }
32
+ if (!isEmpty(schema["x-properties"])) {
33
+ fixSpec(spec, Object.values(schema["x-properties"]), visited);
34
+ }
35
+ if (!isEmpty(schema.items)) {
36
+ delete schema.oneOf;
37
+ delete schema.anyOf;
38
+ schema.type = "array";
39
+ fixSpec(spec, [schema.items], visited);
40
+ const items = resolveRef(spec, schema.items);
41
+ if (Array.isArray(items.default)) {
42
+ schema.default ??= structuredClone(items.default);
43
+ }
44
+ delete items.default;
45
+ }
46
+ if (!isEmpty(schema.anyOf) && !isEmpty(schema.oneOf)) {
47
+ delete schema.anyOf;
48
+ }
49
+ if (isEmpty(schema.enum)) {
50
+ delete schema.enum;
51
+ }
52
+ if (!isEmpty(schema.enum)) {
53
+ if (schema.enum.length === 1) {
54
+ schema.const = schema.enum[0];
55
+ delete schema.enum;
56
+ } else {
57
+ const valuesSet = /* @__PURE__ */ new Set();
58
+ const valuesList = [];
59
+ for (const it of schema.enum) {
60
+ const formattedValue = formatName(snakecase(formatName(it)));
61
+ if (!valuesSet.has(formattedValue)) {
62
+ valuesSet.add(formattedValue);
63
+ valuesList.push(it);
64
+ }
65
+ }
66
+ schema.enum = valuesList;
67
+ }
68
+ delete schema.allOf;
69
+ }
70
+ if (schema.const !== void 0) {
71
+ schema.default = schema.const;
72
+ }
73
+ if (!isEmpty(schema.allOf)) {
74
+ const schemas2 = schema.allOf;
75
+ const resolved = schemas2.map((it) => resolveRef(spec, it));
76
+ const hasObjects = resolved.some((it) => it.type === "object");
77
+ const hasOtherTypes = resolved.some(
78
+ (it) => it.type && it.type !== "object"
79
+ );
80
+ if (hasObjects && hasOtherTypes) {
81
+ assert(false, `allOf must be an object`);
82
+ }
83
+ merge(
84
+ schema,
85
+ ...resolved.map((it) => {
86
+ fixSpec(spec, [it], visited);
87
+ return it;
88
+ })
89
+ );
90
+ delete schema.allOf;
91
+ } else {
92
+ delete schema.allOf;
93
+ }
94
+ if (schema.type === "object" && isEmpty(schema.properties) && typeof schema.additionalProperties === "object" && !isEmpty(schema.additionalProperties) && notRef(schema.additionalProperties) && !isEmpty(schema.additionalProperties.properties)) {
95
+ fixSpec(
96
+ spec,
97
+ Object.values(schema.additionalProperties.properties),
98
+ visited
99
+ );
100
+ Object.assign(schema, schema.additionalProperties);
101
+ delete schema.additionalProperties;
102
+ }
103
+ for (const kind of ["oneOf", "anyOf"]) {
104
+ if (!isEmpty(schema[kind])) {
105
+ delete schema.type;
106
+ fixSpec(spec, schema[kind], visited);
107
+ if (isEmpty(schema[kind])) {
108
+ continue;
109
+ }
110
+ let enumSchemaIndex = -1;
111
+ const enumValues = [];
112
+ for (let idx = 0; idx < schema[kind].length; idx++) {
113
+ const item = schema[kind][idx];
114
+ if (notRef(item) && item.type === "string") {
115
+ if (item.enum && item.enum.length > 1) {
116
+ enumValues.push(...item.enum);
117
+ if (enumSchemaIndex === -1) {
118
+ enumSchemaIndex = idx;
119
+ }
120
+ }
121
+ }
122
+ }
123
+ if (enumSchemaIndex !== -1) {
124
+ const enumSchema = schema[kind][enumSchemaIndex];
125
+ if (notRef(enumSchema)) {
126
+ enumSchema.enum = uniq(enumValues);
127
+ }
128
+ schema[kind] = schema[kind].filter(
129
+ (it, idx) => idx === enumSchemaIndex || isRef(it)
130
+ );
131
+ }
132
+ const otherTypes = schema[kind].filter(
133
+ (it) => resolveRef(spec, it).type !== "null"
134
+ );
135
+ if (otherTypes.length === 1) {
136
+ Object.assign(schema, otherTypes[0]);
137
+ delete schema[kind];
138
+ continue;
139
+ }
140
+ schema["x-varients"] = findVarients(spec, schema[kind]);
141
+ } else {
142
+ delete schema[kind];
143
+ }
144
+ }
145
+ }
146
+ }
147
+ function expandSpec(spec, schemas, refs) {
148
+ for (const [name, schema] of Object.entries(schemas)) {
149
+ if (isRef(schema)) continue;
150
+ if (!isEmpty(schema.properties)) {
151
+ if (!isEmpty(schema.oneOf)) {
152
+ for (const oneOfIdx in schema.oneOf) {
153
+ const oneOf = schema.oneOf[oneOfIdx];
154
+ if (isRef(oneOf)) continue;
155
+ for (const key of ["properties", "x-properties"]) {
156
+ if (!isEmpty(oneOf.required) && schema[key]) {
157
+ schema.oneOf[oneOfIdx] = schema[key][oneOf.required[0]];
158
+ }
159
+ }
160
+ }
161
+ delete schema.type;
162
+ expandSpec(spec, schemas, refs);
163
+ continue;
164
+ }
165
+ if (schema.additionalProperties) {
166
+ continue;
167
+ }
168
+ spec.components.schemas[name] = schema;
169
+ const properties = schema.properties;
170
+ for (const [propName, value] of Object.entries(properties)) {
171
+ if (isRef(value)) continue;
172
+ const fixedPropName = propName.replace("[]", "");
173
+ const refName = pascalcase(joinSkipDigits([name, fixedPropName], " "));
174
+ if (!isEmpty(value.properties)) {
175
+ spec.components.schemas[refName] = value;
176
+ properties[propName] = { $ref: `#/components/schemas/${refName}` };
177
+ expandSpec(spec, { [refName]: value }, refs);
178
+ } else if (!isEmpty(value.oneOf)) {
179
+ expandOneOf(spec, name, value, refs, "oneOf");
180
+ spec.components.schemas[refName] = value;
181
+ properties[propName] = { $ref: `#/components/schemas/${refName}` };
182
+ expandSpec(spec, { [refName]: value }, refs);
183
+ } else if (!isEmpty(value.anyOf)) {
184
+ expandOneOf(spec, name, value, refs, "anyOf");
185
+ spec.components.schemas[refName] = value;
186
+ properties[propName] = { $ref: `#/components/schemas/${refName}` };
187
+ expandSpec(spec, { [refName]: value }, refs);
188
+ } else {
189
+ expandSpec(spec, { [refName]: value }, refs);
190
+ }
191
+ }
192
+ continue;
193
+ }
194
+ if (!isEmpty(schema["x-properties"])) {
195
+ spec.components.schemas[name] = schema;
196
+ const properties = schema["x-properties"];
197
+ for (const [propName, value] of Object.entries(properties)) {
198
+ if (isRef(value)) continue;
199
+ const fixedPropName = propName.replace("[]", "");
200
+ const refName = pascalcase(joinSkipDigits([name, fixedPropName], " "));
201
+ if (!isEmpty(value.properties)) {
202
+ spec.components.schemas[refName] = value;
203
+ properties[propName] = { $ref: `#/components/schemas/${refName}` };
204
+ expandSpec(spec, { [refName]: value }, refs);
205
+ } else if (!isEmpty(value.oneOf)) {
206
+ expandOneOf(spec, name, value, refs, "oneOf");
207
+ spec.components.schemas[refName] = value;
208
+ properties[propName] = { $ref: `#/components/schemas/${refName}` };
209
+ expandSpec(spec, { [refName]: value }, refs);
210
+ } else if (!isEmpty(value.anyOf)) {
211
+ expandOneOf(spec, name, value, refs, "anyOf");
212
+ spec.components.schemas[refName] = value;
213
+ properties[propName] = { $ref: `#/components/schemas/${refName}` };
214
+ expandSpec(spec, { [refName]: value }, refs);
215
+ } else {
216
+ expandSpec(spec, { [refName]: value }, refs);
217
+ }
218
+ }
219
+ continue;
220
+ }
221
+ if (schema.type === "array") {
222
+ if (isRef(schema.items)) continue;
223
+ if (isEmpty(schema.items)) continue;
224
+ const refName = findUniqueSchemaName(spec, name, ["Item", "Entry"]);
225
+ if (schema.items.type === "object") {
226
+ spec.components.schemas[refName] = schema.items;
227
+ expandSpec(spec, { [refName]: schema.items }, refs);
228
+ schema.items = { $ref: `#/components/schemas/${refName}` };
229
+ continue;
230
+ }
231
+ if (schema.items.type === "array") {
232
+ expandSpec(spec, { [refName]: schema.items }, refs);
233
+ continue;
234
+ }
235
+ if (!isEmpty(schema.items.oneOf)) {
236
+ expandOneOf(spec, refName, schema.items, refs, "oneOf");
237
+ continue;
238
+ }
239
+ if (!isEmpty(schema.items.anyOf)) {
240
+ expandOneOf(spec, refName, schema.items, refs, "anyOf");
241
+ continue;
242
+ }
243
+ }
244
+ if (!isEmpty(schema.oneOf)) {
245
+ expandOneOf(spec, name, schema, refs, "oneOf");
246
+ continue;
247
+ }
248
+ if (!isEmpty(schema.anyOf)) {
249
+ expandOneOf(spec, name, schema, refs, "anyOf");
250
+ continue;
251
+ }
252
+ }
253
+ }
254
+ function expandOneOf(spec, name, schema, refs, kind) {
255
+ const varients = schema["x-varients"];
256
+ if (!varients || varients.length === 0) {
257
+ console.warn(
258
+ `No varients found for ${name}. This might be an error in the OpenAPI spec.`
259
+ );
260
+ }
261
+ varients.forEach((varient) => {
262
+ const varientSchema = schema[kind][varient.position];
263
+ if (isRef(varientSchema)) return;
264
+ const refName = findUniqueSchemaName(
265
+ spec,
266
+ pascalcase(`${name} ${varient.name}`),
267
+ ["Varient"]
268
+ );
269
+ if (varientSchema.type === "object") {
270
+ expandSpec(spec, { [refName]: varientSchema }, refs);
271
+ schema[kind][varient.position] = {
272
+ $ref: `#/components/schemas/${refName}`
273
+ };
274
+ } else {
275
+ expandSpec(spec, { [refName]: varientSchema }, refs);
276
+ }
277
+ });
278
+ }
279
+ function coerceTypes(schema, excludeNull = true) {
280
+ const types = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
281
+ if (excludeNull) {
282
+ return types.filter((type) => type !== "null");
283
+ }
284
+ return types;
285
+ }
286
+ export {
287
+ coerceTypes,
288
+ expandSpec,
289
+ fixSpec
290
+ };
291
+ //# sourceMappingURL=tune.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/lib/tune.ts"],
4
+ "sourcesContent": ["import { merge, uniq } from 'lodash-es';\nimport assert from 'node:assert';\nimport type {\n ReferenceObject,\n SchemaObject,\n SchemaObjectType,\n} from 'openapi3-ts/oas31';\n\nimport {\n isEmpty,\n isRef,\n joinSkipDigits,\n notRef,\n pascalcase,\n resolveRef,\n snakecase,\n} from '@sdk-it/core';\n\nimport { type Varient, findVarients } from './find-polymorphic-varients.js';\nimport { findUniqueSchemaName } from './find-unique-schema-name.js';\nimport { formatName } from './format-name.js';\nimport { isPrimitiveSchema } from './is-primitive-schema.js';\nimport type { OurOpenAPIObject } from './types.js';\n\nexport function fixSpec(\n spec: OurOpenAPIObject,\n schemas: (SchemaObject | ReferenceObject)[],\n visited = new Set<string>(),\n) {\n for (const schema of schemas) {\n if (isRef(schema)) continue;\n\n if (!isEmpty(schema.properties)) {\n schema.type = 'object';\n delete schema.oneOf;\n delete schema.anyOf;\n fixSpec(spec, Object.values(schema.properties), visited);\n // path param are required and if it happens to have\n // body with defaults then zod would break off. so flat the defaults from object itself to properties\n for (const [key, value] of Object.entries(schema.properties)) {\n if (notRef(value) && isPrimitiveSchema(value)) {\n value.default ??= schema.default?.[key];\n delete schema.default?.[key];\n }\n }\n delete schema.default; // default should not be in properties\n }\n\n if (!isEmpty(schema['x-properties'])) {\n fixSpec(spec, Object.values(schema['x-properties']), visited);\n }\n\n if (!isEmpty(schema.items)) {\n delete schema.oneOf;\n delete schema.anyOf;\n schema.type = 'array';\n fixSpec(spec, [schema.items], visited);\n const items = resolveRef<SchemaObject>(spec, schema.items);\n if (Array.isArray(items.default)) {\n schema.default ??= structuredClone(items.default);\n }\n delete items.default; // default should not be in items\n }\n\n if (!isEmpty(schema.anyOf) && !isEmpty(schema.oneOf)) {\n delete schema.anyOf;\n }\n\n if (isEmpty(schema.enum)) {\n delete schema.enum;\n }\n\n if (!isEmpty(schema.enum)) {\n if (schema.enum.length === 1) {\n schema.const = schema.enum[0];\n delete schema.enum;\n } else {\n const valuesSet = new Set<string>();\n const valuesList = [];\n for (const it of schema.enum) {\n const formattedValue = formatName(snakecase(formatName(it)));\n if (!valuesSet.has(formattedValue)) {\n valuesSet.add(formattedValue);\n valuesList.push(it);\n }\n }\n schema.enum = valuesList;\n }\n delete schema.allOf;\n }\n\n if (schema.const !== undefined) {\n schema.default = schema.const;\n }\n\n if (!isEmpty(schema.allOf)) {\n const schemas = schema.allOf;\n // if (schemas.length === 1) {\n // fixSpec(spec, [schemas[0]], visited);\n // Object.assign(schema, schemas[0]);\n // delete schema.allOf;\n // } else {\n // }\n const resolved = schemas.map((it) => resolveRef<SchemaObject>(spec, it));\n const hasObjects = resolved.some((it) => it.type === 'object');\n const hasOtherTypes = resolved.some(\n (it) => it.type && it.type !== 'object',\n );\n if (hasObjects && hasOtherTypes) {\n assert(false, `allOf must be an object`);\n }\n merge(\n schema,\n ...resolved.map((it) => {\n fixSpec(spec, [it], visited);\n return it;\n }),\n );\n delete schema.allOf;\n } else {\n delete schema.allOf;\n }\n\n if (\n schema.type === 'object' &&\n isEmpty(schema.properties) &&\n typeof schema.additionalProperties === 'object' &&\n !isEmpty(schema.additionalProperties) &&\n notRef(schema.additionalProperties) &&\n !isEmpty(schema.additionalProperties.properties)\n ) {\n // additionalProperties is of type object and properties is empty\n fixSpec(\n spec,\n Object.values(schema.additionalProperties.properties),\n visited,\n );\n Object.assign(schema, schema.additionalProperties);\n delete schema.additionalProperties;\n }\n\n for (const kind of ['oneOf', 'anyOf'] as const) {\n if (!isEmpty(schema[kind])) {\n delete schema.type; // type is not allowed with oneOf or anyOf\n fixSpec(spec, schema[kind], visited);\n if (isEmpty(schema[kind])) {\n // fixSpec can remove oneOf or anyOf if it has no items so we need to check again\n // after fixing\n continue;\n }\n\n let enumSchemaIndex = -1;\n const enumValues: string[] = [];\n for (let idx = 0; idx < schema[kind].length; idx++) {\n // for (const idx in schema[kind]) {\n const item = schema[kind][idx];\n // just handle non ref for now\n if (notRef(item) && item.type === 'string') {\n // if enum equal one it'd already have been converted to const so check for more than one\n if (item.enum && item.enum.length > 1) {\n // foundEnum = true;\n enumValues.push(...item.enum);\n if (enumSchemaIndex === -1) {\n enumSchemaIndex = idx;\n }\n }\n }\n }\n if (enumSchemaIndex !== -1) {\n const enumSchema = schema[kind][enumSchemaIndex];\n if (notRef(enumSchema)) {\n enumSchema.enum = uniq(enumValues);\n }\n // delete the other schemas that have enum\n schema[kind] = schema[kind].filter(\n (it, idx) => idx === enumSchemaIndex || isRef(it),\n );\n }\n const otherTypes = schema[kind].filter(\n (it) => resolveRef<SchemaObject>(spec, it).type !== 'null',\n );\n if (otherTypes.length === 1) {\n Object.assign(schema, otherTypes[0]);\n delete schema[kind];\n continue;\n }\n\n schema['x-varients'] = findVarients(spec, schema[kind]);\n } else {\n delete schema[kind];\n }\n }\n }\n}\n\ntype Refs = { name: string; value: SchemaObject }[];\n\nexport function expandSpec(\n spec: OurOpenAPIObject,\n schemas: Record<string, SchemaObject | ReferenceObject>,\n refs: Refs,\n) {\n for (const [name, schema] of Object.entries(schemas)) {\n if (isRef(schema)) continue;\n\n if (!isEmpty(schema.properties)) {\n if (!isEmpty(schema.oneOf)) {\n for (const oneOfIdx in schema.oneOf) {\n const oneOf = schema.oneOf[oneOfIdx];\n if (isRef(oneOf)) continue;\n for (const key of ['properties', 'x-properties'] as const) {\n if (!isEmpty(oneOf.required) && schema[key]) {\n schema.oneOf[oneOfIdx] = schema[key][oneOf.required[0]];\n }\n }\n }\n delete schema.type;\n expandSpec(spec, schemas, refs);\n continue;\n }\n if (schema.additionalProperties) {\n continue;\n }\n // refs.push({ name, value: schema });\n spec.components.schemas[name] = schema;\n const properties = schema.properties as Record<\n string,\n SchemaObject | ReferenceObject\n >;\n for (const [propName, value] of Object.entries(properties)) {\n if (isRef(value)) continue;\n\n const fixedPropName = propName.replace('[]', '');\n // this neeeds inheritance logic first otherwise it'll create class mess\n // const refName = findUniqueSchemaName(\n // spec,\n // propName,\n // ['Property', 'Field', 'Attribute'],\n // pascalcase(joinSkipDigits([name, fixedPropName], ' ')),\n // );\n const refName = pascalcase(joinSkipDigits([name, fixedPropName], ' '));\n\n if (!isEmpty(value.properties)) {\n // refs.push({ name: refName, value: value });\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.oneOf)) {\n expandOneOf(spec, name, value, refs, 'oneOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.anyOf)) {\n expandOneOf(spec, name, value, refs, 'anyOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else {\n expandSpec(spec, { [refName]: value }, refs);\n }\n }\n\n continue;\n }\n if (!isEmpty(schema['x-properties'])) {\n // refs.push({ name, value: schema });\n spec.components.schemas[name] = schema;\n\n const properties = schema['x-properties'] as Record<\n string,\n SchemaObject | ReferenceObject\n >;\n for (const [propName, value] of Object.entries(properties)) {\n if (isRef(value)) continue;\n\n const fixedPropName = propName.replace('[]', '');\n // this neeeds inheritance logic first otherwise it'll create class mess\n // const refName = findUniqueSchemaName(\n // spec,\n // propName,\n // ['Property', 'Field', 'Attribute'],\n // pascalcase(joinSkipDigits([name, fixedPropName], ' ')),\n // );\n const refName = pascalcase(joinSkipDigits([name, fixedPropName], ' '));\n\n if (!isEmpty(value.properties)) {\n // refs.push({ name: refName, value: value });\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.oneOf)) {\n expandOneOf(spec, name, value, refs, 'oneOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else if (!isEmpty(value.anyOf)) {\n expandOneOf(spec, name, value, refs, 'anyOf');\n\n spec.components.schemas[refName] = value;\n properties[propName] = { $ref: `#/components/schemas/${refName}` };\n expandSpec(spec, { [refName]: value }, refs);\n } else {\n expandSpec(spec, { [refName]: value }, refs);\n }\n }\n continue;\n }\n\n if (schema.type === 'array') {\n if (isRef(schema.items)) continue;\n if (isEmpty(schema.items)) continue;\n const refName = findUniqueSchemaName(spec, name, ['Item', 'Entry']);\n if (schema.items.type === 'object') {\n // const refName = findUniqueSchemaName(spec, name, ['Object']);\n // refs.push({ name: refName, value: schema.items });\n spec.components.schemas[refName] = schema.items;\n expandSpec(spec, { [refName]: schema.items }, refs);\n schema.items = { $ref: `#/components/schemas/${refName}` };\n continue;\n }\n if (schema.items.type === 'array') {\n // for nested arrays, we need to move the last nested items only\n // so {type: 'array', items: { type: 'array', items: { type: 'object', properties: ... } }}\n // only object schema is moved while the array hirarchy is intact.\n expandSpec(spec, { [refName]: schema.items }, refs);\n continue;\n }\n if (!isEmpty(schema.items.oneOf)) {\n expandOneOf(spec, refName, schema.items, refs, 'oneOf');\n continue;\n }\n if (!isEmpty(schema.items.anyOf)) {\n expandOneOf(spec, refName, schema.items, refs, 'anyOf');\n continue;\n }\n }\n if (!isEmpty(schema.oneOf)) {\n expandOneOf(spec, name, schema, refs, 'oneOf');\n continue;\n }\n if (!isEmpty(schema.anyOf)) {\n expandOneOf(spec, name, schema, refs, 'anyOf');\n continue;\n }\n }\n}\n\nfunction expandOneOf(\n spec: OurOpenAPIObject,\n name: string,\n schema: SchemaObject,\n refs: Refs,\n kind: 'oneOf' | 'anyOf',\n) {\n const varients = schema['x-varients'] as Varient[];\n if (!varients || varients.length === 0) {\n console.warn(\n `No varients found for ${name}. This might be an error in the OpenAPI spec.`,\n );\n }\n varients.forEach((varient) => {\n const varientSchema = schema[kind]![varient.position];\n if (isRef(varientSchema)) return;\n const refName = findUniqueSchemaName(\n spec,\n pascalcase(`${name} ${varient.name}`),\n ['Varient'],\n );\n\n if (varientSchema.type === 'object') {\n expandSpec(spec, { [refName]: varientSchema }, refs);\n schema[kind]![varient.position] = {\n $ref: `#/components/schemas/${refName}`,\n };\n } else {\n expandSpec(spec, { [refName]: varientSchema }, refs);\n }\n\n // const referable = (['array', 'object'] as SchemaObjectType[]).some((type) =>\n // coerceTypes(varientSchema).includes(type),\n // );\n // if (!referable) {\n // return;\n // }\n });\n}\n\nexport function coerceTypes(\n schema: SchemaObject,\n excludeNull = true,\n): SchemaObjectType[] {\n const types = Array.isArray(schema.type)\n ? schema.type\n : schema.type\n ? [schema.type]\n : [];\n if (excludeNull) {\n return types.filter((type) => type !== 'null');\n }\n return types;\n}\n"],
5
+ "mappings": "AAAA,SAAS,OAAO,YAAY;AAC5B,OAAO,YAAY;AAOnB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAuB,oBAAoB;AAC3C,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAG3B,SAAS,QACd,MACA,SACA,UAAU,oBAAI,IAAY,GAC1B;AACA,aAAW,UAAU,SAAS;AAC5B,QAAI,MAAM,MAAM,E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;AAC7C;AAAA,IACF;AACA,QAAI,CAAC,QAAQ,OAAO,KAAK,GAAG;AAC1B,kBAAY,MAAM,MAAM,QAAQ,MAAM,OAAO;AAC7C;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,YACP,MACA,MACA,QACA,MACA,MACA;AACA,QAAM,WAAW,OAAO,YAAY;AACpC,MAAI,CAAC,YAAY,SAAS,WAAW,GAAG;AACtC,YAAQ;AAAA,MACN,yBAAyB,IAAI;AAAA,IAC/B;AAAA,EACF;AACA,WAAS,QAAQ,CAAC,YAAY;AAC5B,UAAM,gBAAgB,OAAO,IAAI,EAAG,QAAQ,QAAQ;AACpD,QAAI,MAAM,aAAa,EAAG;AAC1B,UAAM,UAAU;AAAA,MACd;AAAA,MACA,WAAW,GAAG,IAAI,IAAI,QAAQ,IAAI,EAAE;AAAA,MACpC,CAAC,SAAS;AAAA,IACZ;AAEA,QAAI,cAAc,SAAS,UAAU;AACnC,iBAAW,MAAM,EAAE,CAAC,OAAO,GAAG,cAAc,GAAG,IAAI;AACnD,aAAO,IAAI,EAAG,QAAQ,QAAQ,IAAI;AAAA,QAChC,MAAM,wBAAwB,OAAO;AAAA,MACvC;AAAA,IACF,OAAO;AACL,iBAAW,MAAM,EAAE,CAAC,OAAO,GAAG,cAAc,GAAG,IAAI;AAAA,IACrD;AAAA,EAQF,CAAC;AACH;AAEO,SAAS,YACd,QACA,cAAc,MACM;AACpB,QAAM,QAAQ,MAAM,QAAQ,OAAO,IAAI,IACnC,OAAO,OACP,OAAO,OACL,CAAC,OAAO,IAAI,IACZ,CAAC;AACP,MAAI,aAAa;AACf,WAAO,MAAM,OAAO,CAAC,SAAS,SAAS,MAAM;AAAA,EAC/C;AACA,SAAO;AACT;",
6
+ "names": ["schemas"]
7
+ }
@@ -0,0 +1,60 @@
1
+ import { merge } from "lodash-es";
2
+ import { describe, it } from "node:test";
3
+ import { augmentSpec } from "./operation.ts";
4
+ function createSpec(openapi) {
5
+ return augmentSpec(
6
+ {
7
+ spec: merge(
8
+ {
9
+ openapi: "3.1.0",
10
+ info: {
11
+ title: "Test API",
12
+ version: "1.0.0"
13
+ },
14
+ components: {
15
+ schemas: {},
16
+ securitySchemes: {}
17
+ },
18
+ paths: {}
19
+ },
20
+ openapi
21
+ )
22
+ },
23
+ true
24
+ );
25
+ }
26
+ describe("merge allof", () => {
27
+ it("should handle circular allOf references without stack overflow", () => {
28
+ const spec = createSpec({
29
+ components: {
30
+ schemas: {
31
+ A: {
32
+ allOf: [
33
+ { $ref: "#/components/schemas/B" },
34
+ {
35
+ type: "object",
36
+ properties: {
37
+ nameA: { type: "string" }
38
+ }
39
+ }
40
+ ]
41
+ },
42
+ B: {
43
+ allOf: [
44
+ { $ref: "#/components/schemas/A" },
45
+ {
46
+ type: "object",
47
+ properties: {
48
+ nameB: { type: "string" }
49
+ }
50
+ }
51
+ ]
52
+ }
53
+ }
54
+ }
55
+ });
56
+ const schemaA = spec.components.schemas.A;
57
+ console.dir(spec.components.schemas, { depth: null });
58
+ });
59
+ });
60
+ //# sourceMappingURL=tune.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/lib/tune.test.ts"],
4
+ "sourcesContent": ["import { merge } from 'lodash-es';\nimport { describe, it } from 'node:test';\nimport type { OpenAPIObject, SchemaObject } from 'openapi3-ts/oas31';\n\nimport { augmentSpec } from './operation.ts';\nimport type { OurOpenAPIObject } from './types.ts';\n\nfunction createSpec(openapi?: Partial<OpenAPIObject>): OurOpenAPIObject {\n return augmentSpec(\n {\n spec: merge(\n {\n openapi: '3.1.0',\n info: {\n title: 'Test API',\n version: '1.0.0',\n },\n components: {\n schemas: {},\n securitySchemes: {},\n },\n paths: {},\n },\n openapi,\n ),\n },\n true,\n );\n}\n\ndescribe('merge allof', () => {\n // it('should merge allOf schemas', () => {\n // const spec = createSpec({\n // components: {\n // schemas: {\n // Base: {\n // type: 'object',\n // properties: {\n // id: { type: 'string' },\n // },\n // },\n // Extended: {\n // allOf: [\n // { $ref: '#/components/schemas/Base' },\n // {\n // type: 'object',\n // properties: {\n // name: { type: 'string' },\n // },\n // },\n // ],\n // },\n // },\n // },\n // });\n\n // const extendedSchema = spec.components.schemas.Extended as SchemaObject;\n // console.log(extendedSchema);\n // assert.deepStrictEqual(extendedSchema.type, 'object');\n // assert.deepStrictEqual(extendedSchema.properties, {\n // id: { type: 'string' },\n // name: { type: 'string' },\n // });\n // });\n // it('should handle empty allOf', () => {\n // const spec = createSpec({\n // components: {\n // schemas: {\n // EmptyAllOf: {\n // allOf: [],\n // },\n // },\n // },\n // });\n\n // const emptySchema = spec.components.schemas.EmptyAllOf as SchemaObject;\n // assert.deepStrictEqual(emptySchema.allOf, undefined);\n // assert.deepStrictEqual(emptySchema.type, undefined);\n // });\n // it('should handle allOf with only references', () => {\n // const spec = createSpec({\n // components: {\n // schemas: {\n // Base: {\n // type: 'object',\n // properties: {\n // id: { type: 'string' },\n // },\n // },\n // Extended: {\n // allOf: [\n // {\n // $ref: '#/components/schemas/Base',\n // },\n // ],\n // },\n // },\n // },\n // });\n\n // const extendedSchema = spec.components.schemas.Extended as SchemaObject;\n // assert.deepStrictEqual(extendedSchema.type, 'object');\n // assert.deepStrictEqual(extendedSchema.properties, {\n // id: {\n // type: 'string',\n // },\n // });\n // });\n\n it('should handle circular allOf references without stack overflow', () => {\n const spec = createSpec({\n components: {\n schemas: {\n A: {\n allOf: [\n { $ref: '#/components/schemas/B' },\n {\n type: 'object',\n properties: {\n nameA: { type: 'string' },\n },\n },\n ],\n },\n B: {\n allOf: [\n { $ref: '#/components/schemas/A' },\n {\n type: 'object',\n properties: {\n nameB: { type: 'string' },\n },\n },\n ],\n },\n },\n },\n });\n\n // This would cause a stack overflow with the current implementation\n const schemaA = spec.components.schemas.A as SchemaObject;\n console.dir(spec.components.schemas, { depth: null });\n // The test should not throw RangeError: Maximum call stack size exceeded\n });\n\n // it('should handle circular allOf references without stack overflow', () => {\n // const spec = createSpec({\n // components: {\n // schemas: {\n // A: {\n // allOf: [\n // { $ref: '#/components/schemas/B' },\n // {\n // type: 'object',\n // properties: {\n // nameA: { type: 'string' },\n // },\n // },\n // ],\n // },\n // B: {\n // allOf: [\n // { $ref: '#/components/schemas/A' },\n // {\n // type: 'object',\n // properties: {\n // nameB: { type: 'string' },\n // },\n // },\n // ],\n // },\n // },\n // },\n // });\n\n // // This would cause a stack overflow with the current implementation\n // const schemaA = spec.components.schemas.A as SchemaObject;\n // console.dir(spec.components.schemas, { depth: null });\n // // The test should not throw RangeError: Maximum call stack size exceeded\n // });\n\n // it('should handle self-referencing allOf', () => {\n // const spec = createSpec({\n // components: {\n // schemas: {\n // SelfRef: {\n // allOf: [\n // { $ref: '#/components/schemas/SelfRef' },\n // {\n // type: 'object',\n // properties: {\n // name: { type: 'string' },\n // },\n // },\n // ],\n // },\n // },\n // },\n // });\n\n // // This would also cause infinite recursion\n // const schema = spec.components.schemas.SelfRef as SchemaObject;\n // });\n});\n"],
5
+ "mappings": "AAAA,SAAS,aAAa;AACtB,SAAS,UAAU,UAAU;AAG7B,SAAS,mBAAmB;AAG5B,SAAS,WAAW,SAAoD;AACtE,SAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,QACJ;AAAA,UACE,SAAS;AAAA,UACT,MAAM;AAAA,YACJ,OAAO;AAAA,YACP,SAAS;AAAA,UACX;AAAA,UACA,YAAY;AAAA,YACV,SAAS,CAAC;AAAA,YACV,iBAAiB,CAAC;AAAA,UACpB;AAAA,UACA,OAAO,CAAC;AAAA,QACV;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,eAAe,MAAM;AA+E5B,KAAG,kEAAkE,MAAM;AACzE,UAAM,OAAO,WAAW;AAAA,MACtB,YAAY;AAAA,QACV,SAAS;AAAA,UACP,GAAG;AAAA,YACD,OAAO;AAAA,cACL,EAAE,MAAM,yBAAyB;AAAA,cACjC;AAAA,gBACE,MAAM;AAAA,gBACN,YAAY;AAAA,kBACV,OAAO,EAAE,MAAM,SAAS;AAAA,gBAC1B;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,UACA,GAAG;AAAA,YACD,OAAO;AAAA,cACL,EAAE,MAAM,yBAAyB;AAAA,cACjC;AAAA,gBACE,MAAM;AAAA,gBACN,YAAY;AAAA,kBACV,OAAO,EAAE,MAAM,SAAS;AAAA,gBAC1B;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAGD,UAAM,UAAU,KAAK,WAAW,QAAQ;AACxC,YAAQ,IAAI,KAAK,WAAW,SAAS,EAAE,OAAO,KAAK,CAAC;AAAA,EAEtD,CAAC;AA4DH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,37 @@
1
+ import type { ComponentsObject, MediaTypeObject, OpenAPIObject, OperationObject, ParameterObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, SchemaObject, SecuritySchemeObject } from 'openapi3-ts/oas31';
2
+ import type { SidebarData } from './sidebar.ts';
3
+ export interface OurOpenAPIObject extends OpenAPIObject {
4
+ 'x-sdk-augmented'?: boolean;
5
+ 'x-docs': SidebarData;
6
+ components: Omit<ComponentsObject, 'schemas'> & {
7
+ schemas: Record<string, SchemaObject | ReferenceObject>;
8
+ securitySchemes: Record<string, SecuritySchemeObject | ReferenceObject>;
9
+ };
10
+ paths: PathsObject;
11
+ }
12
+ export interface OurRequestBodyObject extends RequestBodyObject {
13
+ content: Record<string, Omit<MediaTypeObject, 'schema'> & {
14
+ schema: ReferenceObject;
15
+ }>;
16
+ }
17
+ export type TunedOperationObject = Omit<OperationObject, 'operationId' | 'tags' | 'parameters' | 'responses' | 'requestBody'> & {
18
+ tags: string[];
19
+ operationId: string;
20
+ parameters: ParameterObject[];
21
+ responses: Record<string, Omit<ResponseObject, 'content'> & {
22
+ content: Record<string, MediaTypeObject>;
23
+ }>;
24
+ requestBody: OurRequestBodyObject;
25
+ };
26
+ export interface OperationEntry {
27
+ name?: string;
28
+ method: string;
29
+ path: string;
30
+ groupName: string;
31
+ tag: string;
32
+ }
33
+ export type Operation = {
34
+ entry: OperationEntry;
35
+ operation: TunedOperationObject;
36
+ };
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,eAAe,EACf,eAAe,EACf,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,EAAE,WAAW,CAAC;IACtB,UAAU,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,GAAG;QAC9C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,eAAe,CAAC,CAAC;QACxD,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,eAAe,CAAC,CAAC;KACzE,CAAC;IACF,KAAK,EAAE,WAAW,CAAC;CACpB;AAED,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,OAAO,EAAE,MAAM,CACb,MAAM,EACN,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,GAAG;QAAE,MAAM,EAAE,eAAe,CAAA;KAAE,CAC9D,CAAC;CACH;AAED,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,eAAe,EACf,aAAa,GAAG,MAAM,GAAG,YAAY,GAAG,WAAW,GAAG,aAAa,CACpE,GAAG;IACF,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,SAAS,EAAE,MAAM,CACf,MAAM,EACN,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,GAAG;QAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;KAC1C,CACF,CAAC;IACF,WAAW,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;CACb;AACD,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,cAAc,CAAC;IACtB,SAAS,EAAE,oBAAoB,CAAC;CACjC,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdk-it/spec",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -26,7 +26,7 @@
26
26
  "!**/*.tsbuildinfo"
27
27
  ],
28
28
  "dependencies": {
29
- "@sdk-it/core": "0.22.0",
29
+ "@sdk-it/core": "0.23.0",
30
30
  "openapi3-ts": "4.4.0",
31
31
  "pluralize": "^8.0.0",
32
32
  "stringcase": "^4.3.1",
@@ -34,6 +34,7 @@
34
34
  "fast-content-type-parse": "^3.0.0",
35
35
  "lodash-es": "^4.17.21",
36
36
  "debug": "^4.4.1",
37
- "micromatch": "4.0.8"
37
+ "micromatch": "4.0.8",
38
+ "p-limit": "3.1.0"
38
39
  }
39
40
  }