Skip to content

Commit 22895d2

Browse files
committed
restore
1 parent 4a59378 commit 22895d2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/openapi-typescript/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
117117
if (options.inject) output.push(options.inject);
118118

119119
// 2c. root schema
120+
const rootTypes = transformSchema(allSchemas["."].schema as OpenAPI3, ctx);
120121
const typedComponents = (allSchemas["."].schema as OpenAPI3).components!;
121122

122123
if (options.rootTypes) {
@@ -125,6 +126,16 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
125126
}
126127
}
127128

129+
for (const k of Object.keys(rootTypes)) {
130+
if (rootTypes[k] && !EMPTY_OBJECT_RE.test(rootTypes[k])) {
131+
output.push(options.exportType ? `export type ${k} = ${rootTypes[k]};` : `export interface ${k} ${rootTypes[k]}`, "");
132+
} else {
133+
output.push(`export type ${k} = Record<string, never>;`, "");
134+
}
135+
delete rootTypes[k];
136+
delete allSchemas["."]; // garbage collect, but also remove from next step (external)
137+
}
138+
128139
// 2d. external schemas (subschemas)
129140
const externalKeys = Object.keys(allSchemas); // root schema (".") should already be removed
130141
if (externalKeys.length) {

0 commit comments

Comments
 (0)