Skip to content

Commit

Permalink
fixups: Skip defaulting minItems/maxItems to the same size on if/then…
Browse files Browse the repository at this point in the history
…/else schemas

The intent was that if/then/else schemas are not complete, but add to
the top-level schema. A common pattern is increasing the minimum or
decreasing the maximum number of entries for a property. Adding an
implicit minItems/maxItems defeats this. Now that we have the full
schema path available, skip doing this for if/then/else schemas.

Signed-off-by: Rob Herring <robh@kernel.org>
  • Loading branch information
robherring committed Oct 25, 2023
1 parent 2d5d20e commit 79243b1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions dtschema/fixups.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ def _fixup_scalar_to_array(subschema):
subschema['items'] = [{'items': [_extract_single_schemas(subschema)]}]


def _fixup_items_size(schema):
def _fixup_items_size(schema, path=[]):
# Make items list fixed size-spec
if isinstance(schema, list):
for l in schema:
_fixup_items_size(l)
_fixup_items_size(l, path=path)
elif isinstance(schema, dict):
schema.pop('description', None)
if 'items' in schema:
Expand All @@ -213,12 +213,13 @@ def _fixup_items_size(schema):
if 'maxItems' not in schema:
schema['maxItems'] = c

_fixup_items_size(schema['items'])
_fixup_items_size(schema['items'], path=path + ['items'])

elif 'maxItems' in schema and 'minItems' not in schema:
schema['minItems'] = schema['maxItems']
elif 'minItems' in schema and 'maxItems' not in schema:
schema['maxItems'] = schema['minItems']
elif not {'then', 'else'} & set(path):
if 'maxItems' in schema and 'minItems' not in schema:
schema['minItems'] = schema['maxItems']
elif 'minItems' in schema and 'maxItems' not in schema:
schema['maxItems'] = schema['minItems']


def fixup_schema_to_201909(schema):
Expand Down Expand Up @@ -275,7 +276,7 @@ def fixup_vals(schema, path=[]):
_fixup_int_array_items_to_matrix(schema, path=path)
_fixup_string_to_array(schema)
_fixup_scalar_to_array(schema)
_fixup_items_size(schema)
_fixup_items_size(schema, path=path)

fixup_schema_to_201909(schema)

Expand Down

0 comments on commit 79243b1

Please sign in to comment.