Skip to content

Commit

Permalink
feat: Add ToSchema to scheam structs, bump version to 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wangeguo committed Jan 15, 2024
1 parent 7de6f66 commit 3f8361d
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "amp-common"
description = "Rust libraries shared across Amphitheatre components and libraries"
version = "0.6.3"
version = "0.7.0"
edition = "2021"
license = "Apache-2.0"
homepage = "https://amphitheatre.app"
Expand Down
6 changes: 5 additions & 1 deletion src/resource/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ use validator::Validate;
use super::CharacterSpec;
use crate::schema::GitReference;

#[derive(Clone, CustomResource, Debug, Default, Deserialize, Serialize, JsonSchema, Validate, PartialEq)]
use utoipa::ToSchema;

#[derive(
Clone, CustomResource, Debug, Default, Deserialize, Serialize, JsonSchema, Validate, PartialEq, ToSchema,
)]
#[kube(
group = "amphitheatre.app",
version = "v1",
Expand Down
16 changes: 13 additions & 3 deletions src/resource/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use validator::Validate;

use crate::schema::{self, Build, Deploy, Metadata};

use super::Partner;
use crate::schema::{self, Build, Deploy, Metadata};
use utoipa::ToSchema;

#[derive(
Clone, CustomResource, Debug, Default, Deserialize, Eq, JsonSchema, Serialize, PartialEq, Validate,
Clone,
CustomResource,
Debug,
Default,
Deserialize,
Eq,
JsonSchema,
Serialize,
PartialEq,
Validate,
ToSchema,
)]
#[kube(group = "amphitheatre.app", version = "v1", kind = "Character")]
pub struct CharacterSpec {
Expand Down
6 changes: 3 additions & 3 deletions src/resource/partner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::schema::{self, GitReference, LocalPartner, RegisteredPartner};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::schema::{self, GitReference, LocalPartner, RegisteredPartner};
use utoipa::ToSchema;

/// Specify Support for OpenAPI, it does not untagged.
/// Your character can depend on other characters from Registry or other registries,
/// git repositories, or subdirectories of project.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, JsonSchema)]
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, JsonSchema, ToSchema)]
#[serde(rename_all = "lowercase")]
pub enum Partner {
Registry(RegisteredPartner),
Expand Down
9 changes: 8 additions & 1 deletion src/resource/playbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ use k8s_openapi::chrono::Utc;
use kube::CustomResource;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use validator::Validate;

#[derive(Clone, CustomResource, Debug, Default, Deserialize, JsonSchema, Serialize, Validate)]
#[derive(Clone, CustomResource, Debug, Default, Deserialize, JsonSchema, Serialize, Validate, ToSchema)]
#[kube(
group = "amphitheatre.app",
version = "v1",
Expand All @@ -48,6 +49,12 @@ pub struct PlaybookSpec {
pub sync: Option<bool>,
}

impl PlaybookSpec {
pub fn id(&self) -> String {
self.namespace.to_owned()
}
}

#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema, PartialEq)]
pub struct PlaybookStatus {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
Expand Down
6 changes: 3 additions & 3 deletions src/resource/preface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::schema::{GitReference, RegisteredPartner};

use super::CharacterSpec;
use crate::schema::{GitReference, RegisteredPartner};
use utoipa::ToSchema;

/// the lead character in a story.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize, JsonSchema)]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize, JsonSchema, ToSchema)]
pub struct Preface {
/// The name of the character.
pub name: String,
Expand Down
10 changes: 5 additions & 5 deletions src/schema/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

use std::collections::HashMap;

use crate::utils::kubernetes::to_env_var;
use k8s_openapi::api::core::v1::EnvVar;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::utils::kubernetes::to_env_var;
use utoipa::ToSchema;

/// Describes how images are built.
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, Serialize, PartialEq)]
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, Serialize, PartialEq, ToSchema)]
pub struct Build {
/// The configuration for building an image using a Dockerfile.
#[serde(flatten, skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -70,7 +70,7 @@ pub enum BuildMethod {
}

