encode / apistar

The Web API toolkit. 🛠
https://docs.apistar.com
BSD 3-Clause "New" or "Revised" License
5.57k stars 411 forks source link

KeyError on invoking `apistar validate` #651

Open Fak3 opened 5 years ago

Fak3 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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