Skip to content

Commit

Permalink
dev(better_theoros): Updated openapi specs
Browse files Browse the repository at this point in the history
  • Loading branch information
akhercha committed Nov 2, 2024
1 parent 8172260 commit 2ff6699
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 70 deletions.
155 changes: 89 additions & 66 deletions rust/theoros/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,34 @@
"version": "0.1.0"
},
"paths": {
"/v1/calldata/{chain_name}/{feed_id}": {
"/v1/calldata": {
"get": {
"tags": [
"crate::handlers::get_calldata"
],
"tags": ["crate::handlers::rest::get_calldata"],
"operationId": "get_calldata",
"parameters": [],
"parameters": [
{
"name": "chain",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "feed_ids",
"in": "query",
"required": true,
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
],
"responses": {
"200": {
"description": "Constructs the calldata used to update the feed id specified",
"description": "Constructs the calldata used to update the specified feed IDs",
"content": {
"application/json": {
"schema": {
Expand All @@ -31,14 +49,11 @@
}
},
"404": {
"description": "Unknown Feed Id",
"description": "Unknown Feed ID",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/GetCalldataError"
}
"$ref": "#/components/schemas/GetCalldataError"
}
}
}
Expand All @@ -48,9 +63,7 @@
},
"/v1/chains": {
"get": {
"tags": [
"crate::handlers::get_chains"
],
"tags": ["crate::handlers::rest::get_chains"],
"operationId": "get_chains",
"responses": {
"200": {
Expand All @@ -71,9 +84,7 @@
},
"/v1/data_feeds": {
"get": {
"tags": [
"crate::handlers::get_data_feeds"
],
"tags": ["crate::handlers::rest::get_data_feeds"],
"operationId": "get_data_feeds",
"responses": {
"200": {
Expand All @@ -95,37 +106,39 @@
},
"components": {
"schemas": {
"CalldataResponse": {
"type": "object",
"required": ["feed_id", "encoded_calldata"],
"properties": {
"encoded_calldata": {
"type": "string"
},
"feed_id": {
"type": "string"
}
}
},
"GetCalldataError": {
"oneOf": [
{
"type": "string",
"enum": [
"InternalServerError"
]
"enum": ["InternalServerError"]
},
{
"type": "string",
"enum": [
"DatabaseConnection"
]
"enum": ["DatabaseConnection"]
},
{
"type": "string",
"enum": [
"InvalidFeedId"
]
"enum": ["InvalidFeedId"]
},
{
"type": "string",
"enum": [
"DispatchNotFound"
]
"enum": ["DispatchNotFound"]
},
{
"type": "object",
"required": [
"FeedNotFound"
],
"required": ["FeedNotFound"],
"properties": {
"FeedNotFound": {
"type": "string"
Expand All @@ -134,54 +147,54 @@
},
{
"type": "string",
"enum": [
"FailedToCreateHyperlaneClient"
]
"enum": ["FailedToCreateHyperlaneClient"]
},
{
"type": "string",
"enum": [
"FailedToFetchOnchainValidators"
]
"enum": ["FailedToFetchOnchainValidators"]
},
{
"type": "string",
"enum": [
"ValidatorNotFound"
]
"enum": ["ValidatorNotFound"]
},
{
"type": "object",
"required": [
"ChainNotSupported"
],
"required": ["ChainNotSupported"],
"properties": {
"ChainNotSupported": {
"type": "string"
}
}
},
{
"type": "object",
"required": ["CalldataError"],
"properties": {
"CalldataError": {
"type": "string"
}
}
}
]
},
"GetCalldataQuery": {
"type": "object"
},
"GetCalldataResponse": {
"type": "object",
"required": [
"calldata"
],
"required": ["chain", "feed_ids"],
"properties": {
"calldata": {
"chain": {
"type": "string"
},
"feed_ids": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"GetChainsError": {
"type": "string",
"enum": [
"InternalServerError"
]
"enum": ["InternalServerError"]
},
"GetChainsResponse": {
"type": "array",
Expand All @@ -193,9 +206,7 @@
"oneOf": [
{
"type": "object",
"required": [
"ParsingFeedId"
],
"required": ["ParsingFeedId"],
"properties": {
"ParsingFeedId": {
"type": "string"
Expand All @@ -204,9 +215,7 @@
},
{
"type": "string",
"enum": [
"InternalServerError"
]
"enum": ["InternalServerError"]
}
]
},
Expand All @@ -215,20 +224,34 @@
"items": {
"$ref": "#/components/schemas/Feed"
}
},
"RpcDataFeed": {
"type": "object",
"required": ["feed_id", "encoded_calldata"],
"properties": {
"encoded_calldata": {
"type": "string",
"description": "The calldata binary represented as a hex string."
},
"feed_id": {
"type": "string"
}
}
}
},
"responses": {
"GetCalldataResponse": {
"CalldataResponse": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"calldata"
],
"required": ["feed_id", "encoded_calldata"],
"properties": {
"calldata": {
"encoded_calldata": {
"type": "string"
},
"feed_id": {
"type": "string"
}
}
Expand Down Expand Up @@ -270,4 +293,4 @@
"description": "Theoros - The Pragma Consultant"
}
]
}
}
10 changes: 6 additions & 4 deletions rust/theoros/src/handlers/rest/get_calldata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ pub struct GetCalldataQuery {
}

#[derive(Debug, Serialize, Deserialize, ToResponse, ToSchema)]
pub struct GetCalldataResponse {
pub struct CalldataResponse {
pub feed_id: String,
pub encoded_calldata: String,
}

pub type GetCalldataResponse = Vec<CalldataResponse>;

#[utoipa::path(
get,
path = "/v1/calldata",
Expand All @@ -50,7 +52,7 @@ pub struct GetCalldataResponse {
pub async fn get_calldata(
State(state): State<AppState>,
Query(params): Query<GetCalldataQuery>,
) -> Result<Json<Vec<GetCalldataResponse>>, GetCalldataError> {
) -> Result<Json<GetCalldataResponse>, GetCalldataError> {
let started_at = std::time::Instant::now();

let chain_name =
Expand All @@ -64,14 +66,14 @@ pub async fn get_calldata(
}

// Build calldata for each feed ID.
let mut responses = Vec::with_capacity(params.feed_ids.len());
let mut responses: GetCalldataResponse = Vec::with_capacity(params.feed_ids.len());
for feed_id in &params.feed_ids {
let calldata = Calldata::build_from(&state, chain_name, feed_id.clone())
.await
.map_err(|e| GetCalldataError::CalldataError(e.to_string()))?;

let response =
GetCalldataResponse { feed_id: feed_id.clone(), encoded_calldata: hex::encode(calldata.as_bytes()) };
CalldataResponse { feed_id: feed_id.clone(), encoded_calldata: hex::encode(calldata.as_bytes()) };
responses.push(response);
}

Expand Down

0 comments on commit 2ff6699

Please sign in to comment.