openapi-typescript
Advanced tools
Comparing version 6.0.2 to 6.0.3
@@ -57,7 +57,9 @@ import { escObjKey, escStr, getEntries, getSchemaObjectComment, indent, parseRef, tsArrayOf, tsIntersectionOf, tsOmit, tsOneOf, tsOptionalProperty, tsReadonly, tsTupleOf, tsUnionOf, } from "../utils.js"; | ||
} | ||
if (schemaObject.type === "string" || schemaObject.type === "null" || schemaObject.type === "boolean") { | ||
if (schemaObject.type === "null") | ||
return schemaObject.type; | ||
if (schemaObject.type === "string" || schemaObject.type === "boolean") { | ||
return schemaObject.nullable ? tsUnionOf(schemaObject.type, "null") : schemaObject.type; | ||
} | ||
if (schemaObject.type === "number" || schemaObject.type === "integer") { | ||
return "number"; | ||
return schemaObject.nullable ? tsUnionOf("number", "null") : "number"; | ||
} | ||
@@ -89,2 +91,4 @@ if (schemaObject.type === "array") { | ||
itemType = tsArrayOf(itemType); | ||
if (schemaObject.nullable) | ||
itemType = tsUnionOf(itemType, "null"); | ||
return ctx.immutableTypes || schemaObject.readOnly ? tsReadonly(itemType) : itemType; | ||
@@ -113,4 +117,13 @@ } | ||
let addlType = "unknown"; | ||
if (typeof schemaObject.additionalProperties === "object") | ||
addlType = transformSchemaObject(schemaObject.additionalProperties, { path, ctx: { ...ctx, indentLv } }); | ||
if (typeof schemaObject.additionalProperties === "object") { | ||
if (!Object.keys(schemaObject.additionalProperties).length) { | ||
addlType = "unknown"; | ||
} | ||
else { | ||
addlType = transformSchemaObject(schemaObject.additionalProperties, { | ||
path, | ||
ctx: { ...ctx, indentLv }, | ||
}); | ||
} | ||
} | ||
coreType.push(indent(`[key: string]: ${tsUnionOf(addlType ? addlType : "unknown", "undefined")};`, indentLv)); | ||
@@ -117,0 +130,0 @@ } |
@@ -212,4 +212,8 @@ /// <reference types="node" /> | ||
type: "number"; | ||
minimum?: number; | ||
maximum?: number; | ||
} | { | ||
type: "integer"; | ||
minimum?: number; | ||
maximum?: number; | ||
} | { | ||
@@ -230,3 +234,3 @@ type: "array"; | ||
}; | ||
additionalProperties?: boolean | SchemaObject | ReferenceObject; | ||
additionalProperties?: boolean | Record<string, never> | SchemaObject | ReferenceObject; | ||
required?: string[]; | ||
@@ -233,0 +237,0 @@ allOf?: (SchemaObject | ReferenceObject)[]; |
{ | ||
"name": "openapi-typescript", | ||
"description": "Generate TypeScript types from Swagger OpenAPI specs", | ||
"version": "6.0.2", | ||
"version": "6.0.3", | ||
"author": "drew@pow.rs", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -106,10 +106,13 @@ import type { GlobalContext, ReferenceObject, SchemaObject } from "../types"; | ||
// "type": "null" | ||
if (schemaObject.type === "null") return schemaObject.type; | ||
// "type": "string" / "type": "null" | ||
if (schemaObject.type === "string" || schemaObject.type === "null" || schemaObject.type === "boolean") { | ||
return schemaObject.type; | ||
if (schemaObject.type === "string" || schemaObject.type === "boolean") { | ||
return schemaObject.nullable ? tsUnionOf(schemaObject.type, "null") : schemaObject.type; | ||
} | ||
// "type": "null" | ||
// "type": "number" / "type": "integer" | ||
if (schemaObject.type === "number" || schemaObject.type === "integer") { | ||
return "number"; | ||
return schemaObject.nullable ? tsUnionOf("number", "null") : "number"; | ||
} | ||
@@ -148,2 +151,3 @@ | ||
itemType = tsArrayOf(itemType); | ||
if (schemaObject.nullable) itemType = tsUnionOf(itemType, "null"); | ||
return ctx.immutableTypes || schemaObject.readOnly ? tsReadonly(itemType) : itemType; | ||
@@ -175,4 +179,12 @@ } | ||
let addlType = "unknown"; | ||
if (typeof schemaObject.additionalProperties === "object") | ||
addlType = transformSchemaObject(schemaObject.additionalProperties, { path, ctx: { ...ctx, indentLv } }); | ||
if (typeof schemaObject.additionalProperties === "object") { | ||
if (!Object.keys(schemaObject.additionalProperties).length) { | ||
addlType = "unknown"; | ||
} else { | ||
addlType = transformSchemaObject(schemaObject.additionalProperties as SchemaObject, { | ||
path, | ||
ctx: { ...ctx, indentLv }, | ||
}); | ||
} | ||
} | ||
coreType.push(indent(`[key: string]: ${tsUnionOf(addlType ? addlType : "unknown", "undefined")};`, indentLv)); // note: `| undefined` is required to mesh with possibly-undefined keys | ||
@@ -179,0 +191,0 @@ } |
@@ -426,4 +426,4 @@ import type { URL } from "node:url"; | ||
| { type: "string" } | ||
| { type: "number" } | ||
| { type: "integer" } | ||
| { type: "number"; minimum?: number; maximum?: number } | ||
| { type: "integer"; minimum?: number; maximum?: number } | ||
| { | ||
@@ -441,3 +441,3 @@ type: "array"; | ||
properties?: { [name: string]: SchemaObject | ReferenceObject }; | ||
additionalProperties?: boolean | SchemaObject | ReferenceObject; | ||
additionalProperties?: boolean | Record<string, never> | SchemaObject | ReferenceObject; | ||
required?: string[]; | ||
@@ -444,0 +444,0 @@ allOf?: (SchemaObject | ReferenceObject)[]; |
Sorry, the diff of this file is not supported yet
285453
4250