Skip to content

"KeyError: properties" when parsing OpenAPI spec from Kubernetes #54

Description

@larsks

I would like to be able to validate manifests targeting our local k8s cluster. There are invariably CRDs in these manifests. I'm fetching the complete openapi spec from the cluster like this:

curl -o openapi.json -H 'Authorization: Bearer ...' https://api.cluster.example.com:6443/openapi/v2

And then attempting to convert these into json schemas like this:

openapi2jsonschema openapi.json --expanded --kubernetes --strict

This fails with:

Generating shared definitions
Traceback (most recent call last):
  File "/home/lars/.local/bin/openapi2jsonschema", line 8, in <module>
    sys.exit(default())
  File "/home/lars/.local/pipx/venvs/openapi2jsonschema/lib64/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/lars/.local/pipx/venvs/openapi2jsonschema/lib64/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/lars/.local/pipx/venvs/openapi2jsonschema/lib64/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/lars/.local/pipx/venvs/openapi2jsonschema/lib64/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/lars/.local/pipx/venvs/openapi2jsonschema/lib64/python3.9/site-packages/openapi2jsonschema/command.py", line 99, in default
    if expanded and "apiVersion" in type_def["properties"]:
KeyError: 'properties'

I've attached the openapi spec to this issue.

openapi.json.txt

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions