use partial_derive2::Partial;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use super::MongoId;
#[typeshare(serialized_as = "Partial<GitProviderAccount>")]
pub type _PartialGitProviderAccount = PartialGitProviderAccount;
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default, Partial)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[partial_derive(Serialize, Deserialize, Debug, Clone, Default)]
#[diff_derive(Serialize, Deserialize, Debug, Clone, Default)]
#[partial(skip_serializing_none, from, diff)]
#[cfg_attr(
feature = "mongo",
derive(mongo_indexed::derive::MongoIndexed)
)]
#[cfg_attr(feature = "mongo", unique_doc_index({ "domain": 1, "username": 1 }))]
pub struct GitProviderAccount {
#[serde(
default,
rename = "_id",
skip_serializing_if = "String::is_empty",
with = "bson::serde_helpers::hex_string_as_object_id"
)]
pub id: MongoId,
#[cfg_attr(feature = "mongo", index)]
#[serde(default = "default_git_domain")]
#[partial_default(default_git_domain())]
pub domain: String,
#[serde(default = "default_https")]
#[partial_default(default_https())]
pub https: bool,
#[cfg_attr(feature = "mongo", index)]
#[serde(default)]
pub username: String,
#[serde(default)]
pub token: String,
}
fn default_git_domain() -> String {
String::from("github.com")
}
fn default_https() -> bool {
true
}
#[cfg(feature = "utoipa")]
impl utoipa::PartialSchema for PartialGitProviderAccount {
fn schema()
-> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
utoipa::schema!(#[inline] std::collections::HashMap<String, serde_json::Value>).into()
}
}
#[cfg(feature = "utoipa")]
impl utoipa::ToSchema for PartialGitProviderAccount {}
#[typeshare(serialized_as = "Partial<DockerRegistryAccount>")]
pub type _PartialDockerRegistryAccount = PartialDockerRegistryAccount;
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default, Partial)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[partial_derive(Serialize, Deserialize, Debug, Clone, Default)]
#[diff_derive(Serialize, Deserialize, Debug, Clone, Default)]
#[partial(skip_serializing_none, from, diff)]
#[cfg_attr(
feature = "mongo",
derive(mongo_indexed::derive::MongoIndexed)
)]
#[cfg_attr(feature = "mongo", unique_doc_index({ "domain": 1, "username": 1 }))]
pub struct DockerRegistryAccount {
#[serde(
default,
rename = "_id",
skip_serializing_if = "String::is_empty",
with = "bson::serde_helpers::hex_string_as_object_id"
)]
pub id: MongoId,
#[cfg_attr(feature = "mongo", index)]
#[serde(default = "default_registry_domain")]
#[partial_default(default_registry_domain())]
pub domain: String,
#[cfg_attr(feature = "mongo", index)]
#[serde(default)]
pub username: String,
#[serde(default)]
pub token: String,
}
fn default_registry_domain() -> String {
String::from("docker.io")
}
#[cfg(feature = "utoipa")]
impl utoipa::PartialSchema for PartialDockerRegistryAccount {
fn schema()
-> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
utoipa::schema!(#[inline] std::collections::HashMap<String, serde_json::Value>).into()
}
}
#[cfg(feature = "utoipa")]
impl utoipa::ToSchema for PartialDockerRegistryAccount {}