Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deployer & gateway: added OpenAPI docs #794

Merged
merged 4 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@ tracing-subscriber = { version = "0.3.16", default-features = false, features =
"std",
] }
ttl_cache = "0.5.1"
utoipa = { version = "3.2.1", features = [ "uuid", "chrono" ] }
utoipa-swagger-ui = { version = "3.1.3", features = ["axum"] }
uuid = "1.2.2"
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tracing = { workspace = true, features = ["std"] }
tracing-opentelemetry = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, optional = true }
ttl_cache = { workspace = true, optional = true }
utoipa = { workspace = true }
uuid = { workspace = true, features = ["v4", "serde"], optional = true }

[features]
Expand Down
8 changes: 5 additions & 3 deletions common/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ use std::fmt::Display;

use serde::{Deserialize, Serialize};
use strum::Display;
use utoipa::ToSchema;

#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, ToSchema)]
#[serde(rename_all = "lowercase")]
#[schema(as = shuttle_common::database::Type)]
pub enum Type {
AwsRds(AwsRdsEngine),
Shared(SharedEngine),
}

#[derive(Clone, Debug, Deserialize, Display, Serialize, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize, Display, Serialize, Eq, PartialEq, ToSchema)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum AwsRdsEngine {
Expand All @@ -19,7 +21,7 @@ pub enum AwsRdsEngine {
MariaDB,
}

#[derive(Clone, Debug, Deserialize, Display, Serialize, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize, Display, Serialize, Eq, PartialEq, ToSchema)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum SharedEngine {
Expand Down
4 changes: 3 additions & 1 deletion common/src/deployment.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use serde::{Deserialize, Serialize};
use strum::Display;
use utoipa::ToSchema;

#[derive(Clone, Debug, Deserialize, Display, Serialize)]
#[derive(Clone, Debug, Deserialize, Display, Serialize, ToSchema)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
#[schema(as = shuttle_common::deployment::State)]
pub enum State {
Queued,
Building,
Expand Down
11 changes: 9 additions & 2 deletions common/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ use chrono::{DateTime, Utc};
#[cfg(feature = "display")]
use crossterm::style::{StyledContent, Stylize};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use uuid::Uuid;

use crate::deployment::State;

pub const STATE_MESSAGE: &str = "NEW STATE";

#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
#[schema(as = shuttle_common::log::Item)]
pub struct Item {
#[schema(value_type = KnownFormat::Uuid)]
pub id: Uuid,
#[schema(value_type = KnownFormat::DateTime)]
pub timestamp: DateTime<Utc>,
#[schema(value_type = shuttle_common::deployment::State)]
pub state: State,
#[schema(value_type = shuttle_common::log::Level)]
pub level: Level,
pub file: Option<String>,
pub line: Option<u32>,
Expand Down Expand Up @@ -77,8 +83,9 @@ impl std::fmt::Display for Item {
}
}

#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, ToSchema)]
#[serde(rename_all = "lowercase")]
#[schema(as = shuttle_common::log::Level)]
pub enum Level {
Trace,
Debug,
Expand Down
8 changes: 7 additions & 1 deletion common/src/models/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ use comfy_table::{
};
use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use uuid::Uuid;

use crate::deployment::State;

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, ToSchema)]
#[schema(as = shuttle_common::models::deployment::Response)]
pub struct Response {
#[schema(value_type = KnownFormat::Uuid)]
pub id: Uuid,
#[schema(value_type = KnownFormat::Uuid)]
pub service_id: Uuid,
#[schema(value_type = shuttle_common::deployment::State)]
pub state: State,
#[schema(value_type = KnownFormat::DateTime)]
pub last_update: DateTime<Utc>,
}

Expand Down
11 changes: 8 additions & 3 deletions common/src/models/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
use strum::EnumString;
use utoipa::ToSchema;

// Timeframe before a project is considered idle
pub const IDLE_MINUTES: u64 = 30;

