summaryrefslogtreecommitdiff
path: root/requirements-test.txt
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2018-11-15 13:57:58 +0100
committerStephen Finucane <stephen@that.guru>2018-12-22 17:19:07 +0000
commit08d1459a4a400083c92f8d7cf7738899b560bdf0 (patch)
tree657dc060fae0a73a1ec79dd2ad84e0d4c0575e27 /requirements-test.txt
parentf74e54a38d2dbc628ed47bb7cd5c2cbfb5833652 (diff)
downloadpatchwork-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 'requirements-test.txt')
-rw-r--r--requirements-test.txt1
1 files changed, 1 insertions, 0 deletions
diff --git a/requirements-test.txt b/requirements-test.txt
index 6c9bd88..cfb8ce7 100644
--- a/requirements-test.txt
+++ b/requirements-test.txt
@@ -2,3 +2,4 @@ mysqlclient==1.3.13
psycopg2-binary==2.7.6
sqlparse==0.2.4
python-dateutil==2.7.5
+openapi-core==0.7.1