Skip to content

Commit

Permalink
deployer: added OpenAPI docs
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianbarbu committed Apr 13, 2023
1 parent 1db4ae7 commit 8d4af01
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 32 deletions.
91 changes: 91 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
4 changes: 3 additions & 1 deletion common/src/models/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use comfy_table::{
};
use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, ToSchema)]
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
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

0 comments on commit 8d4af01

Please sign in to comment.