include enum types in fields
This commit is contained in:
parent
43f853dad3
commit
0ea0f6ee57
|
@ -55,6 +55,59 @@ pub fn create_struct_for_definition(
|
||||||
let prop_ty = crate::schema_ref_type_name(spec, prop_schema)?;
|
let prop_ty = crate::schema_ref_type_name(spec, prop_schema)?;
|
||||||
let field_name = crate::sanitize_ident(prop_name);
|
let field_name = crate::sanitize_ident(prop_name);
|
||||||
let mut field_ty = prop_ty.clone();
|
let mut field_ty = prop_ty.clone();
|
||||||
|
if let MaybeRef::Value { value } = &prop_schema {
|
||||||
|
fn schema_subtypes(
|
||||||
|
spec: &OpenApiV2,
|
||||||
|
ty_name: &str,
|
||||||
|
name: &str,
|
||||||
|
schema: &Schema,
|
||||||
|
subtypes: &mut Vec<String>,
|
||||||
|
ty: &mut String,
|
||||||
|
) -> eyre::Result<bool> {
|
||||||
|
let b = match schema {
|
||||||
|
Schema {
|
||||||
|
_type: Some(SchemaType::One(Primitive::Object)),
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
let name = format!("{ty_name}{}", name.to_pascal_case());
|
||||||
|
let subtype = create_struct_for_definition(spec, &name, schema)?;
|
||||||
|
subtypes.push(subtype);
|
||||||
|
*ty = name;
|
||||||
|
true
|
||||||
|
}
|
||||||
|
Schema {
|
||||||
|
_type: Some(SchemaType::One(Primitive::String)),
|
||||||
|
_enum: Some(_enum),
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
let name = format!("{ty_name}{}", name.to_pascal_case());
|
||||||
|
let subtype = create_enum(&name, schema.description.as_deref(), _enum)?;
|
||||||
|
subtypes.push(subtype);
|
||||||
|
*ty = name;
|
||||||
|
true
|
||||||
|
}
|
||||||
|
Schema {
|
||||||
|
_type: Some(SchemaType::One(Primitive::Array)),
|
||||||
|
items: Some(items),
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
if let MaybeRef::Value { value } = &**items {
|
||||||
|
if schema_subtypes(spec, ty_name, name, value, subtypes, ty)? {
|
||||||
|
*ty = format!("Vec<{ty}>");
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
Ok(b)
|
||||||
|
}
|
||||||
|
schema_subtypes(spec, name, prop_name, value, &mut subtypes, &mut field_ty)?;
|
||||||
|
}
|
||||||
if field_name.ends_with("url") && field_name != "ssh_url" && field_ty == "String" {
|
if field_name.ends_with("url") && field_name != "ssh_url" && field_ty == "String" {
|
||||||
field_ty = "url::Url".into()
|
field_ty = "url::Url".into()
|
||||||
}
|
}
|
||||||
|
@ -92,17 +145,6 @@ pub fn create_struct_for_definition(
|
||||||
fields.push_str(": ");
|
fields.push_str(": ");
|
||||||
fields.push_str(&field_ty);
|
fields.push_str(&field_ty);
|
||||||
fields.push_str(",\n");
|
fields.push_str(",\n");
|
||||||
|
|
||||||
if let MaybeRef::Value { value } = &prop_schema {
|
|
||||||
if value._type == Some(SchemaType::One(Primitive::Object))
|
|
||||||
|| (value._type == Some(SchemaType::One(Primitive::String))
|
|
||||||
&& value._enum.is_some())
|
|
||||||
{
|
|
||||||
let name = format!("{name}{}", prop_name.to_pascal_case());
|
|
||||||
let subtype = create_struct_for_definition(spec, &name, value)?;
|
|
||||||
subtypes.push(subtype);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7398,7 +7398,7 @@ pub mod structs {
|
||||||
pub from_path: Option<String>,
|
pub from_path: Option<String>,
|
||||||
/// indicates what to do with the file
|
/// indicates what to do with the file
|
||||||
///
|
///
|
||||||
pub operation: String,
|
pub operation: ChangeFileOperationOperation,
|
||||||
/// path to the existing or new file
|
/// path to the existing or new file
|
||||||
///
|
///
|
||||||
pub path: String,
|
pub path: String,
|
||||||
|
@ -7754,7 +7754,7 @@ pub mod structs {
|
||||||
pub config: CreateHookOptionConfig,
|
pub config: CreateHookOptionConfig,
|
||||||
pub events: Option<Vec<String>>,
|
pub events: Option<Vec<String>>,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub r#type: String,
|
pub r#type: CreateHookOptionType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
|
@ -7864,7 +7864,7 @@ pub mod structs {
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
pub due_on: Option<time::OffsetDateTime>,
|
pub due_on: Option<time::OffsetDateTime>,
|
||||||
pub state: Option<String>,
|
pub state: Option<CreateMilestoneOptionState>,
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7912,7 +7912,7 @@ pub mod structs {
|
||||||
pub username: String,
|
pub username: String,
|
||||||
/// possible values are `public` (default), `limited` or `private`
|
/// possible values are `public` (default), `limited` or `private`
|
||||||
///
|
///
|
||||||
pub visibility: Option<String>,
|
pub visibility: Option<CreateOrgOptionVisibility>,
|
||||||
pub website: Option<String>,
|
pub website: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8034,7 +8034,7 @@ pub mod structs {
|
||||||
pub template: Option<bool>,
|
pub template: Option<bool>,
|
||||||
/// TrustModel of the repository
|
/// TrustModel of the repository
|
||||||
///
|
///
|
||||||
pub trust_model: Option<String>,
|
pub trust_model: Option<CreateRepoOptionTrustModel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TrustModel of the repository
|
/// TrustModel of the repository
|
||||||
|
@ -8086,9 +8086,9 @@ pub mod structs {
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub includes_all_repositories: Option<bool>,
|
pub includes_all_repositories: Option<bool>,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub permission: Option<String>,
|
pub permission: Option<CreateTeamOptionPermission>,
|
||||||
pub units: Option<Vec<String>>,
|
pub units: Option<Vec<String>>,
|
||||||
pub units_map: Option<serde_json::Map<String, serde_json::Value>>,
|
pub units_map: Option<CreateTeamOptionUnitsMap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
|
@ -8289,7 +8289,7 @@ pub mod structs {
|
||||||
pub active: Option<bool>,
|
pub active: Option<bool>,
|
||||||
pub authorization_header: Option<String>,
|
pub authorization_header: Option<String>,
|
||||||
pub branch_filter: Option<String>,
|
pub branch_filter: Option<String>,
|
||||||
pub config: Option<serde_json::Map<String, serde_json::Value>>,
|
pub config: Option<EditHookOptionConfig>,
|
||||||
pub events: Option<Vec<String>>,
|
pub events: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8362,7 +8362,7 @@ pub mod structs {
|
||||||
pub repo_admin_change_team_access: Option<bool>,
|
pub repo_admin_change_team_access: Option<bool>,
|
||||||
/// possible values are `public`, `limited` or `private`
|
/// possible values are `public`, `limited` or `private`
|
||||||
///
|
///
|
||||||
pub visibility: Option<String>,
|
pub visibility: Option<EditOrgOptionVisibility>,
|
||||||
pub website: Option<String>,
|
pub website: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8524,9 +8524,9 @@ pub mod structs {
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub includes_all_repositories: Option<bool>,
|
pub includes_all_repositories: Option<bool>,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub permission: Option<String>,
|
pub permission: Option<EditTeamOptionPermission>,
|
||||||
pub units: Option<Vec<String>>,
|
pub units: Option<Vec<String>>,
|
||||||
pub units_map: Option<serde_json::Map<String, serde_json::Value>>,
|
pub units_map: Option<EditTeamOptionUnitsMap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
|
@ -8852,7 +8852,7 @@ pub mod structs {
|
||||||
pub active: Option<bool>,
|
pub active: Option<bool>,
|
||||||
pub authorization_header: Option<String>,
|
pub authorization_header: Option<String>,
|
||||||
pub branch_filter: Option<String>,
|
pub branch_filter: Option<String>,
|
||||||
pub config: Option<serde_json::Map<String, serde_json::Value>>,
|
pub config: Option<HookConfig>,
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
pub created_at: Option<time::OffsetDateTime>,
|
pub created_at: Option<time::OffsetDateTime>,
|
||||||
pub events: Option<Vec<String>>,
|
pub events: Option<Vec<String>>,
|
||||||
|
@ -8962,11 +8962,11 @@ pub mod structs {
|
||||||
///
|
///
|
||||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct IssueFormField {
|
pub struct IssueFormField {
|
||||||
pub attributes: Option<serde_json::Map<String, serde_json::Value>>,
|
pub attributes: Option<IssueFormFieldAttributes>,
|
||||||
pub id: Option<String>,
|
pub id: Option<String>,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub r#type: Option<String>,
|
pub r#type: Option<String>,
|
||||||
pub validations: Option<serde_json::Map<String, serde_json::Value>>,
|
pub validations: Option<IssueFormFieldValidations>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
|
@ -9154,7 +9154,7 @@ pub mod structs {
|
||||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct MergePullRequestOption {
|
pub struct MergePullRequestOption {
|
||||||
#[serde(rename = "Do")]
|
#[serde(rename = "Do")]
|
||||||
pub r#do: String,
|
pub r#do: MergePullRequestOptionDo,
|
||||||
#[serde(rename = "MergeCommitID")]
|
#[serde(rename = "MergeCommitID")]
|
||||||
pub merge_commit_id: Option<String>,
|
pub merge_commit_id: Option<String>,
|
||||||
#[serde(rename = "MergeMessageField")]
|
#[serde(rename = "MergeMessageField")]
|
||||||
|
@ -9212,7 +9212,7 @@ pub mod structs {
|
||||||
/// Name of User or Organisation who will own Repo after migration
|
/// Name of User or Organisation who will own Repo after migration
|
||||||
///
|
///
|
||||||
pub repo_owner: Option<String>,
|
pub repo_owner: Option<String>,
|
||||||
pub service: Option<String>,
|
pub service: Option<MigrateRepoOptionsService>,
|
||||||
/// deprecated (only for backwards compatibility)
|
/// deprecated (only for backwards compatibility)
|
||||||
///
|
///
|
||||||
pub uid: Option<u64>,
|
pub uid: Option<u64>,
|
||||||
|
@ -9277,7 +9277,7 @@ pub mod structs {
|
||||||
///
|
///
|
||||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct NodeInfo {
|
pub struct NodeInfo {
|
||||||
pub metadata: Option<serde_json::Map<String, serde_json::Value>>,
|
pub metadata: Option<NodeInfoMetadata>,
|
||||||
#[serde(rename = "openRegistrations")]
|
#[serde(rename = "openRegistrations")]
|
||||||
pub open_registrations: Option<bool>,
|
pub open_registrations: Option<bool>,
|
||||||
pub protocols: Option<Vec<String>>,
|
pub protocols: Option<Vec<String>>,
|
||||||
|
@ -9924,9 +9924,9 @@ pub mod structs {
|
||||||
pub includes_all_repositories: Option<bool>,
|
pub includes_all_repositories: Option<bool>,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub organization: Option<Organization>,
|
pub organization: Option<Organization>,
|
||||||
pub permission: Option<String>,
|
pub permission: Option<TeamPermission>,
|
||||||
pub units: Option<Vec<String>>,
|
pub units: Option<Vec<String>>,
|
||||||
pub units_map: Option<serde_json::Map<String, serde_json::Value>>,
|
pub units_map: Option<TeamUnitsMap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
|
@ -11129,7 +11129,7 @@ pub mod structs {
|
||||||
pub limit: Option<u32>,
|
pub limit: Option<u32>,
|
||||||
/// package type filter
|
/// package type filter
|
||||||
///
|
///
|
||||||
pub r#type: Option<ListPackagesQueryRType>,
|
pub r#type: Option<ListPackagesQueryType>,
|
||||||
/// name filter
|
/// name filter
|
||||||
///
|
///
|
||||||
pub q: Option<String>,
|
pub q: Option<String>,
|
||||||
|
@ -11155,7 +11155,7 @@ pub mod structs {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum ListPackagesQueryRType {
|
pub enum ListPackagesQueryType {
|
||||||
Alpine,
|
Alpine,
|
||||||
Cargo,
|
Cargo,
|
||||||
Chef,
|
Chef,
|
||||||
|
@ -11179,30 +11179,30 @@ pub mod structs {
|
||||||
Vagrant,
|
Vagrant,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ListPackagesQueryRType {
|
impl ListPackagesQueryType {
|
||||||
fn as_str(&self) -> &'static str {
|
fn as_str(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
ListPackagesQueryRType::Alpine => "alpine",
|
ListPackagesQueryType::Alpine => "alpine",
|
||||||
ListPackagesQueryRType::Cargo => "cargo",
|
ListPackagesQueryType::Cargo => "cargo",
|
||||||
ListPackagesQueryRType::Chef => "chef",
|
ListPackagesQueryType::Chef => "chef",
|
||||||
ListPackagesQueryRType::Composer => "composer",
|
ListPackagesQueryType::Composer => "composer",
|
||||||
ListPackagesQueryRType::Conan => "conan",
|
ListPackagesQueryType::Conan => "conan",
|
||||||
ListPackagesQueryRType::Conda => "conda",
|
ListPackagesQueryType::Conda => "conda",
|
||||||
ListPackagesQueryRType::Container => "container",
|
ListPackagesQueryType::Container => "container",
|
||||||
ListPackagesQueryRType::Cran => "cran",
|
ListPackagesQueryType::Cran => "cran",
|
||||||
ListPackagesQueryRType::Debian => "debian",
|
ListPackagesQueryType::Debian => "debian",
|
||||||
ListPackagesQueryRType::Generic => "generic",
|
ListPackagesQueryType::Generic => "generic",
|
||||||
ListPackagesQueryRType::Go => "go",
|
ListPackagesQueryType::Go => "go",
|
||||||
ListPackagesQueryRType::Helm => "helm",
|
ListPackagesQueryType::Helm => "helm",
|
||||||
ListPackagesQueryRType::Maven => "maven",
|
ListPackagesQueryType::Maven => "maven",
|
||||||
ListPackagesQueryRType::Npm => "npm",
|
ListPackagesQueryType::Npm => "npm",
|
||||||
ListPackagesQueryRType::Nuget => "nuget",
|
ListPackagesQueryType::Nuget => "nuget",
|
||||||
ListPackagesQueryRType::Pub => "pub",
|
ListPackagesQueryType::Pub => "pub",
|
||||||
ListPackagesQueryRType::Pypi => "pypi",
|
ListPackagesQueryType::Pypi => "pypi",
|
||||||
ListPackagesQueryRType::Rpm => "rpm",
|
ListPackagesQueryType::Rpm => "rpm",
|
||||||
ListPackagesQueryRType::Rubygems => "rubygems",
|
ListPackagesQueryType::Rubygems => "rubygems",
|
||||||
ListPackagesQueryRType::Swift => "swift",
|
ListPackagesQueryType::Swift => "swift",
|
||||||
ListPackagesQueryRType::Vagrant => "vagrant",
|
ListPackagesQueryType::Vagrant => "vagrant",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11873,7 +11873,7 @@ pub mod structs {
|
||||||
pub q: Option<String>,
|
pub q: Option<String>,
|
||||||
/// filter by type (issues / pulls) if set
|
/// filter by type (issues / pulls) if set
|
||||||
///
|
///
|
||||||
pub r#type: Option<IssueListIssuesQueryRType>,
|
pub r#type: Option<IssueListIssuesQueryType>,
|
||||||
/// comma separated list of milestone names or ids. It uses names and fall back to ids. Fetch only issues that have any of this milestones. Non existent milestones are discarded
|
/// comma separated list of milestone names or ids. It uses names and fall back to ids. Fetch only issues that have any of this milestones. Non existent milestones are discarded
|
||||||
///
|
///
|
||||||
pub milestones: Option<String>,
|
pub milestones: Option<String>,
|
||||||
|
@ -11973,16 +11973,16 @@ pub mod structs {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum IssueListIssuesQueryRType {
|
pub enum IssueListIssuesQueryType {
|
||||||
Issues,
|
Issues,
|
||||||
Pulls,
|
Pulls,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IssueListIssuesQueryRType {
|
impl IssueListIssuesQueryType {
|
||||||
fn as_str(&self) -> &'static str {
|
fn as_str(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
IssueListIssuesQueryRType::Issues => "issues",
|
IssueListIssuesQueryType::Issues => "issues",
|
||||||
IssueListIssuesQueryRType::Pulls => "pulls",
|
IssueListIssuesQueryType::Pulls => "pulls",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue