don't implement as_str for enums that don't need it
				
					
				
			This commit is contained in:
		
							parent
							
								
									7938d81544
								
							
						
					
					
						commit
						5431303ecb
					
				
					 3 changed files with 18 additions and 138 deletions
				
			
		| 
						 | 
				
			
			@ -261,7 +261,7 @@ fn schema_subtypes(
 | 
			
		|||
            ..
 | 
			
		||||
        } => {
 | 
			
		||||
            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);
 | 
			
		||||
        }
 | 
			
		||||
        Schema {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,7 +44,7 @@ pub fn create_struct_for_definition(
 | 
			
		|||
 | 
			
		||||
    if schema._type == Some(SchemaType::One(Primitive::String)) {
 | 
			
		||||
        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,
 | 
			
		||||
    desc: Option<&str>,
 | 
			
		||||
    _enum: &[serde_json::Value],
 | 
			
		||||
    imp_as_str: bool,
 | 
			
		||||
) -> eyre::Result<String> {
 | 
			
		||||
    let mut variants = String::new();
 | 
			
		||||
    let mut imp = String::new();
 | 
			
		||||
| 
						 | 
				
			
			@ -143,20 +144,26 @@ pub fn create_enum(
 | 
			
		|||
    }
 | 
			
		||||
    imp.push_str("}");
 | 
			
		||||
 | 
			
		||||
    let out = format!(
 | 
			
		||||
    let strukt = format!(
 | 
			
		||||
        "
 | 
			
		||||
{docs}
 | 
			
		||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
 | 
			
		||||
pub enum {name} {{
 | 
			
		||||
    {variants}
 | 
			
		||||
}}
 | 
			
		||||
 | 
			
		||||
impl {name} {{
 | 
			
		||||
    fn as_str(&self) -> &'static str {{
 | 
			
		||||
        {imp}
 | 
			
		||||
    }}
 | 
			
		||||
}}"
 | 
			
		||||
    );
 | 
			
		||||
    let out = if imp_as_str {
 | 
			
		||||
        let imp = format!(
 | 
			
		||||
            "\n\nimpl {name} {{
 | 
			
		||||
                fn as_str(&self) -> &'static str {{
 | 
			
		||||
                    {imp}
 | 
			
		||||
                }}
 | 
			
		||||
            }}"
 | 
			
		||||
        );
 | 
			
		||||
        format!("{strukt} {imp}")
 | 
			
		||||
    } else {
 | 
			
		||||
        strukt
 | 
			
		||||
    };
 | 
			
		||||
    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 enum_def = create_enum(&name, None, _enum)?;
 | 
			
		||||
                    let enum_def = create_enum(&name, None, _enum, true)?;
 | 
			
		||||
                    enums.push(enum_def);
 | 
			
		||||
                    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 enum_def = create_enum(&name, None, _enum)?;
 | 
			
		||||
                    let enum_def = create_enum(&name, None, _enum, true)?;
 | 
			
		||||
                    enums.push(enum_def);
 | 
			
		||||
                    format!("Vec<{name}>")
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -172,16 +172,6 @@ pub enum ChangeFileOperationOperation {
 | 
			
		|||
    Update,
 | 
			
		||||
    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
 | 
			
		||||
///
 | 
			
		||||
/// 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,
 | 
			
		||||
    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
 | 
			
		||||
///
 | 
			
		||||
/// required are "content_type" and "url" Required
 | 
			
		||||
| 
						 | 
				
			
			@ -576,15 +548,6 @@ pub enum CreateMilestoneOptionState {
 | 
			
		|||
    Open,
 | 
			
		||||
    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
 | 
			
		||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
 | 
			
		||||
pub struct CreateOAuth2ApplicationOptions {
 | 
			
		||||
| 
						 | 
				
			
			@ -622,16 +585,6 @@ pub enum CreateOrgOptionVisibility {
 | 
			
		|||
    Limited,
 | 
			
		||||
    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
 | 
			
		||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
 | 
			
		||||
pub struct CreatePullRequestOption {
 | 
			
		||||
| 
						 | 
				
			
			@ -724,17 +677,6 @@ pub enum CreateRepoOptionTrustModel {
 | 
			
		|||
    Committer,
 | 
			
		||||
    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
 | 
			
		||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
 | 
			
		||||
pub struct CreateStatusOption {
 | 
			
		||||
| 
						 | 
				
			
			@ -771,16 +713,6 @@ pub enum CreateTeamOptionPermission {
 | 
			
		|||
    Write,
 | 
			
		||||
    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)]
 | 
			
		||||
pub struct CreateTeamOptionUnitsMap {
 | 
			
		||||
    #[serde(flatten)]
 | 
			
		||||
| 
						 | 
				
			
			@ -1018,16 +950,6 @@ pub enum EditOrgOptionVisibility {
 | 
			
		|||
    Limited,
 | 
			
		||||
    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
 | 
			
		||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
 | 
			
		||||
pub struct EditPullRequestOption {
 | 
			
		||||
| 
						 | 
				
			
			@ -1146,16 +1068,6 @@ pub enum EditTeamOptionPermission {
 | 
			
		|||
    Write,
 | 
			
		||||
    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)]
 | 
			
		||||
pub struct EditTeamOptionUnitsMap {
 | 
			
		||||
    #[serde(flatten)]
 | 
			
		||||
| 
						 | 
				
			
			@ -1720,18 +1632,6 @@ pub enum MergePullRequestOptionDo {
 | 
			
		|||
    Squash,
 | 
			
		||||
    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
 | 
			
		||||
///
 | 
			
		||||
/// this is used to interact with api v1
 | 
			
		||||
| 
						 | 
				
			
			@ -1772,21 +1672,6 @@ pub enum MigrateRepoOptionsService {
 | 
			
		|||
    Gitbucket,
 | 
			
		||||
    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
 | 
			
		||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
 | 
			
		||||
pub struct Milestone {
 | 
			
		||||
| 
						 | 
				
			
			@ -2428,18 +2313,6 @@ pub enum TeamPermission {
 | 
			
		|||
    Admin,
 | 
			
		||||
    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)]
 | 
			
		||||
pub struct TeamUnitsMap {
 | 
			
		||||
    #[serde(flatten)]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue