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

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

Closed
dneuhaeuser-zalando opened this issue Oct 11, 2018 · 2 comments · May be fixed by #62
Closed

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

dneuhaeuser-zalando opened this issue Oct 11, 2018 · 2 comments · May be fixed by #62

Comments

@dneuhaeuser-zalando
Copy link

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
Copy link
Collaborator

garethr commented Nov 18, 2018

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
Copy link
Author

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

kevinburkesegment added a commit to kevinburkesegment/openapi2jsonschema that referenced this issue Oct 25, 2022
If we can't find either 'swagger' or 'openapi' keys, previously we'd
get an UnboundLocalError because of an undefined variable. Even if we
fixed that, it is probably bad to continue with command flow when the
behavior is not well defined. Instead throw an error to exit execution
immediately.

Fixes instrumenta#16.
larsks pushed a commit to larsks/openapi2jsonschema that referenced this issue Mar 30, 2023
If we can't find either 'swagger' or 'openapi' keys, previously we'd
get an UnboundLocalError because of an undefined variable. Even if we
fixed that, it is probably bad to continue with command flow when the
behavior is not well defined. Instead throw an error to exit execution
immediately.

Fixes instrumenta#16.
lirik90 pushed a commit to lirik90/swagger2jsonschema that referenced this issue Mar 30, 2024
…ons/actions/checkout-4.1.2

Bump actions/checkout from 4.1.1 to 4.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants