1
- import type { GlobalContext , OpenAPI3 , OpenAPITSOptions , ParameterObject , SchemaObject , Subschema } from "./types.js" ;
1
+ import type { GlobalContext , OpenAPI3 , OpenAPITSOptions , SchemaObject , 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" ;
@@ -10,8 +10,9 @@ import transformParameterObjectArray from "./transform/parameter-object-array.js
10
10
import transformRequestBodyObject from "./transform/request-body-object.js" ;
11
11
import transformResponseObject from "./transform/response-object.js" ;
12
12
import transformSchemaObject from "./transform/schema-object.js" ;
13
+ import transformSchemaObjectMap from "./transform/schema-object-map.js" ;
13
14
import { error , escObjKey , getDefaultFetch , getEntries , getSchemaObjectComment , indent } from "./utils.js" ;
14
- import transformPathItemObject , { Method } from "./transform/path-item-object.js" ;
15
+
15
16
export * from "./types.js" ; // expose all types to consumers
16
17
17
18
const EMPTY_OBJECT_RE = / ^ \s * \{ ? \s * \} ? \s * $ / ;
@@ -184,43 +185,15 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
184
185
break ;
185
186
}
186
187
case "RequestBodyObject" : {
187
- subschemaOutput = transformRequestBodyObject ( subschema . schema , { path, ctx : { ...ctx , indentLv } } ) ;
188
+ subschemaOutput = ` ${ transformRequestBodyObject ( subschema . schema , { path, ctx : { ...ctx , indentLv } } ) } ;` ;
188
189
break ;
189
190
}
190
191
case "ResponseObject" : {
191
- subschemaOutput = transformResponseObject ( subschema . schema , { path, ctx : { ...ctx , indentLv } } ) ;
192
+ subschemaOutput = ` ${ transformResponseObject ( subschema . schema , { path, ctx : { ...ctx , indentLv } } ) } ;` ;
192
193
break ;
193
194
}
194
195
case "SchemaMap" : {
195
- subschemaOutput += "{\n" ;
196
- indentLv ++ ;
197
-
198
- outer: for ( const [ name , schemaObject ] of getEntries ( subschema . schema ! ) ) {
199
- if ( ! schemaObject || typeof schemaObject !== "object" ) continue ;
200
- const c = getSchemaObjectComment ( schemaObject as SchemaObject , indentLv ) ;
201
- if ( c ) subschemaOutput += indent ( c , indentLv ) ;
202
-
203
- // Test for Path Item Object
204
- if ( ! ( "type" in schemaObject ) && ! ( "$ref" in schemaObject ) ) {
205
- for ( const method of [ "get" , "put" , "post" , "delete" , "options" , "head" , "patch" , "trace" ] as Method [ ] ) {
206
- if ( method in schemaObject ) {
207
- subschemaOutput += indent ( `${ escObjKey ( name ) } : ${ transformPathItemObject ( schemaObject , { path : `${ path } ${ name } ` , ctx : { ...ctx , indentLv } } ) } ;\n` , indentLv ) ;
208
- continue outer;
209
- }
210
- }
211
- }
212
- // Test for Parameter
213
- if ( "in" in schemaObject ) {
214
- subschemaOutput += indent ( `${ escObjKey ( name ) } : ${ transformParameterObject ( schemaObject as ParameterObject , { path : `${ path } ${ name } ` , ctx : { ...ctx , indentLv } } ) } ;\n` , indentLv ) ;
215
- continue ;
216
- }
217
-
218
- // Otherwise, this is a Schema Object
219
- subschemaOutput += indent ( `${ escObjKey ( name ) } : ${ transformSchemaObject ( schemaObject , { path : `${ path } ${ name } ` , ctx : { ...ctx , indentLv } } ) } ;\n` , indentLv ) ;
220
- }
221
-
222
- indentLv -- ;
223
- subschemaOutput += indent ( "};" , indentLv ) ;
196
+ subschemaOutput = `${ transformSchemaObjectMap ( subschema . schema , { path, ctx : { ...ctx , indentLv } } ) } ;` ;
224
197
break ;
225
198
}
226
199
case "SchemaObject" : {
0 commit comments