Skip to content

Commit

Permalink
openapijson2schema/command.py: throw error instead of proceeding
Browse files Browse the repository at this point in the history
If we can't find either 'swagger' or 'openapi' keys, previously we'd
get an UnboundLocalError because of an undefined variable. Even if we
fixed that, it is probably bad to continue with command flow when the
behavior is not well defined. Instead throw an error to exit execution
immediately.

Fixes instrumenta#16.
  • Loading branch information
kevinburkesegment authored and larsks committed Mar 30, 2023
1 parent e513c8b commit 242c5c7
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openapi2jsonschema/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def default(output, schema, prefix, stand_alone, expanded, kubernetes, strict):
version = data["swagger"]
elif "openapi" in data:
version = data["openapi"]
else:
raise ValueError("cannot convert data to JSON because we could not find 'openapi' or 'swagger' keys")

if not os.path.exists(output):
os.makedirs(output)
Expand Down

0 comments on commit 242c5c7

Please sign in to comment.