@@ -691,33 +691,37 @@ let QUERYPARAM = 'query',
691691 let resolvedSchemaProps = { } ,
692692 { includeDeprecated } = context . computedOptions ;
693693
694- _ . forOwn ( schema . properties , ( property , propertyName ) => {
695- // Skip property resolution if it's not schema object
696- if ( ! _ . isObject ( property ) ) {
697- return ;
698- }
694+ // Only process properties if the schema has a properties field
695+ if ( schema . hasOwnProperty ( 'properties' ) ) {
696+ _ . forOwn ( schema . properties , ( property , propertyName ) => {
697+ // Skip property resolution if it's not schema object
698+ if ( ! _ . isObject ( property ) ) {
699+ return ;
700+ }
699701
700- if (
701- property . format === 'decimal' ||
702- property . format === 'byte' ||
703- property . format === 'password' ||
704- property . format === 'unix-time'
705- ) {
706- delete property . format ;
707- }
702+ if (
703+ property . format === 'decimal' ||
704+ property . format === 'byte' ||
705+ property . format === 'password' ||
706+ property . format === 'unix-time'
707+ ) {
708+ delete property . format ;
709+ }
708710
709- // Skip addition of deprecated properties based on provided options
710- if ( ! includeDeprecated && property . deprecated ) {
711- return ;
712- }
711+ // Skip addition of deprecated properties based on provided options
712+ if ( ! includeDeprecated && property . deprecated ) {
713+ return ;
714+ }
713715
714- const currentPropPath = utils . addToJsonPath ( currentPath , [ 'properties' , propertyName ] ) ;
716+ const currentPropPath = utils . addToJsonPath ( currentPath , [ 'properties' , propertyName ] ) ;
715717
716- resolvedSchemaProps [ propertyName ] = _resolveSchema ( context , property , stack , resolveFor ,
717- _ . cloneDeep ( seenRef ) , currentPropPath ) ;
718- } ) ;
718+ resolvedSchemaProps [ propertyName ] = _resolveSchema ( context , property , stack , resolveFor ,
719+ _ . cloneDeep ( seenRef ) , currentPropPath ) ;
720+ } ) ;
719721
720- schema . properties = resolvedSchemaProps ;
722+ schema . properties = resolvedSchemaProps ;
723+ }
724+
721725 schema . type = schema . type || SCHEMA_TYPES . object ;
722726 }
723727 // If schema is of type array
@@ -827,73 +831,70 @@ let QUERYPARAM = 'query',
827831 } ;
828832 }
829833
830- if ( resolvedSchema . type === 'object' && resolvedSchema . properties ) {
834+ if ( resolvedSchema . type === 'object' ) {
831835 const schemaDetails = {
832836 description : resolvedSchema . description ,
833837 title : resolvedSchema . title ,
834- type : resolvedSchema . type ,
835- properties : { } ,
836- required : [ ]
837- } ,
838- requiredProperties = new Set ( resolvedSchema . required || [ ] ) ;
839-
840- for ( let [ propName , propValue ] of Object . entries ( resolvedSchema . properties ) ) {
841- if ( ! propValue . type && ! propValue . anyOf && ! propValue . oneOf && ! propValue . allOf ) {
842- continue ;
843- }
844- const propertyDetails = {
845- type : propValue . type ,
846- deprecated : propValue . deprecated ,
847- enum : propValue . enum || undefined ,
848- minLength : propValue . minLength ,
849- maxLength : propValue . maxLength ,
850- minimum : propValue . minimum ,
851- maximum : propValue . maximum ,
852- pattern : propValue . pattern ,
853- example : propValue . example ,
854- title : propValue . title ,
855- description : propValue . description ,
856- format : propValue . format
838+ type : resolvedSchema . type
857839 } ;
858840
859- if ( requiredProperties . has ( propName ) ) {
860- schemaDetails . required . push ( propName ) ;
861- }
841+ // Only include properties if they exist in the original schema
842+ if ( resolvedSchema . hasOwnProperty ( 'properties' ) ) {
843+ schemaDetails . properties = { } ;
862844
863- if ( propValue . anyOf ) {
864- propertyDetails . anyOf = propValue . anyOf . map ( ( schema ) => {
865- return processSchema ( schema ) ;
866- } ) ;
867- }
868- else if ( propValue . oneOf ) {
869- propertyDetails . oneOf = propValue . oneOf . map ( ( schema ) => {
870- return processSchema ( schema ) ;
871- } ) ;
872- }
873- else if ( propValue . allOf ) {
874- propertyDetails . allOf = propValue . allOf . map ( ( schema ) => {
875- return processSchema ( schema ) ;
876- } ) ;
877- }
878- else if ( propValue . properties ) {
879- let processedProperties = processSchema ( propValue ) ;
880- propertyDetails . properties = processedProperties . properties ;
881- if ( processedProperties . required ) {
882- propertyDetails . required = processedProperties . required ;
845+ for ( let [ propName , propValue ] of Object . entries ( resolvedSchema . properties ) ) {
846+ if ( ! propValue . type && ! propValue . anyOf && ! propValue . oneOf && ! propValue . allOf ) {
847+ continue ;
883848 }
884- }
885- else if ( propValue . type === 'array' && propValue . items ) {
886- propertyDetails . items = processSchema ( propValue . items ) ;
887- }
849+ const propertyDetails = {
850+ type : propValue . type ,
851+ deprecated : propValue . deprecated ,
852+ enum : propValue . enum || undefined ,
853+ minLength : propValue . minLength ,
854+ maxLength : propValue . maxLength ,
855+ minimum : propValue . minimum ,
856+ maximum : propValue . maximum ,
857+ pattern : propValue . pattern ,
858+ example : propValue . example ,
859+ title : propValue . title ,
860+ description : propValue . description ,
861+ format : propValue . format
862+ } ;
888863
889- schemaDetails . properties [ propName ] = propertyDetails ;
890- }
891- if ( schemaDetails . required && schemaDetails . required . length === 0 ) {
892- schemaDetails . required = undefined ;
864+ if ( propValue . anyOf ) {
865+ propertyDetails . anyOf = propValue . anyOf . map ( ( schema ) => {
866+ return processSchema ( schema ) ;
867+ } ) ;
868+ }
869+ else if ( propValue . oneOf ) {
870+ propertyDetails . oneOf = propValue . oneOf . map ( ( schema ) => {
871+ return processSchema ( schema ) ;
872+ } ) ;
873+ }
874+ else if ( propValue . allOf ) {
875+ propertyDetails . allOf = propValue . allOf . map ( ( schema ) => {
876+ return processSchema ( schema ) ;
877+ } ) ;
878+ }
879+ else if ( propValue . properties ) {
880+ let processedProperties = processSchema ( propValue ) ;
881+ propertyDetails . properties = processedProperties . properties ;
882+ if ( processedProperties . required ) {
883+ propertyDetails . required = processedProperties . required ;
884+ }
885+ }
886+ else if ( propValue . type === 'array' && propValue . items ) {
887+ propertyDetails . items = processSchema ( propValue . items ) ;
888+ }
889+
890+ schemaDetails . properties [ propName ] = propertyDetails ;
891+ }
893892 }
894- if ( schemaDetails . properties && Object . keys ( schemaDetails . properties ) . length === 0 ) {
895- schemaDetails . properties = undefined ;
893+
894+ if ( resolvedSchema . required ) {
895+ schemaDetails . required = resolvedSchema . required ;
896896 }
897+
897898 return schemaDetails ;
898899 }
899900 else if ( resolvedSchema . type === 'array' && resolvedSchema . items ) {
0 commit comments