The schema-validation is limited by the current predefined structure. On the other hand the schema files could be a very important source of documentation.
ExampleData:
items:
foo:
itemType: 'type1'
option1: 'option required for type 1'
bar:
itemType: 'type2'
option2: 'option required for type 2'
With the current schema that is an adaption of the concepts of json.schema to yaml no valid schema can be written for that data because it is not possible to require a field if another field has a specific value.
Instead only the presence of the type property could be checked:
type: dictionary
properties:
items:
type: dictionary
properties:
itemType:
type: string
required: true
additionalProperties: TRUE
To write more efficient schemas it would be great to write hierarhical types, flow already has a supertype resolver that could be used to enable hierarchical types.
# register custom types
@itemTypeBase:
type: dictionary
properties:
itemType:
type: string
required: true
additionalProperties: false
@itemType1:
superTypes:
- 'itemTypeBase': TRUE
properties:
type: {value: 'type1'}
option1:
type: string
reqired: true
@itemType2:
superTypes:
- 'itemTypeBase': TRUE
properties:
type: {value: 'type2'}
option2:
type: string
reqired: true
# use the custom types in the schema
type: dictionary
properties:
items:
type: [@itemType1, @itemType2]
description: 'You can define items here'
The implementation would use a registry-stack of the custom-types. If a schema contains typeDefinitions a new instance of the custom-type-stack will be added. The type-definitions are added there and the superTypes are resolved against the other available types. After validating the schema the typeDefinitionStack is reset to the previous state.
A good way to start would be a schema-schema that is currently not possible because of the recursive definition.
- Add local typeRegistry that is filled by the
@...
properties of a schema and that is passed down for complex types - Add
superTypes
for the typeRegistry - Add referencing of the local types by
@
-prefix - Add
value
keyword as an addition to enum - Add
format: schame-name
option for string validation