Skip to content

Commit

Permalink
meta-schemas: Relax vendor-props meta-schema type checks
Browse files Browse the repository at this point in the history
Now that we check globally for properties with missing type, there's not
a need to enforce that in the meta-schema. Doing it in the meta-schema
is not very flexible as it doesn't allow defining a property in one
place and adding just constraints in another place except for places we
allow it (if/then/else schemas) or fail to walk (additionalProperties).

Now an error from the global check will cause a schema author to add
'type' or a $ref. Then when one of those are present, the meta-schema
will require 'description'.

Signed-off-by: Rob Herring <robh@kernel.org>
  • Loading branch information
robherring committed Sep 28, 2023
1 parent 8e378d1 commit df71e72
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 46 deletions.
60 changes: 15 additions & 45 deletions dtschema/meta-schemas/vendor-props.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,28 @@ patternProperties:
- description

additionalProperties:
type: object
type: [boolean, object]
description: Vendor specific properties must have a type and description
unless they have a defined, common suffix.
oneOf:
- description: 'A vendor boolean property can use "type: boolean"'
properties:
description: true
type:
const: boolean
deprecated: true
required:
- type
- description
additionalProperties: false

- description: A vendor string property with exact values has an implicit
type
properties: # A string property with exact values
description: true
enum:
items:
type: string
const:
type: string
deprecated: true
required:
- description
oneOf:
- required: [ enum ]
- required: [ const ]
additionalProperties: false
properties:
type:
description: 'A vendor boolean property can use "type: boolean"'
const: boolean

dependentRequired:
type: [description]

- description: A vendor property needs a $ref to types.yaml
properties: # A property with a type and additional constraints
anyOf:
- properties:
$ref:
description: A vendor property needs a $ref to types.yaml
pattern: "types.yaml#\/definitions\/"
allOf:
items:
- properties:
$ref:
pattern: "types.yaml#\/definitions\/"
required:
- $ref
required:
- description
oneOf:
- required: [ $ref ]
- required: [ allOf ]
- description: A vendor property can have a $ref to a a $defs schema
properties: # A property with a type and additional constraints
dependentRequired:
$ref: [description]
- properties:
$ref:
description: A vendor property can have a $ref to a a $defs schema
pattern: "^#\/(definitions|\\$defs)\/"
required: [ $ref ]

...
2 changes: 1 addition & 1 deletion test/schemas/bad-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ properties:
description: 0

vendor,property:
enum: [ 0, 1, 2 ]
type: boolean

required:
- model
Expand Down

0 comments on commit df71e72

Please sign in to comment.