1
0
Fork 0

don't implement as_str for enums that don't need it

This commit is contained in:
Cyborus 2024-03-15 14:28:28 -04:00
parent 7938d81544
commit 5431303ecb
No known key found for this signature in database
3 changed files with 18 additions and 138 deletions

View file

@ -261,7 +261,7 @@ fn schema_subtypes(
.. ..
} => { } => {
let name = format!("{parent_name}{}", name.to_pascal_case()); let name = format!("{parent_name}{}", name.to_pascal_case());
let subtype = structs::create_enum(&name, schema.description.as_deref(), _enum)?; let subtype = structs::create_enum(&name, schema.description.as_deref(), _enum, false)?;
subtypes.push(subtype); subtypes.push(subtype);
} }
Schema { Schema {

View file

@ -44,7 +44,7 @@ pub fn create_struct_for_definition(
if schema._type == Some(SchemaType::One(Primitive::String)) { if schema._type == Some(SchemaType::One(Primitive::String)) {
if let Some(_enum) = &schema._enum { if let Some(_enum) = &schema._enum {
return create_enum(name, schema.description.as_deref(), _enum); return create_enum(name, schema.description.as_deref(), _enum, false);
} }
} }
@ -124,6 +124,7 @@ pub fn create_enum(
name: &str, name: &str,
desc: Option<&str>, desc: Option<&str>,
_enum: &[serde_json::Value], _enum: &[serde_json::Value],
imp_as_str: bool,
) -> eyre::Result<String> { ) -> eyre::Result<String> {
let mut variants = String::new(); let mut variants = String::new();
let mut imp = String::new(); let mut imp = String::new();
@ -143,20 +144,26 @@ pub fn create_enum(
} }
imp.push_str("}"); imp.push_str("}");
let out = format!( let strukt = format!(
" "
{docs} {docs}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum {name} {{ pub enum {name} {{
{variants} {variants}
}} }}"
);
impl {name} {{ let out = if imp_as_str {
let imp = format!(
"\n\nimpl {name} {{
fn as_str(&self) -> &'static str {{ fn as_str(&self) -> &'static str {{
{imp} {imp}
}} }}
}}" }}"
); );
format!("{strukt} {imp}")
} else {
strukt
};
Ok(out) Ok(out)
} }
@ -241,7 +248,7 @@ fn create_query_struct(spec: &OpenApiV2, op: &Operation) -> eyre::Result<String>
.. ..
} => { } => {
let name = format!("{op_name}{}", param.name.to_pascal_case()); let name = format!("{op_name}{}", param.name.to_pascal_case());
let enum_def = create_enum(&name, None, _enum)?; let enum_def = create_enum(&name, None, _enum, true)?;
enums.push(enum_def); enums.push(enum_def);
name name
} }
@ -256,7 +263,7 @@ fn create_query_struct(spec: &OpenApiV2, op: &Operation) -> eyre::Result<String>
.. ..
} => { } => {
let name = format!("{op_name}{}", param.name.to_pascal_case()); let name = format!("{op_name}{}", param.name.to_pascal_case());
let enum_def = create_enum(&name, None, _enum)?; let enum_def = create_enum(&name, None, _enum, true)?;
enums.push(enum_def); enums.push(enum_def);
format!("Vec<{name}>") format!("Vec<{name}>")
} }

View file

