Skip to content

Commit e7a8046

Browse files
authored
Merge branch 'main' into feat/openapi-lint
2 parents 5f32760 + 91ac810 commit e7a8046

27 files changed

+124
-44
lines changed

catalyst-gateway/bin/src/event_db/types/ballot.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(crate) struct ObjectiveChoices(pub(crate) Vec<String>);
1212
pub(crate) struct BallotType(pub(crate) String);
1313

1414
#[derive(Debug, Clone, PartialEq, Eq)]
15-
/// Vote Plan
15+
/// Voting Plan
1616
pub(crate) struct VotePlan {
1717
/// Chain proposal index
1818
pub(crate) chain_proposal_index: i64,

catalyst-gateway/bin/src/service/api/health/live_get.rs

+3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ use tracing::{error, info, warn};
55

66
use crate::service::common::responses::{
77
resp_2xx::NoContent,
8+
resp_4xx::ApiValidationError,
89
resp_5xx::{ServerError, ServiceUnavailable},
910
};
1011

1112
/// All responses
1213
pub(crate) type AllResponses = response! {
1314
204: NoContent,
15+
400: ApiValidationError,
1416
500: ServerError,
1517
503: ServiceUnavailable,
1618
};
@@ -28,6 +30,7 @@ pub(crate) type AllResponses = response! {
2830
/// ## Responses
2931
///
3032
/// * 204 No Content - Service is OK and can keep running.
33+
/// * 400 API Validation Error
3134
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
3235
/// but unlikely)
3336
/// * 503 Service Unavailable - Service is possibly not running reliably.

catalyst-gateway/bin/src/service/api/health/ready_get.rs

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
event_db::error::Error as DBError,
1414
service::common::responses::{
1515
resp_2xx::NoContent,
16+
resp_4xx::ApiValidationError,
1617
resp_5xx::{server_error, ServerError, ServiceUnavailable},
1718
},
1819
state::{SchemaVersionStatus, State},
@@ -21,6 +22,7 @@ use crate::{
2122
/// All responses
2223
pub(crate) type AllResponses = response! {
2324
204: NoContent,
25+
400: ApiValidationError,
2426
500: ServerError,
2527
503: ServiceUnavailable,
2628
};
@@ -46,6 +48,7 @@ pub(crate) type AllResponses = response! {
4648
/// ## Responses
4749
///
4850
/// * 204 No Content - Service is Ready to serve requests.
51+
/// * 400 API Validation Error
4952
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
5053
/// but unlikely)
5154
/// * 503 Service Unavailable - Service is not ready, do not send other requests.

catalyst-gateway/bin/src/service/api/health/started_get.rs

+3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ use poem_extensions::{response, UniResponse::T204};
44

55
use crate::service::common::responses::{
66
resp_2xx::NoContent,
7+
resp_4xx::ApiValidationError,
78
resp_5xx::{ServerError, ServiceUnavailable},
89
};
910

1011
/// All responses
1112
pub(crate) type AllResponses = response! {
1213
204: NoContent,
14+
400: ApiValidationError,
1315
500: ServerError,
1416
503: ServiceUnavailable,
1517
};
@@ -35,6 +37,7 @@ pub(crate) type AllResponses = response! {
3537
/// ## Responses
3638
///
3739
/// * 204 No Content - Service is Started and can serve requests.
40+
/// * 400 API Validation Error
3841
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
3942
/// but unlikely)
4043
/// * 503 Service Unavailable - Service has not started, do not send other requests.

catalyst-gateway/bin/src/service/api/registration/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
},
2222
responses::{
2323
resp_2xx::OK,
24-
resp_4xx::NotFound,
24+
resp_4xx::{BadRequest, NotFound},
2525
resp_5xx::{server_error, ServerError, ServiceUnavailable},
2626
},
2727
tags::ApiTags,
@@ -59,14 +59,16 @@ impl RegistrationApi {
5959
/// The Event ID to return results for.
6060
/// See [GET Events](Link to events endpoint) for details on retrieving all valid
6161
/// event IDs.
62-
#[oai(validator(minimum(value = "0")))]
62+
// TODO (Blue) : https://github.com/input-output-hk/catalyst-voices/issues/239
63+
#[oai(validator(minimum(value = "0"), maximum(value = "2147483647")))]
6364
event_id: Query<Option<EventId>>,
6465
/// If this optional flag is set, the response will include the delegator's list
6566
/// in the response. Otherwise, it will be omitted.
6667
#[oai(default)]
6768
with_delegators: Query<bool>,
6869
) -> response! {
6970
200: OK<Json<VoterRegistration>>,
71+
400: BadRequest<Json<VoterRegistration>>,
7072
404: NotFound,
7173
500: ServerError,
7274
503: ServiceUnavailable,

catalyst-gateway/bin/src/service/api/test_endpoints/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl TestApi {
5757
/// The action just needs to be any valid UUID.
5858
///
5959
/// # Make sure its a UUID
60-
action: Path<Option<String>>,
60+
action: Path<String>,
6161
#[oai(validator(min_items = 0, max_items = 3, unique_items))]
6262
/// List your favorite pets, in order of preference
6363
pet: Query<Option<Vec<test_get::Animals>>>,
@@ -99,7 +99,7 @@ impl TestApi {
9999
/// * 10 will print a warn log
100100
/// * 15 will print a error log
101101
/// * 20 will panic which should generate a 500
102-
_id: Path<i32>,
102+
id: Path<i32>,
103103
#[oai(validator(
104104
pattern = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
105105
max_length = "36",
@@ -108,8 +108,8 @@ impl TestApi {
108108
/// The action just needs to be any valid UUID.
109109
///
110110
/// # Make sure its a UUID
111-
_action: Path<Option<String>>,
111+
action: Path<String>,
112112
) -> test_post::AllResponses {
113-
test_post::endpoint().await
113+
test_post::endpoint(*id, &action).await
114114
}
115115
}

catalyst-gateway/bin/src/service/api/test_endpoints/test_get.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ pub(crate) enum Animals {
4848
/// ## Responses
4949
///
5050
/// * 204 No Content - Service is OK and can keep running.
51+
/// * 400 API Validation Error
5152
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
5253
/// but unlikely)
5354
/// * 503 Service Unavailable - Service is possibly not running reliably.
5455
#[allow(clippy::unused_async, clippy::panic)]
5556
pub(crate) async fn endpoint(
56-
_state: Arc<State>, id: i32, action: &Option<String>, pet: &Option<Vec<Animals>>,
57+
_state: Arc<State>, id: i32, action: &String, pet: &Option<Vec<Animals>>,
5758
) -> AllResponses {
5859
info!("id: {id:?}, action: {action:?} pet: {pet:?}");
5960
let response: AllResponses = match id {

catalyst-gateway/bin/src/service/api/test_endpoints/test_post.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
//! Test validation of a json body of a POST Endpoint.
22
33
use poem_extensions::{response, UniResponse::T204};
4+
use tracing::info;
45

56
use crate::service::common::responses::{
67
resp_2xx::NoContent,
8+
resp_4xx::ApiValidationError,
79
resp_5xx::{ServerError, ServiceUnavailable},
810
};
911

1012
/// All responses
1113
pub(crate) type AllResponses = response! {
1214
204: NoContent,
15+
400: ApiValidationError,
1316
500: ServerError,
1417
503: ServiceUnavailable,
1518
};
@@ -27,11 +30,15 @@ pub(crate) type AllResponses = response! {
2730
/// ## Responses
2831
///
2932
/// * 204 No Content - Service is OK and can keep running.
33+
/// * 400 API Validation Error.
3034
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
3135
/// but unlikely)
3236
/// * 503 Service Unavailable - Service is possibly not running reliably.
3337
#[allow(clippy::unused_async)]
34-
pub(crate) async fn endpoint() -> AllResponses {
35-
// otherwise everything seems to be A-OK
36-
T204(NoContent)
38+
pub(crate) async fn endpoint(id: i32, action: &String) -> AllResponses {
39+
let response: AllResponses = {
40+
info!("id: {id:?}, action: {action:?}");
41+
T204(NoContent)
42+
};
43+
response
3744
}

catalyst-gateway/bin/src/service/api/v0/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ pub(crate) struct V0Api;
2121
#[OpenApi(prefix_path = "/v0", tag = "ApiTags::V0")]
2222
impl V0Api {
2323
/// Posts a signed transaction.
24+
///
25+
/// Post a signed transaction in a form of message to the network.
2426
#[oai(path = "/message", method = "post", operation_id = "Message")]
2527
async fn message_post(&self, message: Binary<Vec<u8>>) -> message_post::AllResponses {
2628
message_post::endpoint(message).await
2729
}
2830

31+
/// Get all active vote plans endpoint.
32+
///
2933
/// Get all active vote plans endpoint.
3034
#[oai(
3135
path = "/vote/active/plans",

catalyst-gateway/bin/src/service/api/v0/plans_get.rs

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111
objects::vote_plan::VotePlan,
1212
responses::{
1313
resp_2xx::OK,
14+
resp_4xx::BadRequest,
1415
resp_5xx::{ServerError, ServiceUnavailable},
1516
},
1617
},
@@ -20,6 +21,7 @@ use crate::{
2021
/// All responses
2122
pub(crate) type AllResponses = response! {
2223
200: OK<Json<Vec<VotePlan>>>,
24+
400: BadRequest<Json<Vec<VotePlan>>>,
2325
500: ServerError,
2426
503: ServiceUnavailable,
2527
};
@@ -31,6 +33,8 @@ pub(crate) type AllResponses = response! {
3133
/// ## Responses
3234
///
3335
/// * 200 with a JSON array with the list of vote plans with their respective data.
36+
/// * 400 Bad request with a JSON array with the list of vote plans with their respective
37+
/// data.
3438
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
3539
/// but unlikely)
3640
/// * 503 Service Unavailable - Service has not started, do not send other requests.

catalyst-gateway/bin/src/service/api/v1/account_votes_get.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
33
use std::sync::Arc;
44

5-
use poem::web::{Data, Path};
5+
use poem::web::Data;
66
use poem_extensions::{response, UniResponse::T200};
7-
use poem_openapi::payload::Json;
7+
use poem_openapi::{param::Path, payload::Json};
88

99
use crate::{
1010
service::common::{
1111
objects::account_votes::{AccountId, AccountVote},
1212
responses::{
1313
resp_2xx::OK,
14+
resp_4xx::BadRequest,
1415
resp_5xx::{ServerError, ServiceUnavailable},
1516
},
1617
},
@@ -20,6 +21,7 @@ use crate::{
2021
/// All responses
2122
pub(crate) type AllResponses = response! {
2223
200: OK<Json<Vec<AccountVote>>>,
24+
400: BadRequest<Json<Vec<AccountVote>>>,
2325
500: ServerError,
2426
503: ServiceUnavailable,
2527
};
@@ -34,6 +36,7 @@ pub(crate) type AllResponses = response! {
3436
/// ## Responses
3537
///
3638
/// * 200 with a JSON array of the number of voted proposals in a plan.
39+
/// * 400 Bad request with a JSON array of the number of voted proposals in a plan
3740
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
3841
/// but unlikely)
3942
/// * 503 Service Unavailable - Service has not started, do not send other requests.

catalyst-gateway/bin/src/service/api/v1/fragments_post.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ use crate::service::common::{
99
},
1010
responses::{
1111
resp_2xx::OK,
12+
resp_4xx::BadRequest,
1213
resp_5xx::{ServerError, ServiceUnavailable},
1314
},
1415
};
1516

1617
/// All responses
1718
pub(crate) type AllResponses = response! {
1819
200: OK<Json<FragmentsProcessingSummary>>,
20+
400: BadRequest<Json<FragmentsProcessingSummary>>,
1921
500: ServerError,
2022
503: ServiceUnavailable,
2123
};
@@ -27,6 +29,7 @@ pub(crate) type AllResponses = response! {
2729
/// ## Responses
2830
///
2931
/// * 200 No Content - Service is OK and can keep running.
32+
/// * 400 Bad Request
3033
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
3134
/// but unlikely)
3235
/// * 503 Service Unavailable - Service is possibly not running reliably.

catalyst-gateway/bin/src/service/api/v1/fragments_statuses.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@ use poem_extensions::{response, UniResponse::T200};
66
use poem_openapi::payload::Json;
77

88
use crate::service::common::{
9-
objects::fragment_status::FragmentStatus,
9+
objects::{fragment_status::FragmentStatus, fragments_processing_summary::FragmentId},
1010
responses::{
1111
resp_2xx::OK,
12+
resp_4xx::BadRequest,
1213
resp_5xx::{ServerError, ServiceUnavailable},
1314
},
1415
};
1516

16-
/// Comma-separated (no spaces in between) list of fragment IDs.
17-
#[derive(poem_openapi::NewType)]
18-
pub(crate) struct FragmentIds(String);
19-
2017
/// All responses
2118
pub(crate) type AllResponses = response! {
2219
200: OK<Json<HashMap<String, FragmentStatus>>>,
20+
400: BadRequest<Json<HashMap<String, FragmentStatus>>>,
2321
500: ServerError,
2422
503: ServiceUnavailable,
2523
};
@@ -31,10 +29,11 @@ pub(crate) type AllResponses = response! {
3129
/// ## Responses
3230
///
3331
/// * 200 Fragments Statuses - Statuses of the fragments by id.
32+
/// * 400 Bad Request
3433
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
3534
/// but unlikely)
3635
/// * 503 Service Unavailable - Service is possibly not running reliably.
3736
#[allow(clippy::unused_async)]
38-
pub(crate) async fn endpoint(_fragment_ids: FragmentIds) -> AllResponses {
37+
pub(crate) async fn endpoint(_fragment_ids: Vec<FragmentId>) -> AllResponses {
3938
T200(OK(Json(HashMap::new())))
4039
}

catalyst-gateway/bin/src/service/api/v1/mod.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
33
use std::sync::Arc;
44

5-
use poem::web::{Data, Path};
6-
use poem_openapi::{param::Query, payload::Json, OpenApi};
5+
use poem::web::Data;
6+
use poem_openapi::{
7+
param::{Path, Query},
8+
payload::Json,
9+
OpenApi,
10+
};
711

812
use crate::{
913
service::{
1014
common::{
11-
objects::{account_votes::AccountId, fragments_batch::FragmentsBatch},
15+
objects::{
16+
account_votes::AccountId, fragments_batch::FragmentsBatch,
17+
fragments_processing_summary::FragmentId,
18+
},
1219
tags::ApiTags,
1320
},
1421
utilities::middleware::schema_validation::schema_version_validation,
@@ -31,10 +38,15 @@ impl V1Api {
3138
operation_id = "AccountVotes",
3239
transform = "schema_version_validation"
3340
)]
41+
42+
/// Get Account Votes
43+
///
3444
/// Get from all active vote plans, the index of the voted proposals
35-
/// by th given account ID.
45+
/// by the given account ID.
3646
async fn get_account_votes(
37-
&self, state: Data<&Arc<State>>, account_id: Path<AccountId>,
47+
&self, state: Data<&Arc<State>>,
48+
/// A account ID to get the votes for.
49+
account_id: Path<AccountId>,
3850
) -> account_votes_get::AllResponses {
3951
account_votes_get::endpoint(state, account_id).await
4052
}
@@ -73,7 +85,9 @@ impl V1Api {
7385
&self,
7486
/// Comma-separated list of fragment ids for which the statuses will
7587
/// be retrieved.
76-
Query(fragment_ids): Query<fragments_statuses::FragmentIds>,
88+
// TODO (Blue) : https://github.com/input-output-hk/catalyst-voices/issues/239
89+
#[oai(validator(max_items = "1000"))]
90+
Query(fragment_ids): Query<Vec<FragmentId>>,
7791
) -> fragments_statuses::AllResponses {
7892
fragments_statuses::endpoint(fragment_ids).await
7993
}

0 commit comments

Comments
 (0)