responder
responder copied to clipboard
openapi validator
The #202 demonstrates, it is very easy to introduce an error in openapi documentation.
With some sort of openapi validator in place such problems could be revealed quickly.
Possible level of implementation are:
- just advice developers to validate generated openapi spec.
- Example of such validation, possibly by means of test case, would be enough. For validation, https://github.com/p1c2u/openapi-spec-validator could be a candidate (I have no real experience with that)
- make the validation optional part of application startup.
API Star does already provides this, with apistar.validate(schema)
I'm not quite sure on first pass how responder is using APIStar for the docs.
@tomchristie Wow, the Apistar looks as another of my dreams getting fulfilled.
There are only 3 or 4 "apistar" strings in "responsder" code and key point showing how is the OpenAPI being built is here
Yup. The bit that confused me slightly was the docs integration here: https://github.com/kennethreitz/responder/blob/83ff361672980c5f9d9c36c3940ba156a76ae2b0/responder/api.py#L559
Which isn't in line with the documented API usage here: https://docs.apistar.com/api-documentation/ tho it may be that @kennethreitz bumped into an issue there or something.
As it happens, given that responder is using the SwaggerUI interface, it could easily just drop the apistar bit since that's not really adding anything much beyond providing the templates in a pre-packaged manner.
apispec, which responder is using under the hood to build OpenAPI specifications, also has validation functionality
pip install --pre 'apispec[validation]'
from apispec.utils import validate_spec
# Raises an error if OpenAPI spec is invalid
validate_spec(api._apispec)