@sebspark/openapi-typegen 1.7.3 → 1.8.1
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 +22 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -552,7 +552,16 @@ var parseDocumentation = (source) => {
|
|
|
552
552
|
var parseSchemas = (schemas = {}) => Object.entries(schemas || {}).map(
|
|
553
553
|
([name, schema]) => parseSchema(name, schema)
|
|
554
554
|
);
|
|
555
|
-
var
|
|
555
|
+
var marshall = (type, format2) => {
|
|
556
|
+
if (type === "integer") {
|
|
557
|
+
return "number";
|
|
558
|
+
}
|
|
559
|
+
if (type === "string" && (format2 === "date" || format2 === "date-time")) {
|
|
560
|
+
return "Date";
|
|
561
|
+
}
|
|
562
|
+
return type;
|
|
563
|
+
};
|
|
564
|
+
var parseSchema = (name, schemaOrRef, generateDocs2 = true) => {
|
|
556
565
|
const ref = schemaOrRef.$ref;
|
|
557
566
|
if (ref) {
|
|
558
567
|
return { name, type: parseRef(ref) };
|
|
@@ -565,7 +574,7 @@ var parseSchema = (name, schemaOrRef) => {
|
|
|
565
574
|
case "integer":
|
|
566
575
|
case "number":
|
|
567
576
|
case "string":
|
|
568
|
-
return schema.enum ? parseEnumType(name, schema) : parsePropertyType(schema)[0];
|
|
577
|
+
return schema.enum ? parseEnumType(name, schema) : name ? { name, type: marshall(schema.type, schema.format) } : parsePropertyType(schema, generateDocs2)[0];
|
|
569
578
|
default:
|
|
570
579
|
return parseObjectSchema(name, schema);
|
|
571
580
|
}
|
|
@@ -584,13 +593,13 @@ var parseObjectSchema = (name, schema) => {
|
|
|
584
593
|
);
|
|
585
594
|
}
|
|
586
595
|
if (schema.allOf) {
|
|
587
|
-
type.allOf = schema.allOf.flatMap(parsePropertyType);
|
|
596
|
+
type.allOf = schema.allOf.flatMap((s) => parsePropertyType(s));
|
|
588
597
|
}
|
|
589
598
|
if (schema.oneOf) {
|
|
590
|
-
type.oneOf = schema.oneOf.flatMap(parsePropertyType);
|
|
599
|
+
type.oneOf = schema.oneOf.flatMap((s) => parsePropertyType(s));
|
|
591
600
|
}
|
|
592
601
|
if (schema.anyOf) {
|
|
593
|
-
type.oneOf = schema.anyOf.flatMap(parsePropertyType);
|
|
602
|
+
type.oneOf = schema.anyOf.flatMap((s) => parsePropertyType(s));
|
|
594
603
|
}
|
|
595
604
|
if ((_a = schema.discriminator) == null ? void 0 : _a.mapping) {
|
|
596
605
|
const mapping = {};
|
|
@@ -610,7 +619,7 @@ var parseArraySchema = (name, schema) => {
|
|
|
610
619
|
return {
|
|
611
620
|
name,
|
|
612
621
|
type: "array",
|
|
613
|
-
items: schema.items ?
|
|
622
|
+
items: schema.items ? parseSchema(void 0, schema.items, false) : { type: "unknown" },
|
|
614
623
|
...parseDocumentation(schema)
|
|
615
624
|
};
|
|
616
625
|
};
|
|
@@ -623,17 +632,18 @@ var parseProperty = (name, schema, required) => {
|
|
|
623
632
|
};
|
|
624
633
|
return property;
|
|
625
634
|
};
|
|
626
|
-
var parsePropertyType = (property) => {
|
|
635
|
+
var parsePropertyType = (property, generateDocs2 = true) => {
|
|
627
636
|
const ref = property.$ref;
|
|
628
637
|
if (ref) {
|
|
629
638
|
return [{ type: parseRef(ref) }];
|
|
630
639
|
}
|
|
631
640
|
const schemaObject = property;
|
|
641
|
+
const docs = generateDocs2 ? parseDocumentation(schemaObject) : {};
|
|
632
642
|
if (schemaObject.enum) {
|
|
633
643
|
const enumType = {
|
|
634
644
|
type: "enum",
|
|
635
645
|
values: schemaObject.enum,
|
|
636
|
-
...
|
|
646
|
+
...docs
|
|
637
647
|
};
|
|
638
648
|
return [enumType];
|
|
639
649
|
}
|
|
@@ -646,22 +656,11 @@ var parsePropertyType = (property) => {
|
|
|
646
656
|
case "object": {
|
|
647
657
|
return parseObjectSchema(void 0, schemaObject);
|
|
648
658
|
}
|
|
649
|
-
case "integer": {
|
|
650
|
-
return { type: "number", ...parseDocumentation(schemaObject) };
|
|
651
|
-
}
|
|
652
|
-
case "string": {
|
|
653
|
-
switch (schemaObject.format) {
|
|
654
|
-
case "date":
|
|
655
|
-
case "date-time": {
|
|
656
|
-
return { type: "Date", ...parseDocumentation(schemaObject) };
|
|
657
|
-
}
|
|
658
|
-
default: {
|
|
659
|
-
return { type, ...parseDocumentation(schemaObject) };
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
659
|
default: {
|
|
664
|
-
return {
|
|
660
|
+
return {
|
|
661
|
+
type: marshall(type, schemaObject.format),
|
|
662
|
+
...docs
|
|
663
|
+
};
|
|
665
664
|
}
|
|
666
665
|
}
|
|
667
666
|
});
|