From 4957b06873ba16d6422ec2b71c39396d7bdaf20e Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Mon, 24 Oct 2022 18:35:49 -0700 Subject: [PATCH] openapijson2schema/command.py: throw error instead of proceeding 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 #16. --- openapi2jsonschema/command.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openapi2jsonschema/command.py b/openapi2jsonschema/command.py index 9cd1bfc..42dc792 100644 --- a/openapi2jsonschema/command.py +++ b/openapi2jsonschema/command.py @@ -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)