11use jsonschema:: { JSONSchema , SchemaResolver , SchemaResolverError } ;
22use serde:: { Deserialize , Serialize } ;
3- use thiserror:: Error ;
43use serde_json:: Value ;
5- use std:: { sync:: Arc } ;
4+ use std:: sync:: Arc ;
5+ use thiserror:: Error ;
66use url:: Url ;
77// This file is supposed to be auto-generated via rust/build.rs
88pub mod schema_types {
@@ -150,23 +150,28 @@ fn get_topic_schema(topic: &str, version: Option<u16>) -> Result<TopicSchema, Sc
150150 Ok ( schema_metadata)
151151}
152152
153- struct FileSchemaResolver { }
153+ struct FileSchemaResolver { }
154154
155155impl FileSchemaResolver {
156156 fn new ( ) -> Self {
157- Self { }
157+ Self { }
158158 }
159159}
160160
161161impl SchemaResolver for FileSchemaResolver {
162- fn resolve ( & self , _root_schema : & Value , url : & Url , _original_reference : & str ) -> Result < Arc < Value > , SchemaResolverError > {
162+ fn resolve (
163+ & self ,
164+ _root_schema : & Value ,
165+ url : & Url ,
166+ _original_reference : & str ,
167+ ) -> Result < Arc < Value > , SchemaResolverError > {
163168 if url. scheme ( ) == "file" {
164- let url_str = url. as_str ( ) ;
169+ let url_str = url. as_str ( ) ;
165170 let relative_path = & url_str[ 7 ..url_str. len ( ) - 1 ] ;
166171 let schema = find_entry ( SCHEMAS , relative_path) . ok_or ( SchemaError :: InvalidSchema ) ?;
167- let schema_json = serde_json:: from_str ( schema) . map_err ( |_| SchemaError :: InvalidSchema ) ?;
172+ let schema_json =
173+ serde_json:: from_str ( schema) . map_err ( |_| SchemaError :: InvalidSchema ) ?;
168174 return Ok ( Arc :: new ( schema_json) ) ;
169-
170175 }
171176
172177 Err ( SchemaResolverError :: new ( Box :: new ( std:: io:: Error :: new (
@@ -192,7 +197,10 @@ pub fn get_schema(topic: &str, version: Option<u16>) -> Result<Schema, SchemaErr
192197
193198 let s = serde_json:: from_str ( schema) . map_err ( |_| SchemaError :: InvalidSchema ) ?;
194199 let resolver = FileSchemaResolver :: new ( ) ;
195- let compiled_json_schema = JSONSchema :: options ( ) . with_resolver ( resolver) . compile ( & s) . map_err ( |_| SchemaError :: InvalidSchema ) ?;
200+ let compiled_json_schema = JSONSchema :: options ( )
201+ . with_resolver ( resolver)
202+ . compile ( & s)
203+ . map_err ( |_| SchemaError :: InvalidSchema ) ?;
196204
197205 // FIXME(swatinem): This assumes that there is only a single `examples` entry in the definition.
198206 // If we would want to support multiple, we would have to either merge those in code generation,
0 commit comments