-
Notifications
You must be signed in to change notification settings - Fork 479
Enum-like properties like "refine" or enum "valueType" allow general strings, although invalid according to validator #795
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
Comments
The general idea behind that is to allow for extensibility. (This might be inspired by glTF, where you see the same pattern, e.g. for image MIME types). If the (The validator would then have to be updated accordingly. There already are some mechanisms for that in place. The specific form of extension in this example would require moving the validation of the I know that this does raise some questions for library implementors: When creating a library in a high-level programming language*, then you'd usually perform some validation on the library level. Something like (pseudocode)
But this can cause trouble when the set of valid values actually are extended later. I don't have a "silver bullet" solution for that. (In fact, I stumbled over the exact same thing, in my glTF library, for the [case of the * No, I don't count JavaScript into the category of "high-level programming languages" |
In case it's helpful, I've been playing around with glTF / 3D Tiles in Rust myself (strictly for fun and to learn Rust), and found this construct quite natural for the various enums:
This allows the |
I was suspecting already that extensibility was one of the ideas. Maybe it makes sense to add a note in the spec for this, i.e. something like: "Additionally an arbitrary string is allowed for future extension, but is currently not supported", so that it's more clear why the string is allowed as well in the spec.
Oh cool, yeah I should probably open that repo (I plan on open-sourcing this anyway), to avoid possibly duplicated work.
Yep that was also how I was doing it until I opened that issue or rather have found the tests that were prohibiting this custom string. |
I didn't know that Rust allows for "abitrary strings" in enums. The details here vary from language to language. An enum may just be an In practice I think that there is hardly ever a reason to use Here, your answer popped up... Insofar, the fact that
We can consider this. I think that there are not sooo many places where |
I'd agree with you at least somewhat in other languages than in Rust, but as it's an algebraic sum type there (or in typescript terms a "discriminated/tagged union") it's not really comparable to what e.g. a C enum is, and usually an idiomatic solution for a lot of data types in Rust (like this case).
Yeah the amount of these enums is manageable to add a note over each of those and might be worth it so that it's more obvious when looking up those properties instead of having to jump to a specific section where this is described in general. |
Not yet. It's just been a learning exercise for me, so far, so not much worth sharing. I've been trying to follow the approach used in cesium-native, though, where the Rust code to glTF and 3D Tiles is generated from JSON Schema specs. Generating Rust code in Rust is actually pretty nice! I've also been looking at basing the 3D Tiles representation around the Bevy ECS, so that a Tile, for example, is an entity with a Tile component (might break this down further later) and extensions are additional components. It's been a challenge to deserialize tileset.json into the Bevy ECS World, though, probably mostly because I'm a Rust amateur. I'm not completely sure any of this is a good idea, but I thought it would be fun to try. |
I'm currently writing a Rust library to parse and validate 3d-tiles tilesets.
I'm orienting closely to the jsonschema defined in this repo, and I've seen property type definitions like:
My first thought and interpretation according to the JSON schema specification was to allow additionally custom strings other than
"ADD"
and"REPLACE"
, but according to the validator (tests etc.) and what I can read on the 3d-tiles spec, is that this is not allowed.I've now checked all (or most) other places like enum
"valueType"
or class property types that custom strings are seemingly not allowed.So I think
{ "type": "string" }
needs to be removed from all those"anyOf"
s, to disallow any other strings being passed (and to avoid confusion of interpreting the jsonschema).The text was updated successfully, but these errors were encountered: