@@ -233,6 +233,9 @@ paths:
233233
234234 valid , errors := v .ValidateRequestBody (request )
235235
236+ // double-tap to hit the cache
237+ _ , _ = v .ValidateRequestBody (request )
238+
236239 assert .False (t , valid )
237240 assert .Len (t , errors , 1 )
238241 assert .Len (t , errors [0 ].SchemaValidationErrors , 2 )
@@ -746,3 +749,47 @@ components:
746749 assert .Equal (t , "maximum 2 items required, but found 4 items" , errors [0 ].SchemaValidationErrors [0 ].Reason )
747750 assert .Equal (t , 11 , errors [0 ].SchemaValidationErrors [0 ].Column )
748751}
752+
753+ func TestValidateBody_MissingBody (t * testing.T ) {
754+ spec := `openapi: 3.1.0
755+ paths:
756+ /burgers/createBurger:
757+ post:
758+ requestBody:
759+ content:
760+ application/json:
761+ schema:
762+ $ref: '#/components/schema_validation/TestBody'
763+ components:
764+ schema_validation:
765+ TestBody:
766+ type: array
767+ maxItems: 2
768+ items:
769+ type: object
770+ properties:
771+ name:
772+ type: string
773+ patties:
774+ type: integer
775+ maximum: 3
776+ minimum: 1
777+ vegetarian:
778+ type: boolean
779+ required: [name, patties, vegetarian] `
780+
781+ doc , _ := libopenapi .NewDocument ([]byte (spec ))
782+
783+ m , _ := doc .BuildV3Model ()
784+ v := NewRequestBodyValidator (& m .Model )
785+
786+ request , _ := http .NewRequest (http .MethodPost , "https://things.com/burgers/createBurger" ,
787+ http .NoBody )
788+ request .Header .Set ("Content-Type" , "application/json" )
789+
790+ valid , errors := v .ValidateRequestBody (request )
791+
792+ assert .True (t , valid )
793+ assert .Len (t , errors , 0 )
794+
795+ }
0 commit comments