typed-openapi 1.4.3 → 1.4.5
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.
|
@@ -66,10 +66,11 @@ var openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }) => {
|
|
|
66
66
|
return t.union(schema.anyOf.map((prop) => openApiSchemaToTs({ schema: prop, ctx, meta })));
|
|
67
67
|
}
|
|
68
68
|
if (schema.allOf) {
|
|
69
|
-
if (schema.allOf.length === 1) {
|
|
70
|
-
return openApiSchemaToTs({ schema: schema.allOf[0], ctx, meta });
|
|
71
|
-
}
|
|
72
69
|
const types = schema.allOf.map((prop) => openApiSchemaToTs({ schema: prop, ctx, meta }));
|
|
70
|
+
const { allOf, externalDocs, example, examples, description, title, ...rest } = schema;
|
|
71
|
+
if (Object.keys(rest).length > 0) {
|
|
72
|
+
types.push(openApiSchemaToTs({ schema: rest, ctx, meta }));
|
|
73
|
+
}
|
|
73
74
|
return t.intersection(types);
|
|
74
75
|
}
|
|
75
76
|
const schemaType = schema.type ? schema.type.toLowerCase() : void 0;
|
|
@@ -102,6 +103,17 @@ var openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }) => {
|
|
|
102
103
|
if (schemaType === "number" || schemaType === "integer") return t.number();
|
|
103
104
|
if (schemaType === "null") return t.literal("null");
|
|
104
105
|
}
|
|
106
|
+
if (!schemaType && schema.enum) {
|
|
107
|
+
return t.union(schema.enum.map((value) => {
|
|
108
|
+
if (typeof value === "string") {
|
|
109
|
+
return t.literal(`"${value}"`);
|
|
110
|
+
}
|
|
111
|
+
if (value === null) {
|
|
112
|
+
return t.literal("null");
|
|
113
|
+
}
|
|
114
|
+
return t.literal(value);
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
105
117
|
if (schemaType === "array") {
|
|
106
118
|
if (schema.items) {
|
|
107
119
|
let arrayOfType = openApiSchemaToTs({ schema: schema.items, ctx, meta });
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
package/dist/node.export.js
CHANGED
package/package.json
CHANGED
|
@@ -52,11 +52,11 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if (schema.allOf) {
|
|
55
|
-
if (schema.allOf.length === 1) {
|
|
56
|
-
return openApiSchemaToTs({ schema: schema.allOf[0]!, ctx, meta });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
55
|
const types = schema.allOf.map((prop) => openApiSchemaToTs({ schema: prop, ctx, meta }));
|
|
56
|
+
const {allOf, externalDocs, example, examples, description, title, ...rest} = schema
|
|
57
|
+
if (Object.keys(rest).length > 0) {
|
|
58
|
+
types.push(openApiSchemaToTs({schema: rest, ctx, meta}))
|
|
59
|
+
}
|
|
60
60
|
return t.intersection(types);
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -94,6 +94,18 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
|
|
|
94
94
|
if (schemaType === "number" || schemaType === "integer") return t.number();
|
|
95
95
|
if (schemaType === "null") return t.literal("null");
|
|
96
96
|
}
|
|
97
|
+
if (!schemaType && schema.enum) {
|
|
98
|
+
return t.union(schema.enum.map((value) => {
|
|
99
|
+
if (typeof value === "string") {
|
|
100
|
+
return t.literal(`"${value}"`)
|
|
101
|
+
}
|
|
102
|
+
if (value === null) {
|
|
103
|
+
return t.literal("null")
|
|
104
|
+
}
|
|
105
|
+
// handle boolean and number literals
|
|
106
|
+
return t.literal(value)
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
97
109
|
|
|
98
110
|
if (schemaType === "array") {
|
|
99
111
|
if (schema.items) {
|