Open r0b0ji opened 7 months ago
There is a workaround given in the related issue https://github.com/amazon-ion/ion-schema-kotlin/issues/303 but I opened this issue to discuss the possibility of supporting this in ISL or if not then why it is not a good idea.
Thanks for suggesting this feature. From an implementation perspective, it is certainly possible to allow other annotations on type references. I think the next step here is to determine the answers to at least these questions to help figure out how this fits with the rest of the Ion Schema Language.
$null_or
annotation.Thanks for the response.
.hasTypeAnnotation("my_custom_annotation")
. Similarly, I'd expect ISL shouldn't have any order dependent logic either. For internal built-in annotations, ISL should also just check if hasTypeAnnotation("any_isl_annotation")
or the annotations contains the required annotation.
I have a usecase to extend
Type
to add some custom logic.For example, a new Type may have some fields which is mandatory but when comparing two instances of that type I'd like to ignore few fields. We can achieve this by annotating few fields with our custom annotation say
compare.ignore
and then parse the schema and have a list of fields to be ignored in Type and then while comparing we remove those ignored fields from both left and right before comparing.A corresponding schema may look something like:
But this fails as ISL doesn't allow any annotation other than some default annotations [1].
ISL itself is Ion doc and as any Ion doc it could support any custom annotation and have it behave as passthru and
.getIsl()
on type can return the type IonValue as it is along with any annotation and let the client handle that however they want.[1] https://github.com/amazon-ion/ion-schema-kotlin/blob/bbab678c12fdd07bcb9b5d632fb7364a04541a73/ion-schema/src/main/kotlin/com/amazon/ionschema/internal/TypeReference.kt#L58
A related issue: https://github.com/amazon-ion/ion-schema-kotlin/issues/303