diff options
author | Stephen Finucane <stephen@that.guru> | 2018-11-15 13:57:58 +0100 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2018-12-22 17:19:07 +0000 |
commit | 08d1459a4a400083c92f8d7cf7738899b560bdf0 (patch) | |
tree | 657dc060fae0a73a1ec79dd2ad84e0d4c0575e27 /releasenotes | |
parent | f74e54a38d2dbc628ed47bb7cd5c2cbfb5833652 (diff) | |
download | patchwork-08d1459a4a400083c92f8d7cf7738899b560bdf0.tar patchwork-08d1459a4a400083c92f8d7cf7738899b560bdf0.tar.gz |
Add REST API validation using OpenAPI schema
Add validation using the rather excellent 'openapi_core' library. The
biggest issue we have to contend with is the fact that 'openapi_core'
expects us to be able to provide a templated URL string for each request
(e.g. '/api/patches/123/' would become '/api/patches/<id>/') and Django
doesn't provide a way to do this [*]. We work around this by
reverse-engineering some of the Django code to turn a URL to its
matching regex, which we can then easily convert into a template string.
It's kind of hacky and not at all portable but, crucially, it does work
and has highlighted some nice bugs in the API that have already merged.
Going forward, we can probably modify 'openapi_core' somewhat to remove
the need for the templated URL string. If and when this happens, most of
the funkier code here can happily go away.
[*] Django 2.0+ [1] does actually provide a way to do template
string-based URLs and in fact recommends them now, with regexes being
reserved for more advanced corner cases. However, we don't want to drop
support for the Django 1.11 yet as it is the most recent LTS release.
[1] https://docs.djangoproject.com/en/2.1/ref/urls/#django.urls.path
Signed-off-by: Stephen Finucane <stephen@that.guru>
Diffstat (limited to 'releasenotes')
0 files changed, 0 insertions, 0 deletions