instrumenta / openapi2jsonschema

Convert OpenAPI definitions into JSON schemas for all types in the API
Other
226 stars 87 forks source link

Extraction of Schema from K8S 1.12.2 Spec fails with UnboundLocalError #16

Closed dneuhaeuser-zalando closed 5 years ago

dneuhaeuser-zalando commented 6 years ago

When extracting the JSON schema from the Kubernetes 1.12.2 spec I get an UnboundLocalError exception:

$ openapi2jsonschema -o src/zkubelnt/schemas/kubernetes-json-schema/master/v1.12.2-standalone-strict --kubernetes --stand-alone --strict https://raw.githubusercontent.com/kubernetes/kubernetes/v1.12.2/api/openapi-spec/swagger.json
Downloading schema
Parsing schema
Traceback (most recent call last):
  File "/Users/dneuhaeuser/.pyenv/versions/zkubelnt-schema/bin/openapi2jsonschema", line 11, in <module>
    sys.exit(default())
  File "/Users/dneuhaeuser/.pyenv/versions/3.6.4/envs/zkubelnt-schema/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/dneuhaeuser/.pyenv/versions/3.6.4/envs/zkubelnt-schema/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/dneuhaeuser/.pyenv/versions/3.6.4/envs/zkubelnt-schema/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/dneuhaeuser/.pyenv/versions/3.6.4/envs/zkubelnt-schema/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/dneuhaeuser/.pyenv/versions/3.6.4/envs/zkubelnt-schema/lib/python2.7/site-packages/openapi2jsonschema/command.py", line 158, in default
    if version < '3':
UnboundLocalError: local variable 'version' referenced before assignment
garethr commented 5 years ago

Looking at the code I think what's happening is you're not being able to load the content from: https://raw.githubusercontent.com/kubernetes/kubernetes/v1.12.2/api/openapi-spec/swagger.json

If that's a YAML document and it doesn't contain either the swagger or openapi key then this failure happens. It should provide a better error ideally.

This appears to be environmental, as I was just able to run this OK here.

dneuhaeuser-zalando commented 5 years ago

Hm, I tried it myself again just now and it does indeed work just fine.