From df71e72caaca29258b3dfd8bec156ca88e7d41b7 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Wed, 27 Sep 2023 16:25:12 -0500 Subject: [PATCH] meta-schemas: Relax vendor-props meta-schema type checks 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 --- dtschema/meta-schemas/vendor-props.yaml | 60 +++++++------------------ test/schemas/bad-example.yaml | 2 +- 2 files changed, 16 insertions(+), 46 deletions(-) diff --git a/dtschema/meta-schemas/vendor-props.yaml b/dtschema/meta-schemas/vendor-props.yaml index 2471ff7d..b778fbf9 100644 --- a/dtschema/meta-schemas/vendor-props.yaml +++ b/dtschema/meta-schemas/vendor-props.yaml @@ -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 ] ... diff --git a/test/schemas/bad-example.yaml b/test/schemas/bad-example.yaml index 043a09b5..a4131a1e 100644 --- a/test/schemas/bad-example.yaml +++ b/test/schemas/bad-example.yaml @@ -76,7 +76,7 @@ properties: description: 0 vendor,property: - enum: [ 0, 1, 2 ] + type: boolean required: - model