Open desaikd opened 7 months ago
Our usecase is that we take in a single Ion struct which is might not contains the type
field name and it doesn't have type annotation. And we want to use that blob to directly create a new anonymous type for a Schema, like what ion-schema-kotlin is what doing here. Return should be an IslType
so that we can access constraints instead of TypeDefinition
which can only be used to validate ion element.
Without this we have to do the walk around to synthesize an ion struct with type annotation and type to read as ion schema and get the anonymous type. This reduces integrity of our code and we likely to remove the code once this feature is released. Can you prioritize on your end?
Thanks!
@liguoso I want to understand more about your usecase here. Why do you guys require an anonymous type definition instead of regular named type definition and how do you currently perform validation for these types? Anonymous types/inline type definitions (types that doesn't have a name field) can only be inlined/part of a named type definition and all the top level type definitions must have a name.
As per an offline discussion,
The usecase for @liguoso is to create new anonymous type and perform custom validation on it. This doesn't really require creating a schema out of the newly defined type. Hence a possible solution is to add new APIs for IslType
that allow generating type definitions from a byte array similar to the current API that allow programmatic generation of type definition.
Proposed solution:
let isl_type: IslType = load_isl_type(r#"{ codepoint_length: 12 }"#)?;
let isl_constraints = isl_type.constraints();
// perform your own custom validation logic
Schema
doesn't have an API to add new types to it. Similar toion-schema-kotlin
newType, provide a way to add new types toSchema
.