Skip to content

Commit

Permalink
chore: updated spec-*.py scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gierschv committed Jun 5, 2023
1 parent 5625663 commit 82d721b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions spec/spec-flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from copy import deepcopy
import ruamel.yaml
from ruamel.yaml.scalarstring import PreservedScalarString, preserve_literal
from ruamel.yaml.compat import string_types

infname = 'openapi.yaml'
outfname = 'openapi-flatten.yaml'
Expand All @@ -21,7 +20,7 @@ def walk_tree(base, in_inheritance=False):
if not in_inheritance and k == '$ref':
schema_key = v.split('/').pop()
models_used_as_ref.append(schema_key)
if isinstance(v, string_types) and '\n' in v:
if isinstance(v, str) and '\n' in v:
base[k] = preserve_literal(v)
else:
# flatten allOf for code generator
Expand Down Expand Up @@ -49,7 +48,7 @@ def walk_tree(base, in_inheritance=False):
return 'remove'
elif isinstance(base, list):
for idx, elem in reversed(list(enumerate(base))):
if isinstance(elem, string_types) and '\n' in elem:
if isinstance(elem, str) and '\n' in elem:
base[idx] = preserve_literal(v)
else:
result = walk_tree(elem)
Expand Down
5 changes: 2 additions & 3 deletions spec/spec-lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@

import ruamel.yaml
from ruamel.yaml.scalarstring import PreservedScalarString, preserve_literal
from ruamel.yaml.compat import string_types

infname = "openapi.yaml"

def walk_tree(base):
if isinstance(base, dict):
for k in base:
v = base[k]
if isinstance(v, string_types) and '\n' in v:
if isinstance(v, str) and '\n' in v:
base[k] = preserve_literal(v)
else:
walk_tree(v)
elif isinstance(base, list):
for idx, elem in enumerate(base):
if isinstance(elem, string_types) and '\n' in elem:
if isinstance(elem, str) and '\n' in elem:
base[idx] = preserve_literal(v)
else:
walk_tree(elem)
Expand Down

0 comments on commit 82d721b

Please sign in to comment.