@ -172,16 +172,6 @@ pub enum ChangeFileOperationOperation {
Update, Update,
Delete, Delete,
} }
impl ChangeFileOperationOperation {
fn as_str(&self) -> &'static str {
match self {
ChangeFileOperationOperation::Create => "create",
ChangeFileOperationOperation::Update => "update",
ChangeFileOperationOperation::Delete => "delete",
}
}
}
/// ChangeFilesOptions options for creating, updating or deleting multiple files /// ChangeFilesOptions options for creating, updating or deleting multiple files
/// ///
/// Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used) /// Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
@ -486,24 +476,6 @@ pub enum CreateHookOptionType {
Wechatwork, Wechatwork,
Packagist, Packagist,
} }
impl CreateHookOptionType {
fn as_str(&self) -> &'static str {
match self {
CreateHookOptionType::Forgejo => "forgejo",
CreateHookOptionType::Dingtalk => "dingtalk",
CreateHookOptionType::Discord => "discord",
CreateHookOptionType::Gitea => "gitea",
CreateHookOptionType::Gogs => "gogs",
CreateHookOptionType::Msteams => "msteams",
CreateHookOptionType::Slack => "slack",
CreateHookOptionType::Telegram => "telegram",
CreateHookOptionType::Feishu => "feishu",
CreateHookOptionType::Wechatwork => "wechatwork",
CreateHookOptionType::Packagist => "packagist",
}
}
}
/// CreateHookOptionConfig has all config options in it /// CreateHookOptionConfig has all config options in it
/// ///
/// required are "content_type" and "url" Required /// required are "content_type" and "url" Required
@ -576,15 +548,6 @@ pub enum CreateMilestoneOptionState {
Open, Open,
Closed, Closed,
} }
impl CreateMilestoneOptionState {
fn as_str(&self) -> &'static str {
match self {
CreateMilestoneOptionState::Open => "open",
CreateMilestoneOptionState::Closed => "closed",
}
}
}
/// CreateOAuth2ApplicationOptions holds options to create an oauth2 application /// CreateOAuth2ApplicationOptions holds options to create an oauth2 application
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct CreateOAuth2ApplicationOptions { pub struct CreateOAuth2ApplicationOptions {
@ -622,16 +585,6 @@ pub enum CreateOrgOptionVisibility {
Limited, Limited,
Private, Private,
} }
impl CreateOrgOptionVisibility {
fn as_str(&self) -> &'static str {
match self {
CreateOrgOptionVisibility::Public => "public",
CreateOrgOptionVisibility::Limited => "limited",
CreateOrgOptionVisibility::Private => "private",
}
}
}
/// CreatePullRequestOption options when creating a pull request /// CreatePullRequestOption options when creating a pull request
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct CreatePullRequestOption { pub struct CreatePullRequestOption {
@ -724,17 +677,6 @@ pub enum CreateRepoOptionTrustModel {
Committer, Committer,
Collaboratorcommitter, Collaboratorcommitter,
} }
impl CreateRepoOptionTrustModel {
fn as_str(&self) -> &'static str {
match self {
CreateRepoOptionTrustModel::Default => "default",
CreateRepoOptionTrustModel::Collaborator => "collaborator",
CreateRepoOptionTrustModel::Committer => "committer",
CreateRepoOptionTrustModel::Collaboratorcommitter => "collaboratorcommitter",
}
}
}
/// CreateStatusOption holds the information needed to create a new CommitStatus for a Commit /// CreateStatusOption holds the information needed to create a new CommitStatus for a Commit
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct CreateStatusOption { pub struct CreateStatusOption {
@ -771,16 +713,6 @@ pub enum CreateTeamOptionPermission {
Write, Write,
Admin, Admin,
} }
impl CreateTeamOptionPermission {
fn as_str(&self) -> &'static str {
match self {
CreateTeamOptionPermission::Read => "read",
CreateTeamOptionPermission::Write => "write",
CreateTeamOptionPermission::Admin => "admin",
}
}
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct CreateTeamOptionUnitsMap { pub struct CreateTeamOptionUnitsMap {
#[serde(flatten)] #[serde(flatten)]
@ -1018,16 +950,6 @@ pub enum EditOrgOptionVisibility {
Limited, Limited,
Private, Private,
} }
impl EditOrgOptionVisibility {
fn as_str(&self) -> &'static str {
match self {
EditOrgOptionVisibility::Public => "public",
EditOrgOptionVisibility::Limited => "limited",
EditOrgOptionVisibility::Private => "private",
}
}
}
/// EditPullRequestOption options when modify pull request /// EditPullRequestOption options when modify pull request
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct EditPullRequestOption { pub struct EditPullRequestOption {
@ -1146,16 +1068,6 @@ pub enum EditTeamOptionPermission {
Write, Write,
Admin, Admin,
} }
impl EditTeamOptionPermission {
fn as_str(&self) -> &'static str {
match self {
EditTeamOptionPermission::Read => "read",
EditTeamOptionPermission::Write => "write",
EditTeamOptionPermission::Admin => "admin",
}
}
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct EditTeamOptionUnitsMap { pub struct EditTeamOptionUnitsMap {
#[serde(flatten)] #[serde(flatten)]
@ -1720,18 +1632,6 @@ pub enum MergePullRequestOptionDo {
Squash, Squash,
ManuallyMerged, ManuallyMerged,
} }
impl MergePullRequestOptionDo {
fn as_str(&self) -> &'static str {
match self {
MergePullRequestOptionDo::Merge => "merge",
MergePullRequestOptionDo::Rebase => "rebase",
MergePullRequestOptionDo::RebaseMerge => "rebase-merge",
MergePullRequestOptionDo::Squash => "squash",
MergePullRequestOptionDo::ManuallyMerged => "manually-merged",
}
}
}
/// MigrateRepoOptions options for migrating repository's /// MigrateRepoOptions options for migrating repository's
/// ///
/// this is used to interact with api v1 /// this is used to interact with api v1
@ -1772,21 +1672,6 @@ pub enum MigrateRepoOptionsService {
Gitbucket, Gitbucket,
Codebase, Codebase,
} }
impl MigrateRepoOptionsService {
fn as_str(&self) -> &'static str {
match self {
MigrateRepoOptionsService::Git => "git",
MigrateRepoOptionsService::Github => "github",
MigrateRepoOptionsService::Gitea => "gitea",
MigrateRepoOptionsService::Gitlab => "gitlab",
MigrateRepoOptionsService::Gogs => "gogs",
MigrateRepoOptionsService::Onedev => "onedev",
MigrateRepoOptionsService::Gitbucket => "gitbucket",
MigrateRepoOptionsService::Codebase => "codebase",
}
}
}
/// Milestone milestone is a collection of issues on one repository /// Milestone milestone is a collection of issues on one repository
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Milestone { pub struct Milestone {
@ -2428,18 +2313,6 @@ pub enum TeamPermission {
Admin, Admin,
Owner, Owner,
} }
impl TeamPermission {
fn as_str(&self) -> &'static str {
match self {
TeamPermission::None => "none",
TeamPermission::Read => "read",
TeamPermission::Write => "write",
TeamPermission::Admin => "admin",
TeamPermission::Owner => "owner",
}
}
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct TeamUnitsMap { pub struct TeamUnitsMap {
#[serde(flatten)] #[serde(flatten)]