diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-03 12:14:01 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-03 12:14:01 +0000 |
| commit | bb1a44b0c75471b5c004170552540b9632f89810 (patch) | |
| tree | a8450f9ba19595d22981c4ce514299dac5300915 /test/python | |
| parent | c379119d85dc23f855dee005856576cac38126c8 (diff) | |
| download | genenetwork4-bb1a44b0c75471b5c004170552540b9632f89810.tar.gz | |
Add /openapi.json describing the REST API.
* Cargo.toml (dependencies): Add utoipa, feature axum_extras; add utoipa-axum. * src/lib.rs: Use utoipa_axum::router::OpenApiRouter and routes! instead of axum::Router and route!, so paths register into an OpenApi document as well as the router. (ApiDoc): New struct, deriving utoipa::OpenApi with title, description and license. (app): Add /openapi.json, serving the OpenApi document split out of OpenApiRouter via split_for_parts. (hello_world, version, species): Add #[utoipa::path(...)] attributes describing each endpoint's responses. (VersionInfo): Derive utoipa::ToSchema in addition to Serialize. * src/db.rs (Species): Likewise. * tests/openapi.rs: New file. Checks /openapi.json's info.title and that it lists all three endpoints. * test/python/test_openapi.py: New file. Likewise. * README.md: Document /openapi.json. * rust-package.scm: Regenerate with guix import crate -f Cargo.lock genenetwork4. Adds crate-source definitions for utoipa, utoipa-gen, utoipa-axum and pastey. * guix.scm (genenetwork4-git)[native-inputs]: Add rust-utoipa-6.0.0, rust-utoipa-gen-6.0.1, rust-utoipa-axum-0.3.0 and rust-pastey-0.2.3.
Diffstat (limited to 'test/python')
| -rw-r--r-- | test/python/test_openapi.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/python/test_openapi.py b/test/python/test_openapi.py new file mode 100644 index 0000000..03100b9 --- /dev/null +++ b/test/python/test_openapi.py @@ -0,0 +1,28 @@ +"""Mirrors tests/openapi.rs.""" + +import http.client +import json +import unittest + +from server_test_case import HOST, PORT, ServerTestCase + + +class OpenApiTest(ServerTestCase): + def test_openapi_json_describes_all_endpoints(self): + conn = http.client.HTTPConnection(HOST, int(PORT), timeout=5) + try: + conn.request("GET", "/openapi.json") + response = conn.getresponse() + body = response.read() + finally: + conn.close() + self.assertEqual(response.status, 200) + + doc = json.loads(body) + self.assertEqual(doc["info"]["title"], "GeneNetwork4 API") + for path in ("/", "/version", "/species"): + self.assertIn(path, doc["paths"]) + + +if __name__ == "__main__": + unittest.main() |
