@@ -161,6 +161,65 @@ def test_allof_required(self):
161
161
match = "'some_prop' is a required property" ):
162
162
validator .validate ({"another_prop" : "bla" })
163
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
+
164
223
def test_oneof_required (self ):
165
224
instance = {
166
225
'n3IwfId' : 'string' ,
0 commit comments