Skip to content

Commit

Permalink
Avoid IndexError when definition titles have less than 3 components
Browse files Browse the repository at this point in the history
This will cause `openapi2jsonschema to skip definitions that have
fewer than 3 components in the name (like `v1.APIGroup`), rather than
crashing with an IndexError.

Closes instrumenta#57
  • Loading branch information
larsks committed Mar 30, 2023
1 parent eeed250 commit e513c8b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions openapi2jsonschema/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ def default(output, schema, prefix, stand_alone, expanded, kubernetes, strict):
for title in components:
kind = title.split(".")[-1].lower()
if kubernetes:
group = title.split(".")[-3].lower()
api_version = title.split(".")[-2].lower()
try:
group = title.split(".")[-3].lower()
api_version = title.split(".")[-2].lower()
except IndexError:
error(f'unable to determine group and apiversion from {title}')
continue
specification = components[title]
specification["$schema"] = "http://json-schema.org/schema#"
specification.setdefault("type", "object")
Expand Down

0 comments on commit e513c8b

Please sign in to comment.