@@ -50,3 +50,51 @@ class JSONSchemaTests: XCTestCase {
5050 XCTAssertFalse ( schema. validate ( [ " price " : 34.99 ] ) . valid)
5151 }
5252}
53+
54+
55+ class ValidateTests : XCTestCase {
56+ func testValidateDraft4( ) {
57+ let schema : [ String : Any ] = [
58+ " $schema " : " http://json-schema.org/draft-04/schema# " ,
59+ " type " : " object " ,
60+ " properties " : [
61+ " name " : [ " type " : " string " ] ,
62+ " price " : [ " type " : " number " ] ,
63+ ] ,
64+ " required " : [ " name " ] ,
65+ ]
66+
67+ XCTAssertTrue ( validate ( [ " name " : " Eggs " , " price " : 34.99 ] , schema: schema) . valid)
68+ XCTAssertFalse ( validate ( [ " price " : 34.99 ] , schema: schema) . valid)
69+ }
70+
71+ func testValidateDraft6( ) {
72+ let schema : [ String : Any ] = [
73+ " $schema " : " http://json-schema.org/draft-06/schema# " ,
74+ " type " : " object " ,
75+ " properties " : [
76+ " name " : [ " type " : " string " ] ,
77+ " price " : [ " type " : " number " ] ,
78+ ] ,
79+ " required " : [ " name " ] ,
80+ ]
81+
82+ XCTAssertTrue ( validate ( [ " name " : " Eggs " , " price " : 34.99 ] , schema: schema) . valid)
83+ XCTAssertFalse ( validate ( [ " price " : 34.99 ] , schema: schema) . valid)
84+ }
85+
86+ func testValidateDraft7( ) {
87+ let schema : [ String : Any ] = [
88+ " $schema " : " http://json-schema.org/draft-07/schema# " ,
89+ " type " : " object " ,
90+ " properties " : [
91+ " name " : [ " type " : " string " ] ,
92+ " price " : [ " type " : " number " ] ,
93+ ] ,
94+ " required " : [ " name " ] ,
95+ ]
96+
97+ XCTAssertTrue ( validate ( [ " name " : " Eggs " , " price " : 34.99 ] , schema: schema) . valid)
98+ XCTAssertFalse ( validate ( [ " price " : 34.99 ] , schema: schema) . valid)
99+ }
100+ }
0 commit comments