-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update ion-schema and ion-rs dependencies #151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -391,31 +391,28 @@ mod model_tests { | |
name: vec!["org".to_string(), "example".to_string(), "Foo".to_string()], | ||
doc_comment: "This is a structure".to_string(), | ||
is_closed: false, | ||
fields: HashMap::from_iter( | ||
vec![ | ||
( | ||
"foo".to_string(), | ||
FieldReference( | ||
FullyQualifiedTypeReference { | ||
type_name: vec!["String".to_string()], | ||
parameters: vec![], | ||
}, | ||
FieldPresence::Required, | ||
), | ||
fields: HashMap::from_iter(vec![ | ||
( | ||
"foo".to_string(), | ||
FieldReference( | ||
FullyQualifiedTypeReference { | ||
type_name: vec!["String".to_string()], | ||
parameters: vec![], | ||
}, | ||
FieldPresence::Required, | ||
), | ||
( | ||
"bar".to_string(), | ||
FieldReference( | ||
FullyQualifiedTypeReference { | ||
type_name: vec!["int".to_string()], | ||
parameters: vec![], | ||
}, | ||
FieldPresence::Required, | ||
), | ||
), | ||
( | ||
"bar".to_string(), | ||
FieldReference( | ||
FullyQualifiedTypeReference { | ||
type_name: vec!["int".to_string()], | ||
parameters: vec![], | ||
}, | ||
FieldPresence::Required, | ||
), | ||
] | ||
.into_iter(), | ||
), | ||
), | ||
]), | ||
source: anonymous_type(vec![ | ||
type_constraint(named_type_ref("struct")), | ||
fields( | ||
|
@@ -436,6 +433,7 @@ mod model_tests { | |
), | ||
] | ||
.into_iter(), | ||
true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗺️ Adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
), | ||
]), | ||
}; | ||
|
@@ -451,31 +449,28 @@ mod model_tests { | |
]) | ||
.doc_comment("This is a structure") | ||
.is_closed(false) | ||
.fields(HashMap::from_iter( | ||
vec![ | ||
( | ||
"foo".to_string(), | ||
FieldReference( | ||
FullyQualifiedTypeReference { | ||
type_name: vec!["String".to_string()], | ||
parameters: vec![], | ||
}, | ||
FieldPresence::Required, | ||
), | ||
.fields(HashMap::from_iter(vec![ | ||
( | ||
"foo".to_string(), | ||
FieldReference( | ||
FullyQualifiedTypeReference { | ||
type_name: vec!["String".to_string()], | ||
parameters: vec![], | ||
}, | ||
FieldPresence::Required, | ||
), | ||
( | ||
"bar".to_string(), | ||
FieldReference( | ||
FullyQualifiedTypeReference { | ||
type_name: vec!["int".to_string()], | ||
parameters: vec![], | ||
}, | ||
FieldPresence::Required, | ||
), | ||
), | ||
( | ||
"bar".to_string(), | ||
FieldReference( | ||
FullyQualifiedTypeReference { | ||
type_name: vec!["int".to_string()], | ||
parameters: vec![], | ||
}, | ||
FieldPresence::Required, | ||
), | ||
] | ||
.into_iter(), | ||
)) | ||
), | ||
])) | ||
.source(anonymous_type(vec![ | ||
type_constraint(named_type_ref("struct")), | ||
fields( | ||
|
@@ -496,6 +491,7 @@ mod model_tests { | |
), | ||
] | ||
.into_iter(), | ||
true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing- what's the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is part of the ion schema model. It is something to do with whether the fields are closed for a given type. I'll create an issue to replace it with an enum. |
||
), | ||
])); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -449,7 +449,7 @@ impl<'a, 'b> IonInspector<'a, 'b> { | |
match invocation.kind() { | ||
EExp(eexp_arg) => self.inspect_eexp(depth + 1, eexp_arg)?, | ||
EExpArgGroup(_) => todo!("e-exp arg groups"), | ||
TemplateMacro(_) => { | ||
TemplateMacro(_) | TemplateArgGroup(_) => { | ||
unreachable!("e-exp args by definition cannot be template invocations") | ||
} | ||
} | ||
|
@@ -545,6 +545,9 @@ impl<'a, 'b> IonInspector<'a, 'b> { | |
Template(_, _element) => { | ||
self.inspect_ephemeral_sequence(depth, "(", "", ")", delimiter, sexp, no_comment()) | ||
} | ||
Constructed(_, _) => { | ||
todo!() | ||
} | ||
} | ||
} | ||
|
||
|
@@ -662,10 +665,9 @@ impl<'a, 'b> IonInspector<'a, 'b> { | |
depth, | ||
element.annotations().iter().map(|s| Ok(SymbolRef::from(s))), | ||
), | ||
ExpandedValueSource::Constructed(annotations, _) => self.inspect_ephemeral_annotations( | ||
depth, | ||
annotations.iter().copied().map(|s| Ok(s.into())), | ||
), | ||
ExpandedValueSource::Constructed(annotations, _) => { | ||
self.inspect_ephemeral_annotations(depth, annotations.iter().copied().map(Ok)) | ||
} | ||
Comment on lines
-665
to
+670
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗺️ This was a Clippy fix. |
||
ExpandedValueSource::SingletonEExp(eexp) => self.inspect_ephemeral_annotations( | ||
depth, | ||
eexp.require_singleton_annotations().map(|s| Ok(s.into())), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗺️ Now that the dependencies are updated, we can refactor the validate command to use the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
use crate::commands::IonCliCommand; | ||
use anyhow::{Context, Result}; | ||
use clap::{Arg, ArgAction, ArgMatches, Command}; | ||
use ion_rs::{v1_0, Element, Sequence, SequenceWriter, StructWriter, TextFormat, Writer}; | ||
use ion_schema::authority::{DocumentAuthority, FileSystemDocumentAuthority}; | ||
use ion_schema::external::ion_rs::element::reader::ElementReader; | ||
use ion_schema::external::ion_rs::element::writer::ElementWriter; | ||
use ion_schema::external::ion_rs::element::writer::TextKind; | ||
use ion_schema::external::ion_rs::element::Element; | ||
use ion_schema::external::ion_rs::{IonResult, TextWriterBuilder}; | ||
use ion_schema::external::ion_rs::{IonType, IonWriter, ReaderBuilder}; | ||
use ion_schema::system::SchemaSystem; | ||
use std::fs; | ||
use std::path::Path; | ||
|
@@ -87,9 +82,7 @@ impl IonCliCommand for ValidateCommand { | |
let input_file = args.get_one::<String>("input").unwrap(); | ||
let value = | ||
fs::read(input_file).with_context(|| format!("Could not open '{}'", schema_id))?; | ||
let owned_elements: Vec<Element> = ReaderBuilder::new() | ||
.build(value.as_slice())? | ||
.read_all_elements() | ||
let elements: Sequence = Element::read_all(value) | ||
.with_context(|| format!("Could not parse Ion file: '{}'", schema_id))?; | ||
|
||
// Set up document authorities vector | ||
|
@@ -113,46 +106,27 @@ impl IonCliCommand for ValidateCommand { | |
.with_context(|| format!("Schema {} does not have type {}", schema_id, schema_type))?; | ||
|
||
// create a text writer to make the output | ||
let mut output = vec![]; | ||
let mut writer = TextWriterBuilder::new(TextKind::Pretty).build(&mut output)?; | ||
let mut writer = Writer::new(v1_0::Text.with_format(TextFormat::Pretty), vec![])?; | ||
|
||
// validate owned_elements according to type_ref | ||
for owned_element in owned_elements { | ||
for owned_element in elements { | ||
// create a validation report with validation result, value, schema and/or violation | ||
writer.step_in(IonType::Struct)?; | ||
let mut struct_writer = writer.struct_writer()?; | ||
let validation_result = type_ref.validate(&owned_element); | ||
writer.set_field_name("result"); | ||
match validation_result { | ||
Ok(_) => { | ||
writer.write_string("Valid")?; | ||
writer.set_field_name("value"); | ||
writer.write_string(element_to_string(&owned_element)?)?; | ||
writer.set_field_name("schema"); | ||
writer.write_string(schema_id)?; | ||
struct_writer.write("result", "Valid")?; | ||
struct_writer.write("value", format!("{}", &owned_element))?; | ||
struct_writer.write("schema", schema_id)?; | ||
Comment on lines
-127
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, @zslayton put a lot of effort into trying different approaches in order to find an ergonomic writer API. |
||
} | ||
Err(error) => { | ||
writer.write_string("Invalid")?; | ||
writer.set_field_name("violation"); | ||
writer.write_string(format!("{:#?}", error))?; | ||
struct_writer.write("result", "Invalid")?; | ||
struct_writer.write("violation", format!("{:#?}", error))?; | ||
} | ||
} | ||
writer.step_out()?; | ||
} | ||
drop(writer); | ||
println!("Validation report:"); | ||
println!("{}", from_utf8(&output).unwrap()); | ||
println!("{}", from_utf8(writer.output()).unwrap()); | ||
Ok(()) | ||
} | ||
} | ||
|
||
// TODO: this will be provided by Element's implementation of `Display` in a future | ||
// release of ion-rs. | ||
fn element_to_string(element: &Element) -> IonResult<String> { | ||
let mut buffer = Vec::new(); | ||
let mut text_writer = TextWriterBuilder::new(TextKind::Pretty).build(&mut buffer)?; | ||
text_writer.write_element(element)?; | ||
text_writer.flush()?; | ||
Ok(from_utf8(text_writer.output().as_slice()) | ||
.expect("Invalid UTF-8 output") | ||
.to_string()) | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗺️ Also a clippy fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗺️ Clippy recommended fixes because there was a double reference going on when passing
&isl_type_name
.