-
Notifications
You must be signed in to change notification settings - Fork 6
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
adds implementation for WriteToIsl
#183
Conversation
* Defines `WriteToIsl` trait * Implements `WriteToIsl` for `IslSchema`
ion-schema/src/isl/mod.rs
Outdated
use ion_rs::Symbol; | ||
use ion_rs::{IonType, TextWriterBuilder}; | ||
use nom::AsBytes; |
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.
Where is this being used?
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.
This is being used in the tests for WriteToIsl
.
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.
nom
is a pretty heavy dependency to bring in for the AsBytes
trait, which seems to be a helper for fixed-sized arrays. Consider either:
- Removing the dependency and using
Vec::as_slice
to access the bytes of theVec<u8>
. - Downgrading the dependency to a dev dependency.
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.
nom
is a pretty heavy dependency to bring in for theAsBytes
trait, which seems to be a helper for fixed-sized arrays. Consider either:* Removing the dependency and using [`Vec::as_slice`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.as_slice) to access the bytes of the `Vec<u8>`. * Downgrading the dependency to a dev dependency.
According to your suggestion and since I am using this only for tests, I will remove the dependency and just use as_slice
.
IslTypeRefImpl::Named(name, nullability_modifier) => { | ||
nullability_modifier.write_to(writer)?; | ||
writer.write_symbol(name)?; | ||
} | ||
IslTypeRefImpl::TypeImport(type_import, nullability_modifier) => { | ||
nullability_modifier.write_to(writer)?; | ||
writer.step_in(IonType::Struct)?; | ||
type_import.write_to(writer)?; | ||
writer.step_out()?; | ||
} |
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.
I'm assuming that it's possible to construct an IslVariableOccurringTypeRef
that has a Named
or TypeImport
. If that's the case, then we should also be writing out the occurs
in these branches, if it's not the default occurs for that constraint.
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.
Right, for TypeImport
I will modify it to add the occurs
field here. For Named
if it has an occurs
other than the default value then it becomes an Anonymous
(inline) type reference.
e.g.
// Named
fields : {
name: string
}
// Anonymous
fields: {
name: { type: string, occurs: required }
}
ion-schema/src/isl/mod.rs
Outdated
"ion-schema-schemas/json/json.isl", // the file contains `nan` which fails on equivalence for two schemas | ||
"ion-schema-tests/ion_schema_1_0/nullable.isl", // Needs `nullable` annotation related fixes | ||
"ion-schema-tests/ion_schema_1_0/schema/import/import_inline.isl", // related to order of types in the schema file | ||
"ion-schema-tests/ion_schema_2_0/imports/tree/inline_import_a.isl", // related to order of types in the schema file | ||
"ion-schema-tests/ion_schema_2_0/imports/tree/inline_import_c.isl", // related to order of types in the schema file |
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.
Do we have any GitHub issue to track the nan
issue or the "order of types in a schema file" issue?
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.
Created an issue for this, I will add it in the comments for these SKIP_LIST
items.
#184
* adds more doc comments * `write_to` writes `occurs` field for `TypeImport` in `IslVariablyOccurringTypeRef`
if range_boundary_type == &RangeBoundaryType::Exclusive { | ||
writer.set_annotations(["exclusive"]); | ||
} | ||
let element = Element::read_one(format!("{value}").as_bytes())?; |
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.
I don't have a concrete suggestion at the moment, but this bit feels a bit fragile to me. We're using the constraint T: Display
but actually hoping that T
is something that's serialized as text Ion, which is a narrower set of types.
ion-schema/src/isl/mod.rs
Outdated
use ion_rs::Symbol; | ||
use ion_rs::{IonType, TextWriterBuilder}; | ||
use nom::AsBytes; |
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.
nom
is a pretty heavy dependency to bring in for the AsBytes
trait, which seems to be a helper for fixed-sized arrays. Consider either:
- Removing the dependency and using
Vec::as_slice
to access the bytes of theVec<u8>
. - Downgrading the dependency to a dev dependency.
Issue #173
Description of changes:
This PR works on adding implementation of
WriteToIsl
which serializes a schema model into a schema file using Ion writer.Example:
Here is a quick example of how to serialize a schema model using Ion writer.
Output:
List of changes:
WriteToIsl
to serialize isl model into schema fileWriteToIsl
trait which will be sued by all ISL model structs to write schema content to an Ion writerWriteToIsl
forIslSchema
WriteToIsl
implementation forUserReservedFields
Test:
Adds unit tests for
WriteToIsl
implementations.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.