1
- import type { GlobalContext , OpenAPI3 , OpenAPITSOptions , Subschema } from "./types.js" ;
1
+ import type { ComponentsObject , GlobalContext , OpenAPI3 , OpenAPITSOptions , Subschema } from "./types.js" ;
2
2
import type { Readable } from "node:stream" ;
3
3
import { URL } from "node:url" ;
4
4
import load , { resolveSchema , VIRTUAL_JSON_URL } from "./load.js" ;
@@ -12,6 +12,7 @@ import transformResponseObject from "./transform/response-object.js";
12
12
import transformSchemaObject from "./transform/schema-object.js" ;
13
13
import { error , escObjKey , getDefaultFetch , getEntries , getSchemaObjectComment , indent } from "./utils.js" ;
14
14
import transformPathItemObject , { Method } from "./transform/path-item-object.js" ;
15
+ import transformComponentsObjectToTypes from "./transform/components-types.js" ;
15
16
export * from "./types.js" ; // expose all types to consumers
16
17
17
18
const EMPTY_OBJECT_RE = / ^ \s * \{ ? \s * \} ? \s * $ / ;
@@ -101,6 +102,8 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
101
102
if ( options . inject ) output . push ( options . inject ) ;
102
103
103
104
// 2c. root schema
105
+ const types = transformComponentsObjectToTypes ( ( allSchemas [ "." ] . schema as OpenAPI3 ) . components ! , ctx ) ;
106
+
104
107
const rootTypes = transformSchema ( allSchemas [ "." ] . schema as OpenAPI3 , ctx ) ;
105
108
for ( const k of Object . keys ( rootTypes ) ) {
106
109
if ( rootTypes [ k ] && ! EMPTY_OBJECT_RE . test ( rootTypes [ k ] ) ) {
@@ -253,7 +256,7 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
253
256
output . splice ( 1 , 0 , "/** WithRequired type helpers */" , "type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };" , "" ) ;
254
257
}
255
258
256
- return output . join ( "\n" ) ;
259
+ return output . join ( "\n" ) . concat ( types ) ;
257
260
}
258
261
259
262
export default openapiTS ;
0 commit comments