#[derive(Deserialize, Serialize, Clone)]
#[derive(Deserialize, Serialize, Clone, ToSchema)]
#[schema(as = shuttle_common::models::project::Response)]
pub struct Response {
pub name: String,
#[schema(value_type = shuttle_common::models::project::State)]
pub state: State,
}

#[derive(Clone, Debug, Deserialize, Serialize, EnumString)]
#[derive(Clone, Debug, Deserialize, Serialize, EnumString, ToSchema)]
#[serde(rename_all = "lowercase")]
#[schema(as = shuttle_common::models::project::State)]
pub enum State {
Creating { recreate_count: usize },
Attaching { recreate_count: usize },
Expand Down Expand Up @@ -164,7 +168,8 @@ pub struct Config {
pub idle_minutes: u64,
}

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, ToSchema)]
#[schema(as = shuttle_common::models::project::AdminResponse)]
pub struct AdminResponse {
pub project_name: String,
pub account_name: String,
Expand Down
5 changes: 4 additions & 1 deletion common/src/models/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ use comfy_table::{
};
use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, ToSchema)]
#[schema(as = shuttle_common::models::secret::Response)]
pub struct Response {
pub key: String,
#[schema(value_type = KnownFormat::DateTime)]
pub last_update: DateTime<Utc>,
}

Expand Down
13 changes: 9 additions & 4 deletions common/src/models/service.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
use crate::models::deployment;

use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use std::fmt::Display;
use utoipa::ToSchema;
use uuid::Uuid;

#[derive(Deserialize, Serialize)]
use crate::models::deployment;

#[derive(Deserialize, Serialize, ToSchema)]
#[schema(as = shuttle_common::models::service::Response)]
pub struct Response {
#[schema(value_type = KnownFormat::Uuid)]
pub id: Uuid,
pub name: String,
}

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, ToSchema)]
#[schema(as = shuttle_common::models::service::Summary)]
pub struct Summary {
pub name: String,
#[schema(value_type = shuttle_common::models::deployment::Response)]
pub deployment: Option<deployment::Response>,
pub uri: String,
}
Expand Down
7 changes: 5 additions & 2 deletions common/src/models/stats.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use uuid::Uuid;

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, ToSchema)]
#[schema(as = shuttle_common::models::stats::LoadRequest)]
pub struct LoadRequest {
pub id: Uuid,
}

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, ToSchema)]
#[schema(as = shuttle_common::models::stats::LoadResponse)]
pub struct LoadResponse {
pub builds_count: usize,
pub has_capacity: bool,
Expand Down
11 changes: 9 additions & 2 deletions common/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@ use std::fmt::Display;

use serde::{Deserialize, Serialize};
use serde_json::Value;
use utoipa::ToSchema;

use crate::database;

/// Common type to hold all the information we need for a generic resource
#[derive(Clone, Deserialize, Serialize)]
#[derive(Clone, Deserialize, Serialize, ToSchema)]
#[schema(as = shuttle_common::resource::Response)]
pub struct Response {
/// The type of this resource.
#[schema(value_type = shuttle_common::resource::Type)]
pub r#type: Type,

/// The config used when creating this resource. Use the [Self::r#type] to know how to parse this data.
#[schema(value_type = Object)]
pub config: Value,

/// The data associated with this resource. Use the [Self::r#type] to know how to parse this data.
#[schema(value_type = Object)]
pub data: Value,
}

#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, ToSchema)]
#[serde(rename_all = "lowercase")]
#[schema(as = shuttle_common::resource::Type)]
pub enum Type {
#[schema(value_type = shuttle_common::database::Type)]
Database(database::Type),
Secrets,
StaticFolder,
Expand Down
2 changes: 2 additions & 0 deletions deployer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ tracing-subscriber = { workspace = true, features = [
"env-filter",
"fmt",
] }
utoipa = { workspace = true }
utoipa-swagger-ui = { workspace = true }
uuid = { workspace = true, features = ["v4"] }

[dependencies.shuttle-common]
Expand Down
Loading