@sebspark/openapi-typegen 1.8.5 → 1.10.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.
- package/dist/index.js +27 -0
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -157,6 +157,10 @@ var generateType = (parsed) => {
|
|
|
157
157
|
type = generateObject(parsed);
|
|
158
158
|
break;
|
|
159
159
|
}
|
|
160
|
+
case "record": {
|
|
161
|
+
type = generateRecord(parsed);
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
160
164
|
case "unknown": {
|
|
161
165
|
type = generateUnknown(parsed);
|
|
162
166
|
break;
|
|
@@ -241,6 +245,10 @@ var generateObject = (parsed) => {
|
|
|
241
245
|
}
|
|
242
246
|
return lines.join("\n");
|
|
243
247
|
};
|
|
248
|
+
var generateRecord = (parsed) => {
|
|
249
|
+
const itemType = parsed.items.type === "undefined" ? "unknown" : generateType(parsed.items);
|
|
250
|
+
return `Record<string, ${itemType}>`;
|
|
251
|
+
};
|
|
244
252
|
var generateDiscriminator = (discriminator, name) => {
|
|
245
253
|
const lines = [""];
|
|
246
254
|
lines.push(`export type ${name}Discriminator = {`);
|
|
@@ -593,8 +601,27 @@ var parseObjectSchema = (name, schema) => {
|
|
|
593
601
|
mapping
|
|
594
602
|
};
|
|
595
603
|
}
|
|
604
|
+
if (schema.additionalProperties) {
|
|
605
|
+
const record = parseAdditionalProperties(schema.additionalProperties);
|
|
606
|
+
if (!type.allOf) {
|
|
607
|
+
type.allOf = [];
|
|
608
|
+
}
|
|
609
|
+
type.allOf.push(record);
|
|
610
|
+
}
|
|
596
611
|
return type;
|
|
597
612
|
};
|
|
613
|
+
var parseAdditionalProperties = (schema) => {
|
|
614
|
+
let items;
|
|
615
|
+
if (schema === true) {
|
|
616
|
+
items = { type: "undefined" };
|
|
617
|
+
} else {
|
|
618
|
+
items = parseSchema(void 0, schema);
|
|
619
|
+
}
|
|
620
|
+
return {
|
|
621
|
+
type: "record",
|
|
622
|
+
items
|
|
623
|
+
};
|
|
624
|
+
};
|
|
598
625
|
var parseArraySchema = (name, schema) => {
|
|
599
626
|
if (schema.type !== "array") throw new Error("Not an array");
|
|
600
627
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/openapi-typegen",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"change-case": "4.1.2",
|
|
30
30
|
"prettier": "3.3.2",
|
|
31
31
|
"yaml": "2.5.0",
|
|
32
|
-
"yargs": "17.7.2"
|
|
33
|
-
"yarn": "1.22.22"
|
|
32
|
+
"yargs": "17.7.2"
|
|
34
33
|
}
|
|
35
34
|
}
|