typed-openapi 2.2.2 → 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.
|
@@ -132,7 +132,7 @@ var openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }) => {
|
|
|
132
132
|
}
|
|
133
133
|
if (schemaType === "object" || schema.properties || schema.additionalProperties) {
|
|
134
134
|
if (!schema.properties) {
|
|
135
|
-
if (schema.additionalProperties && !isReferenceObject(schema.additionalProperties) && typeof schema.additionalProperties !== "boolean"
|
|
135
|
+
if (schema.additionalProperties && !isReferenceObject(schema.additionalProperties) && typeof schema.additionalProperties !== "boolean") {
|
|
136
136
|
const valueSchema = openApiSchemaToTs({ schema: schema.additionalProperties, ctx, meta });
|
|
137
137
|
return t.literal(`Record<string, ${valueSchema.value}>`);
|
|
138
138
|
}
|
|
@@ -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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typed-openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.4",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@types/node": "^22.15.17",
|
|
35
35
|
"@types/prettier": "3.0.0",
|
|
36
36
|
"msw": "2.10.5",
|
|
37
|
-
"tstyche": "
|
|
37
|
+
"tstyche": "5.0.0",
|
|
38
38
|
"tsup": "^8.4.0",
|
|
39
39
|
"typescript": "^5.8.3",
|
|
40
40
|
"vitest": "^3.1.3",
|
|
@@ -126,8 +126,7 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
|
|
|
126
126
|
if (
|
|
127
127
|
schema.additionalProperties &&
|
|
128
128
|
!isReferenceObject(schema.additionalProperties) &&
|
|
129
|
-
typeof schema.additionalProperties !== "boolean"
|
|
130
|
-
schema.additionalProperties.type
|
|
129
|
+
typeof schema.additionalProperties !== "boolean"
|
|
131
130
|
) {
|
|
132
131
|
const valueSchema = openApiSchemaToTs({ schema: schema.additionalProperties, ctx, meta });
|
|
133
132
|
return t.literal(`Record<string, ${valueSchema.value}>`);
|
|
@@ -181,7 +180,17 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
|
|
|
181
180
|
return isPartial ? t.reference("Partial", [objectType]) : objectType;
|
|
182
181
|
}
|
|
183
182
|
|
|
184
|
-
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
|
+
}
|
|
185
194
|
|
|
186
195
|
throw new Error(`Unsupported schema type: ${schemaType}`);
|
|
187
196
|
};
|
|
@@ -189,7 +198,7 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
|
|
|
189
198
|
let output = getTs();
|
|
190
199
|
if (!isReferenceObject(schema)) {
|
|
191
200
|
// OpenAPI 3.1 does not have nullable, but OpenAPI 3.0 does
|
|
192
|
-
if ((schema as LibSchemaObject).nullable) {
|
|
201
|
+
if ((schema as LibSchemaObject).nullable && output.value !== "null") {
|
|
193
202
|
output = t.union([output, t.literal("null")]);
|
|
194
203
|
}
|
|
195
204
|
}
|