Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add constructor to handle equal sign (=) #104

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion scripts/openapi2jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def allow_null_optional_fields(data, parent=None, grand_parent=None, key=None):
elif isinstance(v, str):
is_non_null_type = k == "type" and v != "null"
has_required_fields = grand_parent and "required" in grand_parent
if is_non_null_type and not has_required_field:
if is_non_null_type and not has_required_fields:
new_v = [v, "null"]
new[k] = new_v
return new
Expand Down Expand Up @@ -106,6 +106,16 @@ def write_schema_file(schema, filename):
print("JSON schema written to {filename}".format(filename=filename))


def construct_value(load, node):
# Handle nodes that start with '='
# See https://github.com/yaml/pyyaml/issues/89
if not isinstance(node, yaml.ScalarNode):
raise yaml.constructor.ConstructorError(
"while constructing a value",
node.start_mark,
"expected a scalar, but found %s" % node.id, node.start_mark
)
yield str(node.value)


if __name__ == "__main__":
Expand All @@ -120,6 +130,7 @@ def write_schema_file(schema, filename):
f = open(crdFile)
with f:
defs = []
yaml.SafeLoader.add_constructor(u'tag:yaml.org,2002:value', construct_value)
for y in yaml.load_all(f, Loader=yaml.SafeLoader):
if y is None:
continue
Expand Down