Skip to content
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

Add new_type API for Schema #207

Open
desaikd opened this issue Feb 9, 2024 · 3 comments
Open

Add new_type API for Schema #207

desaikd opened this issue Feb 9, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@desaikd
Copy link
Contributor

desaikd commented Feb 9, 2024

Schema doesn't have an API to add new types to it. Similar to ion-schema-kotlin newType, provide a way to add new types to Schema.

@desaikd desaikd added the enhancement New feature or request label Feb 9, 2024
@liguoso
Copy link

liguoso commented Mar 7, 2024

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!

@desaikd
Copy link
Contributor Author

desaikd commented Mar 11, 2024

@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.

@desaikd
Copy link
Contributor Author

desaikd commented Mar 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants