@@ -564,7 +564,10 @@ export class OpenAPIValidator<D extends Document = Document> {
564
564
OpenAPIV3 . RequestBodyObject ,
565
565
OpenAPIV3_1 . RequestBodyObject
566
566
> ;
567
- const jsonbody = requestBody . content [ 'application/json' ] ;
567
+ const jsonbody =
568
+ requestBody . content [ 'application/json' ] ||
569
+ requestBody . content [ 'multipart/form-data' ] ||
570
+ requestBody . content [ 'application/x-www-form-urlencoded' ] ;
568
571
if ( jsonbody && jsonbody . schema ) {
569
572
const requestBodySchema : InputValidationSchema = {
570
573
title : 'Request' ,
@@ -582,6 +585,7 @@ export class OpenAPIValidator<D extends Document = Document> {
582
585
583
586
// add compiled params schema to schemas for this operation id
584
587
const requestBodyValidator = this . getAjv ( ValidationContext . RequestBody ) ;
588
+ this . removeBinaryPropertiesFromRequired ( requestBodySchema ) ;
585
589
validators . push ( OpenAPIValidator . compileSchema ( requestBodyValidator , requestBodySchema ) ) ;
586
590
}
587
591
}
@@ -669,6 +673,49 @@ export class OpenAPIValidator<D extends Document = Document> {
669
673
return validators ;
670
674
}
671
675
676
+ /**
677
+ * Removes binary properties from the required array in JSON schema, since they cannot be validated.
678
+ *
679
+ * @param {any } schema
680
+ * @memberof OpenAPIValidator
681
+ */
682
+ private removeBinaryPropertiesFromRequired ( schema : any ) : void {
683
+ if ( typeof schema !== 'object' || ! schema ?. required ) {
684
+ return ;
685
+ }
686
+
687
+ // If this is a schema with properties
688
+ if ( schema . properties && schema . required && Array . isArray ( schema . required ) ) {
689
+ // Find properties with binary format to exclude from required
690
+ const binaryProperties = Object . keys ( schema . properties ) . filter ( ( propName ) => {
691
+ const prop = schema . properties [ propName ] ;
692
+ return prop && prop . type === 'string' && prop . format === 'binary' ;
693
+ } ) ;
694
+
695
+ // Remove binary properties from required array
696
+ if ( binaryProperties . length > 0 ) {
697
+ schema . required = schema . required . filter ( ( prop : string ) => ! binaryProperties . includes ( prop ) ) ;
698
+ }
699
+ }
700
+
701
+ // Recursively process nested objects and arrays
702
+ if ( schema . properties ) {
703
+ Object . values ( schema . properties ) . forEach ( ( prop ) => this . removeBinaryPropertiesFromRequired ( prop ) ) ;
704
+ }
705
+
706
+ // Handle array items
707
+ if ( schema . items ) {
708
+ this . removeBinaryPropertiesFromRequired ( schema . items ) ;
709
+ }
710
+
711
+ // Handle allOf, anyOf, oneOf
712
+ [ 'allOf' , 'anyOf' , 'oneOf' ] . forEach ( ( key ) => {
713
+ if ( Array . isArray ( schema [ key ] ) ) {
714
+ schema [ key ] . forEach ( ( subSchema : any ) => this . removeBinaryPropertiesFromRequired ( subSchema ) ) ;
715
+ }
716
+ } ) ;
717
+ }
718
+
672
719
/**
673
720
* Get response validator function for an operation by operationId
674
721
*
0 commit comments