typed-openapi 1.4.2 → 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.
|
@@ -77,7 +77,17 @@ var openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }) => {
|
|
|
77
77
|
if (schema.enum) {
|
|
78
78
|
if (schema.enum.length === 1) {
|
|
79
79
|
const value = schema.enum[0];
|
|
80
|
-
|
|
80
|
+
if (value === null) {
|
|
81
|
+
return t.literal("null");
|
|
82
|
+
} else if (value === true) {
|
|
83
|
+
return t.literal("true");
|
|
84
|
+
} else if (value === false) {
|
|
85
|
+
return t.literal("false");
|
|
86
|
+
} else if (typeof value === "number") {
|
|
87
|
+
return t.literal(`${value}`);
|
|
88
|
+
} else {
|
|
89
|
+
return t.literal(`"${value}"`);
|
|
90
|
+
}
|
|
81
91
|
}
|
|
82
92
|
if (schemaType === "string") {
|
|
83
93
|
return t.union(schema.enum.map((value) => t.literal(`"${value}"`)));
|
|
@@ -92,6 +102,17 @@ var openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }) => {
|
|
|
92
102
|
if (schemaType === "number" || schemaType === "integer") return t.number();
|
|
93
103
|
if (schemaType === "null") return t.literal("null");
|
|
94
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
|
+
}
|
|
95
116
|
if (schemaType === "array") {
|
|
96
117
|
if (schema.items) {
|
|
97
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
|
@@ -65,7 +65,17 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
|
|
|
65
65
|
if (schema.enum) {
|
|
66
66
|
if (schema.enum.length === 1) {
|
|
67
67
|
const value = schema.enum[0];
|
|
68
|
-
|
|
68
|
+
if (value === null) {
|
|
69
|
+
return t.literal("null");
|
|
70
|
+
} else if (value === true) {
|
|
71
|
+
return t.literal("true");
|
|
72
|
+
} else if (value === false) {
|
|
73
|
+
return t.literal("false");
|
|
74
|
+
} else if (typeof value === "number") {
|
|
75
|
+
return t.literal(`${value}`)
|
|
76
|
+
} else {
|
|
77
|
+
return t.literal(`"${value}"`);
|
|
78
|
+
}
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
if (schemaType === "string") {
|
|
@@ -84,6 +94,18 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
|
|
|
84
94
|
if (schemaType === "number" || schemaType === "integer") return t.number();
|
|
85
95
|
if (schemaType === "null") return t.literal("null");
|
|
86
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
|
+
}
|
|
87
109
|
|
|
88
110
|
if (schemaType === "array") {
|
|
89
111
|
if (schema.items) {
|