File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
packages/openapi-typescript/src Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,7 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
117
117
if ( options . inject ) output . push ( options . inject ) ;
118
118
119
119
// 2c. root schema
120
+ const rootTypes = transformSchema ( allSchemas [ "." ] . schema as OpenAPI3 , ctx ) ;
120
121
const typedComponents = ( allSchemas [ "." ] . schema as OpenAPI3 ) . components ! ;
121
122
122
123
if ( options . rootTypes ) {
@@ -125,6 +126,16 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
125
126
}
126
127
}
127
128
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
+
128
139
// 2d. external schemas (subschemas)
129
140
const externalKeys = Object . keys ( allSchemas ) ; // root schema (".") should already be removed
130
141
if ( externalKeys . length ) {
You can’t perform that action at this time.
0 commit comments