Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add validate spec command (#806)

sarayourfriend96f499687518
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml
index 4c9368526..35f2151b6 100644
--- a/.github/workflows/ci_cd.yml
+++ b/.github/workflows/ci_cd.yml
@@ -18,12 +18,6 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
- - name: Rebase
- if: github.event.input.rebase
- run: |
- git fetch main
- git rebase main
-
- name: Setup Python
uses: actions/setup-python@v2
with:
@@ -176,7 +170,7 @@ jobs:
- build-images
steps:
- name: Checkout repository
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Setup just
uses: extractions/setup-just@v1
@@ -194,6 +188,35 @@ jobs:
- name: Test ReDoc site
run: just api-doctest
+ validate-openapi-spec:
+ name: Validate Open API spec
+ runs-on: ubuntu-latest
+ needs:
+ - build-images
+ steps:
+ - uses: actions/checkout@v3
+ - uses: extractions/setup-just@v1
+
+ - name: Download all images
+ uses: actions/download-artifact@v2
+ with:
+ path: /tmp
+
+ - name: Load all images
+ run: |
+ docker load --input /tmp/api/api.tar
+ docker load --input /tmp/ingestion_server/ingestion_server.tar
+
+ - name: Run check
+ run: just dj validateopenapischema
+
+ - name: Upload schema on failure
+ if: failure()
+ uses: actions/upload-artifact@v2
+ with:
+ name: openverse-api-openapi-schema.yaml
+ path: ./api/openapi.yaml
+
django-check:
name: Run Django check
runs-on: ubuntu-latest
diff --git a/.gitignore b/.gitignore
index 1e8d4652a..34f3ae3d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -140,3 +140,5 @@ ccbot/crawl_plan.yml
ingestion_server/ingestion_server/db
ingestion_server/ingestion_server/lock
.vscode
+
+openapi.yaml
diff --git a/api/Pipfile b/api/Pipfile
index 544e0da74..1564c66b9 100644
--- a/api/Pipfile
+++ b/api/Pipfile
@@ -17,6 +17,7 @@ furo = "*"
myst-parser = "*"
factory-boy = "*"
fakeredis = "*"
+openapi-spec-validator = "*"
[packages]
aws-requests-auth = "*"
diff --git a/api/Pipfile.lock b/api/Pipfile.lock
index 9b453d9a8..38f64e24f 100644
--- a/api/Pipfile.lock
+++ b/api/Pipfile.lock
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
- "sha256": "39a501e005f1bbaf55679cd325cd281599b45f33e6f8814f64eda096e82d33a9"
+ "sha256": "38863b90e28cd5f3ca58cb25c5be39b101cc5ed7b986816eb04aebcce962a3c1"
},
"pipfile-spec": 6,
"requires": {
@@ -42,19 +42,19 @@
},
"boto3": {
"hashes": [
- "sha256:44026e44549148dbc5b261ead5f6b339e785680c350ef621bf85f7e2fca05b49",
- "sha256:b2d9d55f123a9a91eea2fd8e379d90abf37634420fbb45c22d67e10b324ec71b"
+ "sha256:09fb94008bd1f2566ef79ec7d8dd7a233b5da67f3b2536e30432eb8e88022d4d",
+ "sha256:9fab8acec76008797be4671d514f39f1163ba044c0a0bce8d5afe8b52cbd5550"
],
"index": "pypi",
- "version": "==1.24.46"
+ "version": "==1.24.56"
},
"botocore": {
"hashes": [
- "sha256:8e9556ef9f7f492e0755437a1430e32f63ddaf6df61c105957805067b5e22dbb",
- "sha256:ac491c54cdf4126c98a999c5d473d734dc91c5b1e003d0fdafd5007d1408d046"
+ "sha256:81101abab2013992a84019739d85a6fa8ec6f1f42fb09ad07e0bf4c8f0efce60",
+ "sha256:81df81b1a1c5608b3a7aca6a837acb27552c3ecc92584a58b171c60754b1d4eb"
],
"markers": "python_version >= '3.7'",
- "version": "==1.27.49"
+ "version": "==1.27.56"
},
"certifi": {
"hashes": [
@@ -135,11 +135,11 @@
},
"charset-normalizer": {
"hashes": [
- "sha256:5189b6f22b01957427f35b6a08d9a0bc45b46d3788ef5a92e978433c7a35f8a5",
- "sha256:575e708016ff3a5e3681541cb9d79312c416835686d054a23accb873b254f413"
+ "sha256:5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845",
+ "sha256:83e9a75d1911279afd89352c68b45348559d1fc0506b054b346651b5e7fee29f"
],
"markers": "python_version >= '3.6'",
- "version": "==2.1.0"
+ "version": "==2.1.1"
},
"coreapi": {
"hashes": [
@@ -271,11 +271,11 @@
},
"django-storages": {
"hashes": [
- "sha256:3ef9dd5a2ac7221b571aa32f72a94a542b6b03fbd393e1c18e64d2a4006bfddf",
- "sha256:d4fed98bbfb5347096ddfac2a6665d5133c788b9ec32c156ec5f7fb02ae57335"
+ "sha256:3540b45618b04be2c867c0982e8d2bd8e34f84dae922267fcebe4691fb93daf0",
+ "sha256:b3d98ecc09f1b1627c2b2cf430964322ce4e08617dbf9b4236c16a32875a1e0b"
],
"index": "pypi",
- "version": "==1.13"
+ "version": "==1.13.1"
},
"django-tqdm": {
"hashes": [
@@ -747,10 +747,10 @@
},
"pytz": {
"hashes": [
- "sha256:1e760e2fe6a8163bc0b3d9a19c4f84342afa0a2affebfaa84b01b978a02ecaa7",
- "sha256:e68985985296d9a66a881eb3193b0906246245294a881e7c8afe623866ac6a5c"
+ "sha256:220f481bdafa09c3955dfbdddb7b57780e9a94f5127e35456a48589b9e0c0197",
+ "sha256:cea221417204f2d1a2aa03ddae3e867921971d0d76f14d87abb4414415bbdcf5"
],
- "version": "==2022.1"
+ "version": "==2022.2.1"
},
"redis": {
"hashes": [
@@ -793,13 +793,17 @@
},
"ruamel.yaml.clib": {
"hashes": [
+ "sha256:066f886bc90cc2ce44df8b5f7acfc6a7e2b2e672713f027136464492b0c34d7c",
"sha256:0847201b767447fc33b9c235780d3aa90357d20dd6108b92be544427bea197dd",
"sha256:1070ba9dd7f9370d0513d649420c3b362ac2d687fe78c6e888f5b12bf8bc7bee",
"sha256:1866cf2c284a03b9524a5cc00daca56d80057c5ce3cdc86a52020f4c720856f0",
+ "sha256:1b4139a6ffbca8ef60fdaf9b33dec05143ba746a6f0ae0f9d11d38239211d335",
+ "sha256:210c8fcfeff90514b7133010bf14e3bad652c8efde6b20e00c43854bf94fa5a6",
"sha256:221eca6f35076c6ae472a531afa1c223b9c29377e62936f61bc8e6e8bdc5f9e7",
"sha256:31ea73e564a7b5fbbe8188ab8b334393e06d997914a4e184975348f204790277",
"sha256:3fb9575a5acd13031c57a62cc7823e5d2ff8bc3835ba4d94b921b4e6ee664104",
"sha256:4ff604ce439abb20794f05613c374759ce10e3595d1867764dd1ae675b85acbd",
+ "sha256:61bc5e5ca632d95925907c569daa559ea194a4d16084ba86084be98ab1cec1c6",
"sha256:6e7be2c5bcb297f5b82fee9c665eb2eb7001d1050deaba8471842979293a80b0",
"sha256:72a2b8b2ff0a627496aad76f37a652bcef400fd861721744201ef1b45199ab78",
"sha256:77df077d32921ad46f34816a9a16e6356d8100374579bc35e15bab5d4e9377de",
@@ -815,6 +819,7 @@
"sha256:ada3f400d9923a190ea8b59c8f60680c4ef8a4b0dfae134d2f2ff68429adfab5",
"sha256:bf75d28fa071645c529b5474a550a44686821decebdd00e21127ef1fd566eabe",
"sha256:cfdb9389d888c5b74af297e51ce357b800dd844898af9d4a547ffc143fa56751",
+ "sha256:d3c620a54748a3d4cf0bcfe623e388407c8e85a4b06b8188e126302bcab93ea8",
"sha256:d67f273097c368265a7b81e152e07fb90ed395df6e552b9fa858c6d2c9f42502",
"sha256:dc6a613d6c74eef5a14a214d433d06291526145431c3b964f5e16529b1842bed",
"sha256:de9c6b8a1ba52919ae919f3ae96abb72b994dd0350226e28f3686cb4f142165c"
@@ -832,19 +837,19 @@
},
"sentry-sdk": {
"hashes": [
- "sha256:011155f11ab828a977fe8a60c5b534c30f49d70c9938362536d206bb230bb519",
- "sha256:9921e76e29135aa1fa65fe231aaaef47355f85470c5ec59ce32715e22e6340b6"
+ "sha256:2d7ec7bc88ebbdf2c4b6b2650b3257893d386325a96c9b723adcd31033469b63",
+ "sha256:b4b41f90951ed83e7b4c176eef021b19ecba39da5b73aca106c97a9b7e279a90"
],
"index": "pypi",
- "version": "==1.9.2"
+ "version": "==1.9.5"
},
"setuptools": {
"hashes": [
- "sha256:63f463b90ff5e0a1422010100268fd688e15c44ae0798659013c8412963e15e4",
- "sha256:9b5d2cb8df48f005825654e0cb17217418317e4d996c035f0bca7cbaeb8acf51"
+ "sha256:7f4bc85450898a09f76ebf28b72fa25bc7111f6c7d665d514a60bba9c75ef2a9",
+ "sha256:a3ca5857c89f82f5c9410e8508cb32f4872a3bafd4aa7ae122a24ca33bccc750"
],
"markers": "python_version >= '3.7'",
- "version": "==64.0.0"
+ "version": "==65.2.0"
},
"six": {
"hashes": [
@@ -887,11 +892,11 @@
},
"urllib3": {
"hashes": [
- "sha256:c33ccba33c819596124764c23a97d25f32b28433ba0dedeb77d873a38722c9bc",
- "sha256:ea6e8fb210b19d950fab93b60c9009226c63a28808bc8386e05301e25883ac0a"
+ "sha256:3fa96cf423e6987997fc326ae8df396db2a8b7c667747d47ddd8ecba91f4a74e",
+ "sha256:b930dd878d5a8afb066a637fbb35144fe7901e3b209d1cd4f524bd0e9deee997"
],
- "markers": "python_version >= '3.5'",
- "version": "==1.26.11"
+ "markers": "python_version >= '3.6'",
+ "version": "==1.26.12"
},
"webob": {
"hashes": [
@@ -1054,10 +1059,10 @@
},
"asttokens": {
"hashes": [
- "sha256:8444353e4e2a99661c8dfb85ec9c02eedded08f0006234bff7db44a06840acc2",
- "sha256:f5589ef8518f73dd82c15e1c19f795d8a62c133485e557c04443d4a1a730cf9f"
+ "sha256:c61e16246ecfb2cde2958406b4c8ebc043c9e6d73aaa83c941673b35e5d3a76b",
+ "sha256:e3305297c744ae53ffa032c45dc347286165e4ffce6875dc662b205db0623d86"
],
- "version": "==2.0.7"
+ "version": "==2.0.8"
},
"async-timeout": {
"hashes": [
@@ -1183,11 +1188,11 @@
},
"charset-normalizer": {
"hashes": [
- "sha256:5189b6f22b01957427f35b6a08d9a0bc45b46d3788ef5a92e978433c7a35f8a5",
- "sha256:575e708016ff3a5e3681541cb9d79312c416835686d054a23accb873b254f413"
+ "sha256:5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845",
+ "sha256:83e9a75d1911279afd89352c68b45348559d1fc0506b054b346651b5e7fee29f"
],
"markers": "python_version >= '3.6'",
- "version": "==2.1.0"
+ "version": "==2.1.1"
},
"click": {
"hashes": [
@@ -1246,10 +1251,10 @@
},
"executing": {
"hashes": [
- "sha256:4ce4d6082d99361c0231fc31ac1a0f56979363cc6819de0b1410784f99e49105",
- "sha256:ea278e2cf90cbbacd24f1080dd1f0ac25b71b2e21f50ab439b7ba45dd3195587"
+ "sha256:9c745f80cda11eb22b62cbecf21156491a794eb56ab06f9d286a44e62822b24e",
+ "sha256:d1cd87c2e371e9966261410c5b3769d6df2f9e4a79a83eebd2662dd3388f9833"
],
- "version": "==0.9.1"
+ "version": "==0.10.0"
},
"factory-boy": {
"hashes": [
@@ -1261,11 +1266,11 @@
},
"faker": {
"hashes": [
- "sha256:172e45220b7a46743f4fb58cf380adb306d5c3ab1c0b0d97062508474cec5ff8",
- "sha256:7c3f8ee807d3916415568169a172bf0893ea9cc3371ab55e4e5f5170d2185bea"
+ "sha256:067a03f64e555261610e69277536072997b4576dbf84b113faef3c06d85b466b",
+ "sha256:0e00bfa1eadf1493f15662edb181222fea4847764cf3f9ff3e66ee0f95c9a644"
],
"markers": "python_version >= '3.6'",
- "version": "==13.15.1"
+ "version": "==14.1.0"
},
"fakeredis": {
"hashes": [
@@ -1547,6 +1552,14 @@
"markers": "python_version >= '3.7'",
"version": "==3.1.2"
},
+ "jsonschema": {
+ "hashes": [
+ "sha256:15062f4cc6f591400cd528d2c355f2cfa6a57e44c820dc783aee5e23d36a831f",
+ "sha256:9892b8d630a82990521a9ca630d3446bd316b5ad54dbe981338802787f3e0d2d"
+ ],
+ "markers": "python_version >= '3.7'",
+ "version": "==4.14.0"
+ },
"livereload": {
"hashes": [
"sha256:776f2f865e59fde56490a56bcc6773b6917366bce0c267c60ee8aaf1a0959869"
@@ -1555,11 +1568,11 @@
},
"locust": {
"hashes": [
- "sha256:d556e70898240deaa08097a7c3eee9456897150246ceec8367b9943580c0a7c6",
- "sha256:e5571de2510bb6293daee6245b3e01a614dce5935b1d5283f709ce5b49125492"
+ "sha256:b1855b1c6413e56f333de86eb6f92df643bdd605369f7a258e8bfdcd9117b833",
+ "sha256:b6bfbdc4cccd4617b6f9637a3eea3b4c0fda681a1531f5566ad66e2c16547ecd"
],
"index": "pypi",
- "version": "==2.10.2"
+ "version": "==2.11.0"
},
"markdown-it-py": {
"hashes": [
@@ -1617,11 +1630,11 @@
},
"matplotlib-inline": {
"hashes": [
- "sha256:a04bfba22e0d1395479f866853ec1ee28eea1485c1d69a6faf00dc3e24ff34ee",
- "sha256:aed605ba3b72462d64d475a21a9296f400a19c4f74a31b59103d2a99ffd5aa5c"
+ "sha256:f1f41aab5328aa5aaea9b16d083b128102f8712542f819fe7e6a420ff581b311",
+ "sha256:f887e5f10ba98e8d2b150ddcf4702c1e5f8b3a20005eb0f74bfdbd360ee6f304"
],
"markers": "python_version >= '3.5'",
- "version": "==0.1.3"
+ "version": "==0.1.6"
},
"mdit-py-plugins": {
"hashes": [
@@ -1633,11 +1646,11 @@
},
"mdurl": {
"hashes": [
- "sha256:6a8f6804087b7128040b2fb2ebe242bdc2affaeaa034d5fc9feeed30b443651b",
- "sha256:f79c9709944df218a4cdb0fcc0b0c7ead2f44594e3e84dc566606f04ad749c20"
+ "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8",
+ "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"
],
"markers": "python_version >= '3.7'",
- "version": "==0.1.1"
+ "version": "==0.1.2"
},
"msgpack": {
"hashes": [
@@ -1712,6 +1725,22 @@
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6'",
"version": "==1.7.0"
},
+ "openapi-schema-validator": {
+ "hashes": [
+ "sha256:2c64907728c3ef78e23711c8840a423f0b241588c9ed929855e4b2d1bb0cf5f2",
+ "sha256:9bae709212a19222892cabcc60cafd903cbf4b220223f48583afa3c0e3cc6fc4"
+ ],
+ "markers": "python_version >= '3.7' and python_version < '4'",
+ "version": "==0.2.3"
+ },
+ "openapi-spec-validator": {
+ "hashes": [
+ "sha256:06900ac4d546a1df3642a779da0055be58869c598e3042a2fef067cfd99d04d0",
+ "sha256:97f258850afc97b048f7c2653855e0f88fa66ac103c2be5077c7960aca2ad49a"
+ ],
+ "index": "pypi",
+ "version": "==0.4.0"
+ },
"packaging": {
"hashes": [
"sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb",
@@ -1845,11 +1874,11 @@
},
"pygments": {
"hashes": [
- "sha256:5eb116118f9612ff1ee89ac96437bb6b49e8f04d8a13b514ba26f620208e26eb",
- "sha256:dc9c10fb40944260f6ed4c688ece0cd2048414940f1cea51b8b226318411c519"
+ "sha256:56a8508ae95f98e2b9bdf93a6be5ae3f7d8af858b43e02c5a2ff083726be40c1",
+ "sha256:f643f331ab57ba3c9d89212ee4a2dabc6e94f117cf4eefde99a0574720d14c42"
],
"markers": "python_version >= '3.6'",
- "version": "==2.12.0"
+ "version": "==2.13.0"
},
"pyparsing": {
"hashes": [
@@ -1859,6 +1888,33 @@
"markers": "python_full_version >= '3.6.8'",
"version": "==3.0.9"
},
+ "pyrsistent": {
+ "hashes": [
+ "sha256:0e3e1fcc45199df76053026a51cc59ab2ea3fc7c094c6627e93b7b44cdae2c8c",
+ "sha256:1b34eedd6812bf4d33814fca1b66005805d3640ce53140ab8bbb1e2651b0d9bc",
+ "sha256:4ed6784ceac462a7d6fcb7e9b663e93b9a6fb373b7f43594f9ff68875788e01e",
+ "sha256:5d45866ececf4a5fff8742c25722da6d4c9e180daa7b405dc0a2a2790d668c26",
+ "sha256:636ce2dc235046ccd3d8c56a7ad54e99d5c1cd0ef07d9ae847306c91d11b5fec",
+ "sha256:6455fc599df93d1f60e1c5c4fe471499f08d190d57eca040c0ea182301321286",
+ "sha256:6bc66318fb7ee012071b2792024564973ecc80e9522842eb4e17743604b5e045",
+ "sha256:7bfe2388663fd18bd8ce7db2c91c7400bf3e1a9e8bd7d63bf7e77d39051b85ec",
+ "sha256:7ec335fc998faa4febe75cc5268a9eac0478b3f681602c1f27befaf2a1abe1d8",
+ "sha256:914474c9f1d93080338ace89cb2acee74f4f666fb0424896fcfb8d86058bf17c",
+ "sha256:b568f35ad53a7b07ed9b1b2bae09eb15cdd671a5ba5d2c66caee40dbf91c68ca",
+ "sha256:cdfd2c361b8a8e5d9499b9082b501c452ade8bbf42aef97ea04854f4a3f43b22",
+ "sha256:d1b96547410f76078eaf66d282ddca2e4baae8964364abb4f4dcdde855cd123a",
+ "sha256:d4d61f8b993a7255ba714df3aca52700f8125289f84f704cf80916517c46eb96",
+ "sha256:d7a096646eab884bf8bed965bad63ea327e0d0c38989fc83c5ea7b8a87037bfc",
+ "sha256:df46c854f490f81210870e509818b729db4488e1f30f2a1ce1698b2295a878d1",
+ "sha256:e24a828f57e0c337c8d8bb9f6b12f09dfdf0273da25fda9e314f0b684b415a07",
+ "sha256:e4f3149fd5eb9b285d6bfb54d2e5173f6a116fe19172686797c056672689daf6",
+ "sha256:e92a52c166426efbe0d1ec1332ee9119b6d32fc1f0bbfd55d5c1088070e7fc1b",
+ "sha256:f87cc2863ef33c709e237d4b5f4502a62a00fab450c9e020892e8e2ede5847f5",
+ "sha256:fd8da6d0124efa2f67d86fa70c851022f87c98e205f0594e1fae044e7119a5a6"
+ ],
+ "markers": "python_version >= '3.7'",
+ "version": "==0.18.1"
+ },
"pytest": {
"hashes": [
"sha256:13d0e3ccfc2b6e26be000cb6568c832ba67ba32e719443bfe725814d3c42433c",
@@ -1893,10 +1949,10 @@
},
"pytz": {
"hashes": [
- "sha256:1e760e2fe6a8163bc0b3d9a19c4f84342afa0a2affebfaa84b01b978a02ecaa7",
- "sha256:e68985985296d9a66a881eb3193b0906246245294a881e7c8afe623866ac6a5c"
+ "sha256:220f481bdafa09c3955dfbdddb7b57780e9a94f5127e35456a48589b9e0c0197",
+ "sha256:cea221417204f2d1a2aa03ddae3e867921971d0d76f14d87abb4414415bbdcf5"
],
- "version": "==2022.1"
+ "version": "==2022.2.1"
},
"pyyaml": {
"hashes": [
@@ -2022,11 +2078,11 @@
},
"setuptools": {
"hashes": [
- "sha256:63f463b90ff5e0a1422010100268fd688e15c44ae0798659013c8412963e15e4",
- "sha256:9b5d2cb8df48f005825654e0cb17217418317e4d996c035f0bca7cbaeb8acf51"
+ "sha256:7f4bc85450898a09f76ebf28b72fa25bc7111f6c7d665d514a60bba9c75ef2a9",
+ "sha256:a3ca5857c89f82f5c9410e8508cb32f4872a3bafd4aa7ae122a24ca33bccc750"
],
"markers": "python_version >= '3.7'",
- "version": "==64.0.0"
+ "version": "==65.2.0"
},
"six": {
"hashes": [
@@ -2132,10 +2188,10 @@
},
"stack-data": {
"hashes": [
- "sha256:77bec1402dcd0987e9022326473fdbcc767304892a533ed8c29888dacb7dddbc",
- "sha256:aa1d52d14d09c7a9a12bb740e6bdfffe0f5e8f4f9218d85e7c73a8c37f7ae38d"
+ "sha256:a90ae7e260f7d15aefeceb46f0a028d4ccb9eb8856475c53e341945342d41ea7",
+ "sha256:b94fed36d725cfabc6d09ed5886913e35eed9009766a1af1d5941b9da3a94aaa"
],
- "version": "==0.3.0"
+ "version": "==0.4.0"
},
"toml": {
"hashes": [
@@ -2188,11 +2244,11 @@
},
"urllib3": {
"hashes": [
- "sha256:c33ccba33c819596124764c23a97d25f32b28433ba0dedeb77d873a38722c9bc",
- "sha256:ea6e8fb210b19d950fab93b60c9009226c63a28808bc8386e05301e25883ac0a"
+ "sha256:3fa96cf423e6987997fc326ae8df396db2a8b7c667747d47ddd8ecba91f4a74e",
+ "sha256:b930dd878d5a8afb066a637fbb35144fe7901e3b209d1cd4f524bd0e9deee997"
],
- "markers": "python_version >= '3.5'",
- "version": "==1.26.11"
+ "markers": "python_version >= '3.6'",
+ "version": "==1.26.12"
},
"virtualenv": {
"hashes": [
diff --git a/api/catalog/api/views/oauth2_views.py b/api/catalog/api/views/oauth2_views.py
index bdf12d68e..db17a03a4 100644
--- a/api/catalog/api/views/oauth2_views.py
+++ b/api/catalog/api/views/oauth2_views.py
@@ -80,7 +80,6 @@ curl \\
type=openapi.TYPE_STRING,
min_length=1,
max_length=150,
- unique=True,
description="A unique human-readable name for your application "
"or project requiring access to the Openverse API.",
),
diff --git a/api/catalog/management/commands/validateopenapischema.py b/api/catalog/management/commands/validateopenapischema.py
new file mode 100644
index 000000000..ff39b5646
--- /dev/null
+++ b/api/catalog/management/commands/validateopenapischema.py
@@ -0,0 +1,42 @@
+from argparse import ArgumentParser
+from pathlib import Path
+
+from django.core.management import BaseCommand, call_command
+
+from openapi_spec_validator import validate_v2_spec
+from openapi_spec_validator.readers import read_from_filename
+
+
+class Command(BaseCommand):
+ def add_arguments(self, parser: ArgumentParser):
+ parser.add_argument(
+ "--output-dir",
+ default=Path(".").absolute(),
+ help=(
+ "The direction into which to output the spec file. "
+ "Defaults the the current working directory."
+ ),
+ )
+
+ def handle_validation(self, spec_dict: dict):
+ """
+ This method should raise an error if the spec is not valid.
+ """
+ validate_v2_spec(spec_dict)
+
+ invalid_paths = [p for p in spec_dict["paths"].keys() if not p.endswith("/")]
+
+ assert invalid_paths == [], (
+ "All paths must end with a trailing slash. "
+ f"Found {len(invalid_paths)} missing a trailing "
+ f"slash: {', '.join(invalid_paths)}"
+ )
+
+ def handle(self, *args, **options):
+ file_path = (Path(options["output_dir"]).absolute() / "openapi.yaml").absolute()
+ call_command("generate_swagger", file_path, overwrite=True)
+ spec_dict, spec_url = read_from_filename(file_path)
+ self.handle_validation(spec_dict)
+ # Only remove the file when there are no errros to ease debugging.
+ # Therefore, we don't `try/except` the call to `handle_validation`
+ file_path.unlink()
diff --git a/api/catalog/settings.py b/api/catalog/settings.py
index 5ecdb9435..53a91dfd6 100644
--- a/api/catalog/settings.py
+++ b/api/catalog/settings.py
@@ -105,7 +105,10 @@ MIDDLEWARE = [
"oauth2_provider.middleware.OAuth2TokenMiddleware",
]
-SWAGGER_SETTINGS = {"SECURITY_DEFINITIONS": {}}
+SWAGGER_SETTINGS = {
+ "DEFAULT_INFO": "catalog.urls.swagger.open_api_info",
+ "SECURITY_DEFINITIONS": {},
+}
OAUTH2_PROVIDER = {
"SCOPES": {
diff --git a/api/catalog/urls/__init__.py b/api/catalog/urls/__init__.py
index b3c44e0a8..c37b1d44e 100644
--- a/api/catalog/urls/__init__.py
+++ b/api/catalog/urls/__init__.py
@@ -76,7 +76,7 @@ versioned_paths += router.urls
urlpatterns = [
path("", RedirectView.as_view(pattern_name="root")),
path("admin/", admin.site.urls),
- path("healthcheck", HealthCheck.as_view()),
+ path("healthcheck/", HealthCheck.as_view()),
# Swagger documentation
path("", include(swagger_patterns)),
# API
diff --git a/api/catalog/urls/auth_tokens.py b/api/catalog/urls/auth_tokens.py
index 3631bbc4d..344e3c12b 100644
--- a/api/catalog/urls/auth_tokens.py
+++ b/api/catalog/urls/auth_tokens.py
@@ -5,6 +5,6 @@ from catalog.api.views.oauth2_views import Register, VerifyEmail
urlpatterns = [
path("register/", Register.as_view(), name="register"),
- path("verify/<str:code>", VerifyEmail.as_view(), name="verify-email"),
+ path("verify/<str:code>/", VerifyEmail.as_view(), name="verify-email"),
path("", include("oauth2_provider.urls", namespace="oauth2_provider")),
]
diff --git a/api/catalog/urls/swagger.py b/api/catalog/urls/swagger.py
index 0cb06ae22..a241c4e79 100644
--- a/api/catalog/urls/swagger.py
+++ b/api/catalog/urls/swagger.py
@@ -18,16 +18,18 @@ with open(description_path, "r") as description_file:
tos_url = "https://wordpress.github.io/openverse-api/terms_of_service.html"
license_url = "https://github.com/WordPress/openverse-api/blob/HEAD/LICENSE"
logo_url = "https://raw.githubusercontent.com/WordPress/openverse/HEAD/brand/logo.svg"
+open_api_info = openapi.Info(
+ title="Openverse API consumer docs",
+ default_version=settings.API_VERSION,
+ description=description,
+ contact=openapi.Contact(email=settings.CONTACT_EMAIL),
+ license=openapi.License(name="MIT License", url=license_url),
+ terms_of_service=tos_url,
+ x_logo={"url": logo_url, "backgroundColor": "#fafafa"},
+)
+
schema_view = get_schema_view(
- openapi.Info(
- title="Openverse API consumer docs",
- default_version=settings.API_VERSION,
- description=description,
- contact=openapi.Contact(email=settings.CONTACT_EMAIL),
- license=openapi.License(name="MIT License", url=license_url),
- terms_of_service=tos_url,
- x_logo={"url": logo_url, "backgroundColor": "#fafafa"},
- ),
+ open_api_info,
public=True,
permission_classes=(AllowAny,),
)
diff --git a/justfile b/justfile
index 770065498..7149b2e2b 100644
--- a/justfile
+++ b/justfile
@@ -194,7 +194,7 @@ _api-install:
# Check the health of the API
@web-health:
- -curl -s -o /dev/null -w '%{http_code}' 'http://localhost:50280/healthcheck'
+ -curl -s -o /dev/null -w '%{http_code}' 'http://localhost:50280/healthcheck/'
# Wait for the API to be healthy
@wait-for-web: