File tree Expand file tree Collapse file tree
lib/cocina/models/validators Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,7 +36,8 @@ def self.validate(...)
3636 # @return [JSONSchema validator] a cached per-definition validator
3737 def self . validator_for ( def_name )
3838 @validators ||= { }
39- @validators [ def_name ] ||= JSONSchema . validator_for ( { '$ref' => "#/$defs/#{ def_name } " , '$defs' => document [ '$defs' ] } )
39+ schema = { '$ref' => "#/$defs/#{ def_name } " , '$defs' => document [ '$defs' ] }
40+ @validators [ def_name ] ||= JSONSchema . validator_for ( schema , validate_formats : true )
4041 end
4142
4243 # @return [Hash] a hash representation of the schema.json document
Original file line number Diff line number Diff line change 11261126 },
11271127 "uri" : {
11281128 "description" : " URI value of the descriptive element." ,
1129- "type" : " string"
1129+ "type" : " string" ,
1130+ "format" : " uri"
11301131 },
11311132 "standard" : {
11321133 "$ref" : " #/$defs/Standard"
14161417 },
14171418 "uri" : {
14181419 "description" : " URI for the standard or encoding." ,
1419- "type" : " string"
1420+ "type" : " string" ,
1421+ "format" : " uri"
14201422 },
14211423 "value" : {
14221424 "description" : " String describing the standard or encoding." ,
19561958 },
19571959 "uri" : {
19581960 "description" : " URI value of the descriptive element." ,
1959- "type" : " string"
1961+ "type" : " string" ,
1962+ "format" : " uri"
19601963 },
19611964 "value" : {
19621965 "description" : " Value of the descriptive element." ,
30753078 },
30763079 "uri" : {
30773080 "description" : " URI for the value source." ,
3078- "type" : " string"
3081+ "type" : " string" ,
3082+ "format" : " uri"
30793083 },
30803084 "value" : {
30813085 "description" : " String describing the value source." ,
31223126 },
31233127 "uri" : {
31243128 "description" : " URI for the standard or encoding." ,
3125- "type" : " string"
3129+ "type" : " string" ,
3130+ "format" : " uri"
31263131 },
31273132 "value" : {
31283133 "description" : " String describing the standard or encoding." ,
Original file line number Diff line number Diff line change 9494 end
9595 end
9696
97+ context 'with an invalid uri' do
98+ let ( :properties ) do
99+ JSON . parse ( File . read ( 'spec/fixtures/description/etd.json' ) ) . tap do |props |
100+ props [ 'contributor' ] . first [ 'role' ] . first [ 'uri' ] = 'not a uri'
101+ end
102+ end
103+
104+ it 'raises' do
105+ expect { item } . to raise_error ( Cocina ::Models ::ValidationError )
106+ end
107+ end
108+
97109 describe 'introspecting' do
98110 it 'is possible to get the nodes from the schema' do
99111 # We use this to determine whether the paths in the descriptive spreadsheet are valid
You can’t perform that action at this time.
0 commit comments