Creating a schema for arbitrary keys in a map
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 167
- PR merge metrics
- No merged PRs in 30d
Description
Hello!
I'm having trouble understanding how to create a schema that contains a map with arbitrary keys.
Here's an example of the sort of YAML I want to create a schema for:
```
planets:
Sun:
size: 1.9891e+30
Jupiter:
size: 1.8986e+27
Earth:
size: 5.9736e+24
Mars:
size: 6.4185e+23
```
This map doesn't have a fixed set of keys, but those keys are strings and it has values that I'd like to create a schema to match.
For comparison, the jsonschema spec has an [additionalProperties](https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties) section that allows you to define a schema to use for any fields that aren't otherwise specified.
Reading the [schema reference](https://carvel.dev/ytt/docs/v0.40.0/lang-ref-ytt-schema), I wasn't able to find a way to define this sort of schema. Am I misunderstanding something? Or is this not currently possible?
If it's not possible _yet_, then this is the sort of syntax I'm hoping is possible:
```
#@ def planet_schema():
size: 0.0
#@ end
#@data/values-schema
---
#@schema/type value=planet_schema()
planets: {}
```
Alternatively, syntax like this would be great:
```
#@data/values-schema
---
planets:
_:
size: 0.0
```
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.