Skip to content

Commit

Permalink
More OAS 3.0 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Nov 3, 2023
1 parent 7934033 commit 5c7ea7d
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions ogc/bblocks/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,11 +696,27 @@ def apply_fixes(parent):
elif len(prop_val) == 1:
parent['type'] = prop_val[0]
else:
one_of = {'oneOf': [{'type': v} for v in prop_val]}
if 'oneOf' in parent:
one_of = {'anyOf': [{'type': v} for v in prop_val]}
if 'anyOf' in parent:
parent.setdefault('allOf', []).append(one_of)
else:
parent['oneOf'] = one_of
parent['anyOf'] = one_of

if 'oneOf' in parent:
add_nullable = False
for_deletion = []
for oo in parent['oneOf']:
if oo.get('type') == 'null':
del oo['type']
add_nullable = True
if not oo:
for_deletion.append(oo)
for item in for_deletion:
parent['oneOf'].remove(item)
if not parent['oneOf']:
del parent['oneOf']
if add_nullable:
parent['nullable'] = True

def walk(subschema, schema_id: str | Path, is_properties: bool = False) -> tuple[dict, str, str | Path]:
schema_version = None
Expand Down Expand Up @@ -749,7 +765,10 @@ def walk(subschema, schema_id: str | Path, is_properties: bool = False) -> tuple

if ref_version:
ref_schema['x-schema-version'] = ref_version
if isinstance(ref_id, Path):

if root_ref_id == cur_ref_id:
ref_id = schema_url
elif isinstance(ref_id, Path):
ref_id = urljoin(schema_url, os.path.relpath(ref_id, schema_fn))
ref_schema['x-schema-source'] = ref_id

Expand Down

0 comments on commit 5c7ea7d

Please sign in to comment.