Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

KeyError on invoking apistar validate #651

Open
Fak3 opened this issue Mar 18, 2019 · 2 comments
Open

KeyError on invoking apistar validate #651

Fak3 opened this issue Mar 18, 2019 · 2 comments

Comments

@Fak3
Copy link

Fak3 commented Mar 18, 2019

I tried to validate the schema from README, but got an error:

> apistar validate --path schema.yaml 
Traceback (most recent call last):
  File "/home/u1/.virtualenvs/videospeed/bin/apistar", line 10, in <module>
    sys.exit(cli())
  File "/home/u1/.virtualenvs/videospeed/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/u1/.virtualenvs/videospeed/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/u1/.virtualenvs/videospeed/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/u1/.virtualenvs/videospeed/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/u1/.virtualenvs/videospeed/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/u1/.virtualenvs/videospeed/lib/python3.7/site-packages/apistar/cli.py", line 163, in validate
    }[format]
KeyError: None
@carltongibson
Copy link

carltongibson commented Mar 25, 2019

I'm seeing something related here. With a not-great™ schema I get some a hoped for

typesystem.base.ValidationError: {'info': {'title': 'This field is required.', 'version': 'This field is required.'}, 'paths': ...

But when handling that something else comes up:

During handling of the above exception, another exception occurred:

...
 File "...apistar/cli.py", line 137, in validate
    apistar.validate(content, format=format, encoding=encoding)
  File "...apistar/core.py", line 75, in validate
    value = typesystem.validate_with_positions(token=token, validator=validator)
  File "...typesystem/tokenize/positional_validation.py", line 19, in validate_with_positions
    token = token.lookup(message.index[:-1])
  File "...typesystem/tokenize/tokens.py", line 46, in lookup
    token = token._get_child_token(key)
  File "...typesystem/tokenize/tokens.py", line 95, in _get_child_token
    return self._child_tokens[key]
KeyError: 'info'

So the end result is not great UI. (The underlying ValidationError is super-informative, so ideally that would be surfaced, even if other info isn't available.)

@nielskou
Copy link

I read in the source code that the apistar configuration file must be named apistar.yml and not apistar.yaml. That solved it for me. This is especially confusing because the schema file is named schema.yaml

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

No branches or pull requests

3 participants