@@ -30,3 +30,52 @@ function test_longpoll_exception_check()
30
30
@test OpenAPI. Clients. is_longpoll_timeout (CompositeException ([openapiex1, as_taskfailedexception (openapiex2)]))
31
31
@test OpenAPI. Clients. is_longpoll_timeout (CompositeException ([openapiex1, as_taskfailedexception (openapiex1)])) == false
32
32
end
33
+
34
+ function test_validations ()
35
+ # maximum
36
+ @test_throws OpenAPI. ValidationException OpenAPI. validate_param (" test_param" , " test_model" , :maximum , 11 , 10 , true )
37
+ @test_throws OpenAPI. ValidationException OpenAPI. validate_param (" test_param" , " test_model" , :maximum , 11 , 10 , false )
38
+ @test_throws OpenAPI. ValidationException OpenAPI. validate_param (" test_param" , " test_model" , :maximum , 10 , 10 , true )
39
+ @test OpenAPI. validate_param (" test_param" , " test_model" , :maximum , 10 , 10 , false ) === nothing
40
+ @test OpenAPI. validate_param (" test_param" , " test_model" , :maximum , 1 , 10 , false ) === nothing
41
+
42
+ # minimum
43
+ @test_throws OpenAPI. ValidationException OpenAPI. validate_param (" test_param" , " test_model" , :minimum , 10 , 11 , true )
44
+ @test_throws OpenAPI. ValidationException OpenAPI. validate_param (" test_param" , " test_model" , :minimum , 10 , 11 , false )
45
+ @test_throws OpenAPI. ValidationException OpenAPI. validate_param (" test_param" , " test_model" , :minimum , 10 , 10 , true )
46
+ @test OpenAPI. validate_param (" test_param" , " test_model" , :minimum , 10 , 10 , false ) === nothing
47
+ @test OpenAPI. validate_param (" test_param" , " test_model" , :minimum , 10 , 1 , false ) === nothing
48
+
49
+ # maxLength, maxItems, maxProperties
50
+ for test in (:maxLength , :maxItems , :maxProperties )
51
+ for items in (1 : 10 , Dict (zip (1 : 10 , 1 : 10 )), [1 : 10 ... ])
52
+ @test OpenAPI. validate_param (" test_param" , " test_model" , test, items, 10 ) === nothing
53
+ end
54
+ for items in (1 : 2 , Dict (zip (1 : 2 , 1 : 2 )), [1 : 2 ... ])
55
+ @test OpenAPI. validate_param (" test_param" , " test_model" , test, items, 10 ) === nothing
56
+ end
57
+ end
58
+
59
+ # minLength, minItems, minProperties
60
+ for test in (:minLength , :minItems , :minProperties )
61
+ for items in (1 : 10 , Dict (zip (1 : 10 , 1 : 10 )), [1 : 10 ... ])
62
+ @test OpenAPI. validate_param (" test_param" , " test_model" , test, items, 10 ) === nothing
63
+ @test OpenAPI. validate_param (" test_param" , " test_model" , test, items, 1 ) === nothing
64
+ end
65
+ end
66
+
67
+ # unique
68
+ @test OpenAPI. validate_param (" test_param" , " test_model" , :uniqueItems , [1 , 2 , 3 ], true ) === nothing
69
+ @test OpenAPI. validate_param (" test_param" , " test_model" , :uniqueItems , [1 , 2 , 2 ], false ) === nothing
70
+ @test_throws OpenAPI. ValidationException OpenAPI. validate_param (" test_param" , " test_model" , :uniqueItems , [1 , 2 , 2 ], true )
71
+
72
+ # pattern
73
+ @test OpenAPI. validate_param (" test_param" , " test_model" , :pattern , " test" , r" [a-z]+" ) === nothing
74
+ @test_throws OpenAPI. ValidationException OpenAPI. validate_param (" test_param" , " test_model" , :pattern , " test" , r" [0-9]+" )
75
+
76
+ # enum
77
+ @test OpenAPI. validate_param (" test_param" , " test_model" , :enum , [:a , :b , :b ], [:a , :b , :c ]) === nothing
78
+ @test_throws OpenAPI. ValidationException OpenAPI. validate_param (" test_param" , " test_model" , :enum , [:a , :b , :c , :d ], [:a , :b , :c ])
79
+
80
+ return nothing
81
+ end
0 commit comments