@@ -27,16 +27,32 @@ class OpenAPI {
2727 } ;
2828 this . endpoints = [ ] ;
2929 this . debug = debug ;
30+
31+ if ( debug ) {
32+ this . log ( 'info' , 'OpenAPI instance created with debug mode enabled' ) ;
33+ }
3034 }
3135
32- private log ( level : string , message : string ) : void {
36+ // deno-lint-ignore no-explicit-any
37+ private log ( level : string , message : string , meta ?: any ) : void {
3338 if ( this . debug ) {
34- console . log ( `@murat/openapi [${ level } ] ${ message } ` ) ;
39+ const timestamp = new Date ( ) . toISOString ( ) ;
40+ const prefix = `@murat/openapi [${ timestamp } ] [${ level . toUpperCase ( ) } ]` ;
41+
42+ if ( meta ) {
43+ console . log ( `${ prefix } ${ message } ` , meta ) ;
44+ } else {
45+ console . log ( `${ prefix } ${ message } ` ) ;
46+ }
3547 }
3648 }
3749
3850 getJSON ( ) : OpenAPICore {
39- this . log ( 'info' , 'Generating OpenAPI JSON' ) ;
51+ this . log ( 'info' , 'Generating OpenAPI JSON' , {
52+ endpointCount : this . endpoints . length ,
53+ paths : this . raw . paths ? Object . keys ( this . raw . paths ) . length : 0 ,
54+ } ) ;
55+
4056 // Create a deep copy of the raw object
4157 const result = JSON . parse ( JSON . stringify ( this . raw ) ) as OpenAPICore ;
4258
@@ -48,10 +64,7 @@ class OpenAPI {
4864
4965 for ( const endpoint of this . endpoints ) {
5066 if ( ! endpoint . path || ! endpoint . method ) {
51- console . warn (
52- 'Endpoint is missing path or method, skipping' ,
53- endpoint
54- ) ;
67+ this . log ( 'error' , 'Endpoint is missing path or method, skipping' , endpoint ) ;
5568 continue ;
5669 }
5770
@@ -71,15 +84,23 @@ class OpenAPI {
7184
7285 // Add an array of endpoints
7386 addEndpoints ( endpoints : EndpointBuilder [ ] ) : this {
74- this . log ( 'info' , `Adding ${ endpoints . length } endpoints` ) ;
87+ this . log ( 'info' , `Adding ${ endpoints . length } endpoints` , {
88+ endpoints : endpoints . map ( e => `${ e . method || 'unknown' } ${ e . path || 'unknown' } ` )
89+ } ) ;
7590 endpoints . forEach ( this . addEndpoint . bind ( this ) ) ;
7691 return this ;
7792 }
7893
7994 // Add a single endpoint
8095 addEndpoint ( endpoint : EndpointBuilder ) : this {
8196 this . endpoints . push ( endpoint ) ;
82- this . log ( 'info' , `Endpoint added: ${ endpoint . method } ${ endpoint . path } ` ) ;
97+ this . log ( 'info' , `Endpoint added: ${ endpoint . method } ${ endpoint . path } ` , {
98+ operationId : endpoint . operation ?. operationId ,
99+ tags : endpoint . operation ?. tags ,
100+ hasParameters : ( endpoint . operation ?. parameters ?? [ ] ) . length > 0 ,
101+ hasRequestBody : ! ! endpoint . operation ?. requestBody ,
102+ responseStatusCodes : endpoint . operation ?. responses ? Object . keys ( endpoint . operation . responses ) : [ ]
103+ } ) ;
83104
84105 return this ;
85106 }
@@ -151,13 +172,20 @@ class OpenAPI {
151172 }
152173
153174 addEndpointPath ( endpointPath : EndpointPath ) : this {
154- this . log ( 'info' , `Adding endpoint path: ${ endpointPath . path } ` ) ;
175+ this . log ( 'info' , `Adding endpoint path: ${ endpointPath . path } ` , {
176+ operations : Object . keys ( endpointPath . pathItem ) ,
177+ parameters : endpointPath . pathItem . parameters ?. length
178+ } ) ;
179+
155180 if ( ! this . raw . paths ) {
156181 this . raw . paths = { } ;
157182 }
158183
159184 if ( this . raw . paths [ endpointPath . path ] ) {
160- this . log ( 'warn' , `Path ${ endpointPath . path } already exists, overwriting it` ) ;
185+ this . log ( 'warn' , `Path ${ endpointPath . path } already exists, overwriting it` , {
186+ existingOperations : Object . keys ( this . raw . paths [ endpointPath . path ] ) ,
187+ newOperations : Object . keys ( endpointPath . pathItem )
188+ } ) ;
161189 }
162190
163191 this . raw . paths [ endpointPath . path ] = endpointPath . pathItem ;
@@ -181,7 +209,10 @@ class OpenAPI {
181209 name : string ;
182210 scopes ?: string [ ] ;
183211 } ) : this {
184- this . log ( 'info' , `Setting security scheme: ${ scheme . name } (${ scheme . type } )` ) ;
212+ this . log (
213+ 'info' ,
214+ `Setting security scheme: ${ scheme . name } (${ scheme . type } )`
215+ ) ;
185216 if ( ! this . raw . security ) {
186217 this . raw . security = [ ] as never ;
187218 }
@@ -243,7 +274,14 @@ class OpenAPI {
243274 description ?: string ;
244275 }
245276 ) : this {
246- this . log ( 'info' , `Adding security schema: ${ name } (${ scheme . type } )` ) ;
277+ this . log ( 'info' , `Adding security schema: ${ name } (${ scheme . type } )` , {
278+ scheme : scheme . scheme ,
279+ bearerFormat : scheme . bearerFormat ,
280+ apiKeyName : scheme . name ,
281+ apiKeyIn : scheme . in ,
282+ hasFlows : ! ! scheme . flows
283+ } ) ;
284+
247285 if ( ! this . raw . components ) {
248286 this . raw . components = { securitySchemes : { } } ;
249287 }
0 commit comments