File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -143,3 +143,40 @@ def post(self):
143143 client .post_json ("/apples/validation/" , data )
144144
145145 assert Payload .payload == data
146+
147+ def test_api_payload_strict_verification (self , app , client ):
148+ api = restx .Api (app , validate = True )
149+ ns = restx .Namespace ("apples" )
150+ api .add_namespace (ns )
151+
152+ fields = ns .model (
153+ "Person" ,
154+ {
155+ "name" : restx .fields .String (required = True ),
156+ "age" : restx .fields .Integer ,
157+ "birthdate" : restx .fields .DateTime ,
158+ },
159+ strict = True ,
160+ )
161+
162+ @ns .route ("/validation/" )
163+ class Payload (restx .Resource ):
164+ payload = None
165+
166+ @ns .expect (fields )
167+ def post (self ):
168+ Payload .payload = ns .payload
169+ return {}
170+
171+ data = {
172+ "name" : "John Doe" ,
173+ "agge" : 15 , # typo
174+ }
175+
176+ resp = client .post_json ("/apples/validation/" , data , status = 400 )
177+ assert resp == {
178+ "errors" : {
179+ "" : "Additional properties are not allowed ('agge' was unexpected)"
180+ },
181+ "message" : "Input payload validation failed" ,
182+ }
You can’t perform that action at this time.
0 commit comments