instrumenta / instrumenta/openapi2jsonschema

"KeyError: properties" when parsing OpenAPI spec from Kubernetes

Open
#54 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
248
Forks
95
PR merge metrics
No merged PRs in 30d

Description

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
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](https://github.com/instrumenta/openapi2jsonschema/files/7399639/openapi.json.txt)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in openapi2jsonschema/command.py at the reported line 99, then reproduce the failure with the attached openapi.json.txt and the documented openapi2jsonschema command. Check how definitions without a "properties" key are handled during expanded Kubernetes conversion; done means the attached Kubernetes OpenAPI spec no longer raises this KeyError.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.