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

KeyError when a definition doesn't have "properties" #49

Open
mengqiy opened this issue Apr 16, 2021 · 2 comments
Open

KeyError when a definition doesn't have "properties" #49

mengqiy opened this issue Apr 16, 2021 · 2 comments

Comments

@mengqiy
Copy link

mengqiy commented Apr 16, 2021

if expanded and "apiVersion" in type_def["properties"]:
will cause KeyError when there is no "properties" in some schema (CRDs and some new built-in types in OSS k8s).

For examples:

  "io.gke.nodemanagement.v1alpha1.UpdateInfo": {
      "type": "object",
      "x-kubernetes-group-version-kind": [
        {
          "group": "nodemanagement.gke.io",
          "kind": "UpdateInfo",
          "version": "v1alpha1"
        }
      ]
    },
@garethahealy
Copy link

Am seeing the same error:

Traceback (most recent call last):
  File "/Users/garethhealy/.pyenv/versions/3.8.2/bin/openapi2jsonschema", line 10, in <module>
    sys.exit(default())
  File "/Users/garethhealy/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/garethhealy/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/garethhealy/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/garethhealy/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/garethhealy/.pyenv/versions/3.8.2/lib/python3.8/site-packages/openapi2jsonschema/command.py", line 99, in default
    if expanded and "apiVersion" in type_def["properties"]:
KeyError: 'properties'

any workaround?

@piotrminkina
Copy link

piotrminkina commented Aug 13, 2021

Try below command for workaround, but first You must install jq. In this example I fetch OpenAPI directly from Kubernetes API, so if You want parse contents from file instead of URL then replace curl with cat. This command should work fine in BASH or ZSH, but not SH.

openapi2jsonschema \
    --output output_dir \
    --kubernetes \
    --stand-alone \
    --strict \
    file://<(curl -sSL http://localhost:8001/openapi/v2 | jq '.definitions[] |= if .["x-kubernetes-group-version-kind"] then . + {properties: (.properties // {})} else . end')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants