@@ -4,7 +4,7 @@ use rstest::*;
4
4
use std:: { collections:: HashMap , fs} ;
5
5
use std:: path:: PathBuf ;
6
6
use proptest:: prelude:: * ;
7
- use boon:: { Schemas , Compiler , SchemaIndex } ;
7
+ use boon:: { Compiler , SchemaIndex , Schemas , UrlLoader } ;
8
8
use glob:: glob;
9
9
use std:: sync:: OnceLock ;
10
10
@@ -18,6 +18,10 @@ impl EventsSchemas {
18
18
let mut schemas = Schemas :: new ( ) ;
19
19
let mut compiler = Compiler :: new ( ) ;
20
20
let mut mapping = HashMap :: new ( ) ;
21
+
22
+ //HACK to resolve invalid `$ref: "/schema/links/embeddedlinksarray.json"`
23
+ compiler. register_url_loader ( "https" , Box :: new ( HackUrlLoader { } ) ) ;
24
+
21
25
for entry in glob ( "../cdevents-specs/*/schemas/*.json" ) . expect ( "Failed to read glob pattern" ) {
22
26
let schemapath = entry. unwrap ( ) ;
23
27
//TODO avoid to read the schema twice (as json, then as jsonschema)
@@ -47,14 +51,27 @@ impl EventsSchemas {
47
51
}
48
52
}
49
53
54
+ struct HackUrlLoader ;
55
+
56
+ impl UrlLoader for HackUrlLoader {
57
+ fn load ( & self , url : & str ) -> Result < serde_json:: Value , Box < dyn std:: error:: Error > > {
58
+ if url. starts_with ( "https://cdevents.dev/schema/links/" ) {
59
+ let path = url. replace ( "https://cdevents.dev/schema" , "../cdevents-specs/spec-v0.4/schemas/" ) ;
60
+ let jsonschema: serde_json:: Value = serde_json:: from_str ( & std:: fs:: read_to_string ( path) ?) ?;
61
+ Ok ( jsonschema)
62
+ } else {
63
+ Err ( format ! ( "fail to load {url}" ) . into ( ) )
64
+ }
65
+ }
66
+ }
50
67
static EVENTS_SCHEMA_CELL : OnceLock < EventsSchemas > = OnceLock :: new ( ) ;
51
68
52
69
fn events_schemas ( ) -> & ' static EventsSchemas {
53
70
EVENTS_SCHEMA_CELL . get_or_init ( EventsSchemas :: load)
54
71
}
55
72
56
73
#[ rstest]
57
- fn for_each_example ( #[ files( "../cdevents-specs/spec-v0.3 /examples/*.json" ) ] path : PathBuf ) {
74
+ fn can_serde_example ( #[ files( "../cdevents-specs/spec-* /examples/*.json" ) ] path : PathBuf ) {
58
75
let example_txt = fs:: read_to_string ( path) . expect ( "to read file as string" ) ;
59
76
//HACK uri are stored ad http::Uri, they are "normalized" when serialized, so prenormalization to avoid failure like
60
77
// json atoms at path ".subject.content.repository.source" are not equal:
@@ -78,7 +95,7 @@ fn for_each_example(#[files("../cdevents-specs/spec-v0.3/examples/*.json")] path
78
95
}
79
96
80
97
#[ rstest]
81
- fn validate_example_against_schema ( #[ files( "../cdevents-specs/spec-v0.3 /examples/*.json" ) ] path : PathBuf ) {
98
+ fn validate_example_against_schema ( #[ files( "../cdevents-specs/spec-* /examples/*.json" ) ] path : PathBuf ) {
82
99
let events_schemas = events_schemas ( ) ;
83
100
let example_txt = fs:: read_to_string ( path) . expect ( "to read file as string" ) ;
84
101
let example_json: serde_json:: Value =
0 commit comments