/// The configuration for building an image using a Dockerfile.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema, ToSchema)]
pub struct DockerfileConfig {
/// Locates the Dockerfile relative to workspace.
pub dockerfile: String,
Expand All @@ -85,7 +85,7 @@ impl Default for DockerfileConfig {
}

/// The configuration for building an image using Cloud Native Buildpacks.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema, ToSchema)]
pub struct BuildpacksConfig {
/// Builds images using Cloud Native Buildpacks,
/// default builder is `gcr.io/buildpacks/builder:v1`
Expand Down
6 changes: 3 additions & 3 deletions src/schema/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

use std::{collections::HashMap, fs::read_to_string, path::Path};

use super::{Build, Deploy, Partner};
use anyhow::anyhow;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use validator::Validate;

use super::{Build, Deploy, Partner};

#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, Serialize, PartialEq, Validate)]
pub struct Character {
/// Contains all the information about a character.
Expand Down Expand Up @@ -57,7 +57,7 @@ impl Character {
}

/// Contains all the information about a character.
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, Serialize, PartialEq, Validate)]
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, Serialize, PartialEq, Validate, ToSchema)]
pub struct Metadata {
/// The name of the character.
pub name: String,
Expand Down
6 changes: 3 additions & 3 deletions src/schema/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@

use std::collections::HashMap;

use crate::utils::kubernetes::to_env_var;
use k8s_openapi::api::core::v1::{ContainerPort, EnvVar, ServicePort};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::utils::kubernetes::to_env_var;
use utoipa::ToSchema;

use super::Service;

/// Describes how images are deploy.
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, Serialize, PartialEq)]
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, Serialize, PartialEq, ToSchema)]
pub struct Deploy {
/// Specify the external image to be launched when it’s a reference kind of manifest.
/// Or by default, leave it empty and Amphitheatre will automatically create it
Expand Down
10 changes: 5 additions & 5 deletions src/schema/partner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use super::GitReference;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use super::GitReference;
use utoipa::ToSchema;

/// Your character can depend on other characters from Registry or other registries,
/// git repositories, or subdirectories of local filesystem.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema)]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema, ToSchema)]
#[serde(untagged, rename_all = "lowercase")]
pub enum Partner {
Registry(RegisteredPartner),
Expand All @@ -28,7 +28,7 @@ pub enum Partner {
}

/// A partner that pulls a character from a registry.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, JsonSchema)]
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, JsonSchema, ToSchema)]
pub struct RegisteredPartner {
/// The registry to pull the character from. Defaults to Catalog.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -38,7 +38,7 @@ pub struct RegisteredPartner {
}

/// A partner that pulls a character from a local path.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, JsonSchema)]
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, JsonSchema, ToSchema)]
pub struct LocalPartner {
/// The path to the character.
pub path: String,
Expand Down
5 changes: 3 additions & 2 deletions src/schema/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
use k8s_openapi::api::core::v1::{ContainerPort, ServicePort};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// Defines the behavior of a service
#[derive(Clone, Debug, Deserialize, Eq, Serialize, JsonSchema, PartialEq)]
#[derive(Clone, Debug, Deserialize, Eq, Serialize, JsonSchema, PartialEq, ToSchema)]
pub struct Service {
/// Type determines how the Service is exposed. Defaults to ClusterIP.
/// Valid options are ExternalName, ClusterIP, NodePort, and LoadBalancer.
Expand All @@ -38,7 +39,7 @@ impl TryInto<Vec<ContainerPort>> for Service {
}

/// List of ports to expose from the container.
#[derive(Clone, Debug, Deserialize, Eq, Serialize, JsonSchema, PartialEq)]
#[derive(Clone, Debug, Deserialize, Eq, Serialize, JsonSchema, PartialEq, ToSchema)]
pub struct Port {
/// The port that will be exposed by this service.
pub port: i32,
Expand Down
3 changes: 2 additions & 1 deletion src/schema/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// Your characters can depend on other partners from other registries,
/// git repositories, or subdirectories on your local file system.
#[derive(Clone, Debug, Default, Deserialize, Serialize, JsonSchema, Eq, Hash, PartialEq)]
#[derive(Clone, Debug, Default, Deserialize, Serialize, JsonSchema, Eq, Hash, PartialEq, ToSchema)]
pub struct GitReference {
/// Source code repository the partner should be cloned from.
/// e.g. https://github.com/amphitheatre-app/amphitheatre.git.
Expand Down

0 comments on commit 3f8361d

Please sign in to comment.