@@ -167,11 +167,12 @@ class DefinitionGenerator {
167167
168168 if ( documentation . contact ) {
169169 const contactObj = { } ;
170- contactObj . name = documentation . contact . name || "" ;
170+
171+ if ( documentation . contact . name ) contactObj . name = documentation . contact . name ;
171172
172173 if ( documentation . contact . url ) contactObj . url = documentation . contact . url ;
173174
174- contactObj . email = documentation . contact . email || "" ;
175+ if ( documentation . contact . email ) contactObj . email = documentation . contact . email ;
175176
176177 const extendedSpec = this . extendSpecification ( documentation . contact ) ;
177178
@@ -591,7 +592,9 @@ class DefinitionGenerator {
591592 obj . headers = corsHeaders ;
592593 addHeaders ( owaspHeaders ) ;
593594 } else {
594- obj . headers = owaspHeaders ;
595+ if ( Object . keys ( owaspHeaders ) . length ) {
596+ obj . headers = owaspHeaders ;
597+ }
595598 }
596599 }
597600
@@ -677,10 +680,13 @@ class DefinitionGenerator {
677680
678681 async createRequestBody ( requestBodyDetails ) {
679682 const obj = {
680- description : requestBodyDetails . description ,
681683 required : requestBodyDetails . required || false ,
682684 } ;
683685
686+ if ( requestBodyDetails . description ) {
687+ obj . description = requestBodyDetails . description ;
688+ }
689+
684690 obj . content = await this . createMediaTypeObject (
685691 requestBodyDetails . models
686692 ) . catch ( ( err ) => {
@@ -692,56 +698,60 @@ class DefinitionGenerator {
692698
693699 async createMediaTypeObject ( models , type ) {
694700 const mediaTypeObj = { } ;
695-
696701 for ( const mediaTypeDocumentation of this . schemaHandler . models ) {
697702 if ( models === undefined || models === null ) {
698703 throw new Error (
699704 `${ this . currentFunctionName } is missing a Response Model for statusCode ${ this . currentStatusCode } `
700705 ) ;
701706 }
702707
703- if ( Object . values ( models ) . includes ( mediaTypeDocumentation . name ) ) {
704- let contentKey = "" ;
705- for ( const [ key , value ] of Object . entries ( models ) ) {
706- if ( value === mediaTypeDocumentation . name ) contentKey = key ;
708+ for ( const modelContentType in models ) {
709+ let contentKey
710+
711+ if ( models [ modelContentType ] === mediaTypeDocumentation . name ) {
712+ contentKey = modelContentType ;
707713 }
708- const obj = { } ;
709714
710- let schema ;
711- if ( mediaTypeDocumentation ?. content ) {
712- if ( mediaTypeDocumentation . content [ contentKey ] ?. example )
713- obj . example = mediaTypeDocumentation . content [ contentKey ] . example ;
715+ if ( contentKey ) {
714716
715- if ( mediaTypeDocumentation . content [ contentKey ] ?. examples )
716- obj . examples = this . createExamples (
717- mediaTypeDocumentation . content [ contentKey ] . examples
718- ) ;
717+ const obj = { } ;
718+ let schema ;
719+ if ( mediaTypeDocumentation . content ) {
720+ if ( mediaTypeDocumentation . content [ contentKey ] ?. example ) {
721+ obj . example = mediaTypeDocumentation . content [ contentKey ] ?. example ;
722+ }
719723
720- schema = mediaTypeDocumentation . content [ contentKey ] . schema ;
721- } else if (
722- mediaTypeDocumentation ?. contentType &&
723- mediaTypeDocumentation . schema
724- ) {
725- if ( mediaTypeDocumentation ?. example )
726- obj . example = mediaTypeDocumentation . example ;
724+ if ( mediaTypeDocumentation . content [ contentKey ] ?. examples ) {
725+ obj . examples = this . createExamples (
726+ mediaTypeDocumentation . content [ contentKey ] . examples
727+ ) ;
728+ }
727729
728- if ( mediaTypeDocumentation ?. examples )
729- obj . examples = this . createExamples ( mediaTypeDocumentation . examples ) ;
730+ schema = ( mediaTypeDocumentation . schema ) ? mediaTypeDocumentation . schema : mediaTypeDocumentation . schemas [ contentKey ] ;
731+ } else if ( mediaTypeDocumentation ?. contentType && mediaTypeDocumentation . schema ) {
732+ if ( mediaTypeDocumentation . example ) {
733+ obj . example = mediaTypeDocumentation . example ;
734+ }
730735
731- schema = mediaTypeDocumentation . schema ;
732- }
736+ if ( mediaTypeDocumentation . examples ) {
737+ obj . example = mediaTypeDocumentation . examples ;
738+ }
733739
734- const schemaRef = await this . schemaHandler
735- . createSchema ( mediaTypeDocumentation . name )
736- . catch ( ( err ) => {
737- throw err ;
738- } ) ;
740+ schema = mediaTypeDocumentation . schema ;
741+ }
739742
740- obj . schema = {
741- $ref : schemaRef ,
742- } ;
743+ const schemaRef = await this . schemaHandler
744+ . createSchema ( mediaTypeDocumentation . name )
745+ . catch ( ( err ) => {
746+ throw err ;
747+ } ) ;
743748
744- Object . assign ( mediaTypeObj , { [ contentKey ] : obj } ) ;
749+ obj . schema = {
750+ $ref : schemaRef ,
751+ } ;
752+
753+ Object . assign ( mediaTypeObj , { [ contentKey ] : obj } ) ;
754+ }
745755 }
746756 }
747757
@@ -861,7 +871,7 @@ class DefinitionGenerator {
861871 if (
862872 this . openAPI . components [ type ] [ name ] &&
863873 isEqual ( schemaObj [ name ] , this . openAPI . components [ type ] [ name ] ) ===
864- false
874+ false
865875 ) {
866876 delete schemaObj [ name ] ;
867877 newName = `${ name } -${ uuid ( ) } ` ;
0 commit comments