Skip to content

Commit 9216afc

Browse files
mightyiamjfly
andcommitted
feat(api)!: remove /api/v1 and add /api/v2
Closes #244 Co-authored-by: Jeremy Fleischman <jeremyfleischman@gmail.com>
1 parent 4a4ec51 commit 9216afc

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

crates/api/src/lib.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ impl<'a> FromRequest<'a> for DbConnection {
6262

6363
struct Api;
6464

65-
#[OpenApi(prefix_path = "/v1")]
65+
#[OpenApi]
6666
impl Api {
67-
#[oai(path = "/:pr", method = "get")]
67+
#[allow(clippy::unused_async)]
68+
#[oai(path = "/v1/:_", method = "get")]
69+
async fn v1(&self) -> V1Response {
70+
V1Response::NotSupported(payload::PlainText("API v1 not supported"))
71+
}
72+
73+
#[oai(path = "/v2/landings/:pr", method = "get")]
6874
async fn landed(
6975
&self,
7076
param::Path(pr): param::Path<i32>,
@@ -80,7 +86,7 @@ impl Api {
8086
Ok(payload::Json(LandedIn { branches }))
8187
}
8288

83-
#[oai(path = "/healthcheck", method = "get")]
89+
#[oai(path = "/v2/healthcheck", method = "get")]
8490
#[allow(clippy::unused_async)]
8591
async fn health_check(
8692
&self,
@@ -90,6 +96,12 @@ impl Api {
9096
}
9197
}
9298

99+
#[derive(ApiResponse)]
100+
enum V1Response {
101+
#[oai(status = 404)]
102+
NotSupported(payload::PlainText<&'static str>),
103+
}
104+
93105
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, poem_openapi::NewType)]
94106
pub struct Branch(pub String);
95107

crates/api/tests/healthcheck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use poem::http::StatusCode;
77
use test_util::TestContext;
88

99
test![healthcheck_ok, |ctx: TestContext| async move {
10-
let response = ctx.client().get("/api/v1/healthcheck").send().await;
10+
let response = ctx.client().get("/api/v2/healthcheck").send().await;
1111
response.assert_status_is_ok();
1212
}];
1313

1414
test![healthcheck_not_ok, |mut ctx: TestContext| async move {
1515
ctx.db_mut().kill_db().unwrap();
16-
let response = ctx.client().get("/api/v1/healthcheck").send().await;
16+
let response = ctx.client().get("/api/v2/healthcheck").send().await;
1717
response.assert_status(StatusCode::SERVICE_UNAVAILABLE);
1818
}];

crates/api/tests/landings.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use poem::http::StatusCode;
77
use test_util::TestContext;
88

99
test![negative_pr_number, |ctx: TestContext| async move {
10-
let response = ctx.client().get("/api/v1/-1").send().await;
10+
let response = ctx.client().get("/api/v2/landings/-1").send().await;
1111
response.assert_status(StatusCode::BAD_REQUEST);
1212
response
1313
.assert_text("Pull request number non-positive.")
@@ -28,13 +28,13 @@ test![negative_pr_number, |ctx: TestContext| async move {
2828
//
2929
// test![internal_landed_error, |mut ctx: TestContext| async move {
3030
// bork_db(ctx.db_mut()).await;
31-
// let response = ctx.client().get("/api/v1/1").send().await;
31+
// let response = ctx.client().get("/api/v2/landings/1").send().await;
3232
// response.assert_status(StatusCode::SERVICE_UNAVAILABLE);
3333
// response.assert_text("Error. Sorry.").await;
3434
// }];
3535

3636
test![pr_not_found, |ctx: TestContext| async move {
37-
let response = ctx.client().get("/api/v1/2134").send().await;
37+
let response = ctx.client().get("/api/v2/landings/2134").send().await;
3838
response.assert_status(StatusCode::NO_CONTENT);
3939
response.assert_text("Pull request not found.").await;
4040
}];
@@ -50,7 +50,7 @@ test![pr_not_landed, |ctx: TestContext| async move {
5050
.await
5151
.unwrap();
5252

53-
let response = ctx.client().get("/api/v1/123").send().await;
53+
let response = ctx.client().get("/api/v2/landings/123").send().await;
5454
response.assert_status_is_ok();
5555
response
5656
.assert_json(pr_tracker_api::LandedIn { branches: vec![] })
@@ -77,7 +77,7 @@ test![pr_landed, |ctx: TestContext| async move {
7777

7878
landing.upsert(connection).await.unwrap();
7979

80-
let response = ctx.client().get("/api/v1/2134").send().await;
80+
let response = ctx.client().get("/api/v2/landings/2134").send().await;
8181
response.assert_status_is_ok();
8282

8383
response

crates/api/tests/v1.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#[path = "../test-util.rs"]
2+
#[macro_use]
3+
mod test_util;
4+
5+
use futures::FutureExt;
6+
use poem::http::StatusCode;
7+
use test_util::TestContext;
8+
9+
test![v1_api_not_found, |ctx: TestContext| async move {
10+
let response = ctx.client().get("/api/v1/healthcheck").send().await;
11+
response.assert_status(StatusCode::NOT_FOUND);
12+
response.assert_text("API v1 not supported").await;
13+
14+
let response = ctx.client().get("/api/v1/42").send().await;
15+
response.assert_status(StatusCode::NOT_FOUND);
16+
response.assert_text("API v1 not supported").await;
17+
}];

modules/integration-tests/api/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
testScript = ''
1313
pr_tracker_api.start()
1414
pr_tracker_api.wait_for_unit("pr-tracker-api.service")
15-
pr_tracker_api.succeed("curl --fail http://localhost:7000/api/v1/healthcheck")
15+
pr_tracker_api.succeed("curl --fail http://localhost:7000/api/v2/healthcheck")
1616
'';
1717
};
1818
};

modules/integration-tests/create-locally.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ in
5151
testScript = ''
5252
pr_tracker.start()
5353
pr_tracker.wait_for_unit("pr-tracker-api.service")
54-
pr_tracker.succeed("curl --fail http://localhost:${toString apiPort}/api/v1/healthcheck")
54+
pr_tracker.succeed("curl --fail http://localhost:${toString apiPort}/api/v2/healthcheck")
5555
pr_tracker.wait_until_succeeds("journalctl -u pr-tracker-fetcher.service --grep 'error sending request for url'", timeout=60)
5656
'';
5757
};

0 commit comments

Comments
 (0)