typed-openapi 2.2.3 → 2.2.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.
|
@@ -170,12 +170,20 @@ var openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }) => {
|
|
|
170
170
|
const objectType = additionalProperties ? t.intersection([t.object(props), additionalProperties]) : t.object(props);
|
|
171
171
|
return isPartial ? t.reference("Partial", [objectType]) : objectType;
|
|
172
172
|
}
|
|
173
|
-
if (!schemaType)
|
|
173
|
+
if (!schemaType) {
|
|
174
|
+
const nullableKey = Object.keys(schema).filter(
|
|
175
|
+
(key) => !["nullable"].includes(key)
|
|
176
|
+
);
|
|
177
|
+
if (nullableKey.length === 0 && schema.nullable) {
|
|
178
|
+
return t.literal("null");
|
|
179
|
+
}
|
|
180
|
+
return t.unknown();
|
|
181
|
+
}
|
|
174
182
|
throw new Error(`Unsupported schema type: ${schemaType}`);
|
|
175
183
|
};
|
|
176
184
|
let output = getTs();
|
|
177
185
|
if (!isReferenceObject(schema)) {
|
|
178
|
-
if (schema.nullable) {
|
|
186
|
+
if (schema.nullable && output.value !== "null") {
|
|
179
187
|
output = t.union([output, t.literal("null")]);
|
|
180
188
|
}
|
|
181
189
|
}
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
package/dist/node.export.js
CHANGED
package/package.json
CHANGED
|
@@ -180,7 +180,17 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
|
|
|
180
180
|
return isPartial ? t.reference("Partial", [objectType]) : objectType;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
if (!schemaType)
|
|
183
|
+
if (!schemaType) {
|
|
184
|
+
const nullableKey = Object.keys(schema).filter(
|
|
185
|
+
key => !['nullable'].includes(key)
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
if (nullableKey.length === 0 && (schema as LibSchemaObject).nullable) {
|
|
189
|
+
return t.literal("null");
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return t.unknown();
|
|
193
|
+
}
|
|
184
194
|
|
|
185
195
|
throw new Error(`Unsupported schema type: ${schemaType}`);
|
|
186
196
|
};
|
|
@@ -188,7 +198,7 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
|
|
|
188
198
|
let output = getTs();
|
|
189
199
|
if (!isReferenceObject(schema)) {
|
|
190
200
|
// OpenAPI 3.1 does not have nullable, but OpenAPI 3.0 does
|
|
191
|
-
if ((schema as LibSchemaObject).nullable) {
|
|
201
|
+
if ((schema as LibSchemaObject).nullable && output.value !== "null") {
|
|
192
202
|
output = t.union([output, t.literal("null")]);
|
|
193
203
|
}
|
|
194
204
|
}
|