@@ -146,3 +146,95 @@ def test_string_uuid(self, value):
146
146
result = validator .validate (value )
147
147
148
148
assert result is None
149
+
150
+ def test_allof_required (self ):
151
+ schema = {
152
+ "allOf" : [
153
+ {"type" : "object" ,
154
+ "properties" : {
155
+ "some_prop" : {"type" : "string" }}},
156
+ {"type" : "object" , "required" : ["some_prop" ]},
157
+ ]
158
+ }
159
+ validator = OAS30Validator (schema , format_checker = oas30_format_checker )
160
+ with pytest .raises (ValidationError ,
161
+ match = "'some_prop' is a required property" ):
162
+ validator .validate ({"another_prop" : "bla" })
163
+
164
+ def test_required (self ):
165
+ schema = {
166
+ "type" : "object" ,
167
+ "properties" : {
168
+ "some_prop" : {
169
+ "type" : "string"
170
+ }
171
+ },
172
+ "required" : ["some_prop" ]
173
+ }
174
+
175
+ validator = OAS30Validator (schema , format_checker = oas30_format_checker )
176
+ with pytest .raises (ValidationError ,
177
+ match = "'some_prop' is a required property" ):
178
+ validator .validate ({"another_prop" : "bla" })
179
+ assert validator .validate ({"some_prop" : "hello" }) is None
180
+
181
+ def test_required_read_only (self ):
182
+ schema = {
183
+ "type" : "object" ,
184
+ "properties" : {
185
+ "some_prop" : {
186
+ "type" : "string" ,
187
+ "readOnly" : True
188
+ }
189
+ },
190
+ "required" : ["some_prop" ]
191
+ }
192
+
193
+ validator = OAS30Validator (schema , format_checker = oas30_format_checker ,
194
+ read = True )
195
+ with pytest .raises (ValidationError ,
196
+ match = "'some_prop' is a required property" ):
197
+ validator .validate ({"another_prop" : "hello" })
198
+ validator = OAS30Validator (schema , format_checker = oas30_format_checker ,
199
+ write = True )
200
+ assert validator .validate ({"another_prop" : "hello" }) is None
201
+
202
+ def test_required_write_only (self ):
203
+ schema = {
204
+ "type" : "object" ,
205
+ "properties" : {
206
+ "some_prop" : {
207
+ "type" : "string" ,
208
+ "writeOnly" : True
209
+ }
210
+ },
211
+ "required" : ["some_prop" ]
212
+ }
213
+
214
+ validator = OAS30Validator (schema , format_checker = oas30_format_checker ,
215
+ write = True )
216
+ with pytest .raises (ValidationError ,
217
+ match = "'some_prop' is a required property" ):
218
+ validator .validate ({"another_prop" : "hello" })
219
+ validator = OAS30Validator (schema , format_checker = oas30_format_checker ,
220
+ read = True )
221
+ assert validator .validate ({"another_prop" : "hello" }) is None
222
+
223
+ def test_oneof_required (self ):
224
+ instance = {
225
+ 'n3IwfId' : 'string' ,
226
+ }
227
+ schema = {
228
+ "type" : "object" ,
229
+ "properties" : {
230
+ "n3IwfId" : {"type" : "string" },
231
+ "wagfId" : {"type" : "string" },
232
+ },
233
+ "oneOf" : [
234
+ {"required" : ["n3IwfId" ]},
235
+ {"required" : ["wagfId" ]},
236
+ ],
237
+ }
238
+ validator = OAS30Validator (schema , format_checker = oas30_format_checker )
239
+ result = validator .validate (instance )
240
+ assert result is None
0 commit comments