typed-openapi 1.4.3 → 1.4.4
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.
|
@@ -102,6 +102,17 @@ var openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }) => {
|
|
|
102
102
|
if (schemaType === "number" || schemaType === "integer") return t.number();
|
|
103
103
|
if (schemaType === "null") return t.literal("null");
|
|
104
104
|
}
|
|
105
|
+
if (!schemaType && schema.enum) {
|
|
106
|
+
return t.union(schema.enum.map((value) => {
|
|
107
|
+
if (typeof value === "string") {
|
|
108
|
+
return t.literal(`"${value}"`);
|
|
109
|
+
}
|
|
110
|
+
if (value === null) {
|
|
111
|
+
return t.literal("null");
|
|
112
|
+
}
|
|
113
|
+
return t.literal(value);
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
105
116
|
if (schemaType === "array") {
|
|
106
117
|
if (schema.items) {
|
|
107
118
|
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
|
@@ -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) {
|