@@ -388,6 +388,51 @@ function resolveResponse (fastifyResponseJson, produces, ref) {
388388 return responsesContainer
389389}
390390
391+ function resolveCallbacks ( schema , ref ) {
392+ const callbacksContainer = { }
393+
394+ for ( const eventName in schema ) {
395+ if ( ! schema [ eventName ] ) {
396+ continue
397+ }
398+
399+ const eventSchema = schema [ eventName ]
400+ const [ callbackUrl ] = Object . keys ( eventSchema )
401+
402+ if ( ! callbackUrl || ! eventSchema [ callbackUrl ] ) {
403+ continue
404+ }
405+
406+ const callbackSchema = schema [ eventName ] [ callbackUrl ]
407+ const [ httpMethodName ] = Object . keys ( callbackSchema )
408+
409+ if ( ! httpMethodName || ! callbackSchema [ httpMethodName ] ) {
410+ continue
411+ }
412+
413+ const httpMethodSchema = callbackSchema [ httpMethodName ]
414+ const httpMethodContainer = { }
415+
416+ if ( httpMethodSchema . requestBody ) {
417+ httpMethodContainer . requestBody = convertJsonSchemaToOpenapi3 (
418+ ref . resolve ( httpMethodSchema . requestBody )
419+ )
420+ }
421+
422+ httpMethodContainer . responses = httpMethodSchema . responses
423+ ? convertJsonSchemaToOpenapi3 ( ref . resolve ( httpMethodSchema . responses ) )
424+ : { '2XX' : { description : 'Default Response' } }
425+
426+ callbacksContainer [ eventName ] = {
427+ [ callbackUrl ] : {
428+ [ httpMethodName ] : httpMethodContainer
429+ }
430+ }
431+ }
432+
433+ return callbacksContainer
434+ }
435+
391436function prepareOpenapiMethod ( schema , ref , openapiObject , url ) {
392437 const openapiMethod = { }
393438 const parameters = [ ]
@@ -432,6 +477,7 @@ function prepareOpenapiMethod (schema, ref, openapiObject, url) {
432477 if ( schema . deprecated ) openapiMethod . deprecated = schema . deprecated
433478 if ( schema . security ) openapiMethod . security = schema . security
434479 if ( schema . servers ) openapiMethod . servers = schema . servers
480+ if ( schema . callbacks ) openapiMethod . callbacks = resolveCallbacks ( schema . callbacks , ref )
435481 for ( const key of Object . keys ( schema ) ) {
436482 if ( key . startsWith ( 'x-' ) ) {
437483 openapiMethod [ key ] = schema [ key ]
0 commit comments