KhronosGroup / KhronosGroup/glTF-Validator
About extensions and enum validation
- Dominant language
- Dart
- Stars
- 470
- Forks
- 77
- PR merge metrics
- No merged PRs in 30d
Description
Enums are usually specified to follow the pattern of
```
"anyOf": [
{
"const": 5120,
"type": "integer"
},
{
"const": 5121,
"type": "integer"
},
...
{
"type": "integer"
}
]
```
The last object that only declares the type `integer` is intended for extensions. When there is an extension that adds a new valid value to that enum, then this should still be compliant to the *schema itself*.
The validator goes beyond schema matching. It will therefore issue an error for such an enum value, *unless* there is a known extension that declares the new enum value to be valid.
There is one specific example for this right now, namely the `EXT_texture_webp` extension, that adds `image/webp` as a valid value for the `image.mimeType`. From quickly skimming over the code, this is accomplished by storing the [`imageMimeTypes` in the `context`](https://github.com/KhronosGroup/glTF-Validator/blob/e60dd6d6a96aed2fa18e80af2bfffe5436684438/lib/src/context.dart#L256) (pre-populated with the core MIME types), and [adding WEBP to that list](https://github.com/KhronosGroup/glTF-Validator/blob/e60dd6d6a96aed2fa18e80af2bfffe5436684438/lib/src/ext/EXT_texture_webp/ext_texture_webp.dart#L33) during the initialization of the extensions.
Now I wondered about the general approach for this. Namely, how extensions can sensibly add new valid enum values. If an extension was supposed to add, for example, a new `meshPrimitive.mode`, then the only solution that I'd come up with right now would be to *first* update the "core" validator, by adding
```
final List meshPrimitiveModes = [gl.LINES, gl.LINE_LOOP,
gl.LINE_STRIP, gl.TRIANGLES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN];
```
to the `context`, and changing the place where the mode is obtained from
```
final mode = getUint(map, MODE, context,
min: gl.POINTS, max: gl.TRIANGLE_FAN, def: gl.TRIANGLES);
```
to
```
final mode = getUint(map, MODE, context, list: context.meshPrimitiveModes);
```
So the question that came to my mind was:
Is there (or should there be) a generic mechanism that allows extensions to "hook" into **all** open-ended enums?
(The alternative would be that contributors that add support for a specific extension also have to add changes like the one described above, but it is hard to be sure that this does not have undesired side-effects...)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the enum validation and extension initialization through lib/src/context.dart and lib/src/ext/EXT_texture_webp/ext_texture_webp.dart. Compare the existing imageMimeTypes handling with mesh primitive mode validation and identify the entry points involved. Done should be a documented, generic approach for extensions to add values to open-ended enums without weakening core validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100