Skip to content

Commit

Permalink
fixups: Fix handling of required "interrupts" without "properties" in…
Browse files Browse the repository at this point in the history
… schema

In subschemas with "{required: [ interrupts ]}", we fail to do the
"interrupts-extended" fixup because there is not any "properties" entry.
Therefore, we need to do the fixup for "required" regardless unless it
is under a "oneOf" already (otherwise, we'd keep recursing applying the
same fixup).

Also, if "required" becomes empty, remove it.

Signed-off-by: Rob Herring <[email protected]>
  • Loading branch information
robherring committed Dec 6, 2023
1 parent 414a9f7 commit 9150864
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions dtschema/fixups.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,35 +285,34 @@ def walk_properties(schema, path=[]):
fixup_vals(schema, path=path)


def fixup_interrupts(schema):
def fixup_interrupts(schema, path):
# Supporting 'interrupts' implies 'interrupts-extended' is also supported.
if 'properties' not in schema:
return

# Any node with 'interrupts' can have 'interrupt-parent'
if schema['properties'].keys() & {'interrupts', 'interrupt-controller'} and \
'interrupt-parent' not in schema['properties']:
schema['properties']['interrupt-parent'] = True

if 'interrupts' not in schema['properties'] or 'interrupts-extended' in schema['properties']:
return
if 'properties' in schema:
# Any node with 'interrupts' can have 'interrupt-parent'
if schema['properties'].keys() & {'interrupts', 'interrupt-controller'} and \
'interrupt-parent' not in schema['properties']:
schema['properties']['interrupt-parent'] = True

schema['properties']['interrupts-extended'] = copy.deepcopy(schema['properties']['interrupts'])

if not ('required' in schema and 'interrupts' in schema['required']):
return
if 'interrupts' not in schema['properties'] or 'interrupts-extended' in schema['properties']:
return

# Currently no better way to express either 'interrupts' or 'interrupts-extended'
# is required. If this fails validation, the error reporting is the whole
# schema file fails validation
reqlist = [{'required': ['interrupts']}, {'required': ['interrupts-extended']}]
if 'oneOf' in schema:
if 'allOf' not in schema:
schema['allOf'] = []
schema['allOf'].append({'oneOf': reqlist})
else:
schema['oneOf'] = reqlist
schema['required'].remove('interrupts')
schema['properties']['interrupts-extended'] = copy.deepcopy(schema['properties']['interrupts'])

if 'required' in schema and 'interrupts' in schema['required'] and \
(not len(path) or path[-1] != 'oneOf'):
# Currently no better way to express either 'interrupts' or 'interrupts-extended'
# is required. If this fails validation, the error reporting is the whole
# schema file fails validation
reqlist = [{'required': ['interrupts']}, {'required': ['interrupts-extended']}]
if 'oneOf' in schema:
if 'allOf' not in schema:
schema['allOf'] = []
schema['allOf'].append({'oneOf': reqlist})
else:
schema['oneOf'] = reqlist
schema['required'].remove('interrupts')
if len(schema['required']) == 0:
schema.pop('required')


known_variable_matrix_props = {
Expand All @@ -327,7 +326,7 @@ def fixup_sub_schema(schema, path=[]):
return

schema.pop('description', None)
fixup_interrupts(schema)
fixup_interrupts(schema, path)
fixup_node_props(schema)

# 'additionalProperties: true' doesn't work with 'unevaluatedProperties', so
Expand Down

0 comments on commit 9150864

Please sign in to comment.