generate subtypes and enums
This commit is contained in:
parent
4d63cd09c1
commit
945647baf1
|
@ -103,8 +103,7 @@ fn method_docs(spec: &OpenApiV2, op: &Operation) -> eyre::Result<String> {
|
|||
for param in params {
|
||||
let param = param.deref(spec)?;
|
||||
match ¶m._in {
|
||||
ParameterIn::Path { param: _ }
|
||||
| ParameterIn::FormData { param: _ } => {
|
||||
ParameterIn::Path { param: _ } | ParameterIn::FormData { param: _ } => {
|
||||
write!(&mut out, "/// - `{}`", param.name)?;
|
||||
if let Some(description) = ¶m.description {
|
||||
write!(&mut out, ": {}", description)?;
|
||||
|
|
|
@ -39,6 +39,14 @@ pub fn create_struct_for_definition(
|
|||
return Ok(String::new());
|
||||
}
|
||||
|
||||
if schema._type == Some(SchemaType::One(Primitive::String)) {
|
||||
if let Some(_enum) = &schema._enum {
|
||||
return create_enum(name, schema);
|
||||
}
|
||||
}
|
||||
|
||||
let mut subtypes = Vec::new();
|
||||
|
||||
let docs = create_struct_docs(schema)?;
|
||||
let mut fields = String::new();
|
||||
let required = schema.required.as_deref().unwrap_or_default();
|
||||
|
@ -84,6 +92,17 @@ pub fn create_struct_for_definition(
|
|||
fields.push_str(": ");
|
||||
fields.push_str(&field_ty);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +114,33 @@ pub fn create_struct_for_definition(
|
|||
fields.push_str(">,\n");
|
||||
}
|
||||
|
||||
let out = format!("{docs}#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]\npub struct {name} {{\n{fields}}}\n\n");
|
||||
let mut out = format!("{docs}#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]\npub struct {name} {{\n{fields}}}\n\n");
|
||||
for subtype in subtypes {
|
||||
out.push_str(&subtype);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
fn create_enum(name: &str, schema: &Schema) -> eyre::Result<String> {
|
||||
let _enum = schema
|
||||
._enum
|
||||
.as_deref()
|
||||
.ok_or_else(|| eyre::eyre!("cannot create enum from non-enum schema"))?;
|
||||
let mut variants = String::new();
|
||||
|
||||
let docs = create_struct_docs(schema)?;
|
||||
for variant in _enum {
|
||||
match variant {
|
||||
serde_json::Value::String(s) => {
|
||||
let variant_name = s.to_pascal_case();
|
||||
variants.push_str(&variant_name);
|
||||
variants.push_str(",\n");
|
||||
}
|
||||
x => eyre::bail!("cannot create enum variant. expected string, got {x:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
let out = format!("{docs}#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]\npub enum {name} {{\n{variants}}}\n\n");
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
|
|
147
src/generated.rs
147
src/generated.rs
|
@ -7407,6 +7407,15 @@ pub mod structs {
|
|||
pub sha: Option<String>,
|
||||
}
|
||||
|
||||
/// indicates what to do with the file
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ChangeFileOperationOperation {
|
||||
Create,
|
||||
Update,
|
||||
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)
|
||||
|
@ -7738,6 +7747,21 @@ pub mod structs {
|
|||
pub r#type: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum CreateHookOptionType {
|
||||
Forgejo,
|
||||
Dingtalk,
|
||||
Discord,
|
||||
Gitea,
|
||||
Gogs,
|
||||
Msteams,
|
||||
Slack,
|
||||
Telegram,
|
||||
Feishu,
|
||||
Wechatwork,
|
||||
Packagist,
|
||||
}
|
||||
|
||||
/// CreateHookOptionConfig has all config options in it
|
||||
///
|
||||
/// required are "content_type" and "url" Required
|
||||
|
@ -7817,6 +7841,12 @@ pub mod structs {
|
|||
pub title: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum CreateMilestoneOptionState {
|
||||
Open,
|
||||
Closed,
|
||||
}
|
||||
|
||||
/// CreateOAuth2ApplicationOptions holds options to create an oauth2 application
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -7851,6 +7881,15 @@ pub mod structs {
|
|||
pub website: Option<String>,
|
||||
}
|
||||
|
||||
/// possible values are `public` (default), `limited` or `private`
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum CreateOrgOptionVisibility {
|
||||
Public,
|
||||
Limited,
|
||||
Private,
|
||||
}
|
||||
|
||||
/// CreatePullRequestOption options when creating a pull request
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -7953,6 +7992,16 @@ pub mod structs {
|
|||
pub trust_model: Option<String>,
|
||||
}
|
||||
|
||||
/// TrustModel of the repository
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum CreateRepoOptionTrustModel {
|
||||
Default,
|
||||
Collaborator,
|
||||
Committer,
|
||||
Collaboratorcommitter,
|
||||
}
|
||||
|
||||
/// CreateStatusOption holds the information needed to create a new CommitStatus for a Commit
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -7986,6 +8035,19 @@ pub mod structs {
|
|||
pub units_map: Option<serde_json::Map<String, serde_json::Value>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum CreateTeamOptionPermission {
|
||||
Read,
|
||||
Write,
|
||||
Admin,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct CreateTeamOptionUnitsMap {
|
||||
#[serde(flatten)]
|
||||
pub additional: std::collections::BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
/// CreateUserOption create user options
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -8166,6 +8228,12 @@ pub mod structs {
|
|||
pub events: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct EditHookOptionConfig {
|
||||
#[serde(flatten)]
|
||||
pub additional: std::collections::BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
/// EditIssueCommentOption options for editing a comment
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -8233,6 +8301,15 @@ pub mod structs {
|
|||
pub website: Option<String>,
|
||||
}
|
||||
|
||||
/// possible values are `public`, `limited` or `private`
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum EditOrgOptionVisibility {
|
||||
Public,
|
||||
Limited,
|
||||
Private,
|
||||
}
|
||||
|
||||
/// EditPullRequestOption options when modify pull request
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -8377,6 +8454,19 @@ pub mod structs {
|
|||
pub units_map: Option<serde_json::Map<String, serde_json::Value>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum EditTeamOptionPermission {
|
||||
Read,
|
||||
Write,
|
||||
Admin,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct EditTeamOptionUnitsMap {
|
||||
#[serde(flatten)]
|
||||
pub additional: std::collections::BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
/// EditUserOption edit user options
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -8689,6 +8779,12 @@ pub mod structs {
|
|||
pub updated_at: Option<time::OffsetDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct HookConfig {
|
||||
#[serde(flatten)]
|
||||
pub additional: std::collections::BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
/// Identity for a person's identity like an author or committer
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -8789,6 +8885,18 @@ pub mod structs {
|
|||
pub validations: Option<serde_json::Map<String, serde_json::Value>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct IssueFormFieldAttributes {
|
||||
#[serde(flatten)]
|
||||
pub additional: std::collections::BTreeMap<String, ()>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct IssueFormFieldValidations {
|
||||
#[serde(flatten)]
|
||||
pub additional: std::collections::BTreeMap<String, ()>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct IssueFormFieldType {}
|
||||
|
||||
|
@ -8975,6 +9083,15 @@ pub mod structs {
|
|||
pub merge_when_checks_succeed: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum MergePullRequestOptionDo {
|
||||
Merge,
|
||||
Rebase,
|
||||
RebaseMerge,
|
||||
Squash,
|
||||
ManuallyMerged,
|
||||
}
|
||||
|
||||
/// MigrateRepoOptions options for migrating repository's
|
||||
///
|
||||
/// this is used to interact with api v1
|
||||
|
@ -9007,6 +9124,18 @@ pub mod structs {
|
|||
pub wiki: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum MigrateRepoOptionsService {
|
||||
Git,
|
||||
Github,
|
||||
Gitea,
|
||||
Gitlab,
|
||||
Gogs,
|
||||
Onedev,
|
||||
Gitbucket,
|
||||
Codebase,
|
||||
}
|
||||
|
||||
/// Milestone milestone is a collection of issues on one repository
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -9049,6 +9178,9 @@ pub mod structs {
|
|||
pub version: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct NodeInfoMetadata {}
|
||||
|
||||
/// NodeInfoServices contains the third party sites this server can connect to via their application API
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -9688,6 +9820,21 @@ pub mod structs {
|
|||
pub units_map: Option<serde_json::Map<String, serde_json::Value>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum TeamPermission {
|
||||
None,
|
||||
Read,
|
||||
Write,
|
||||
Admin,
|
||||
Owner,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct TeamUnitsMap {
|
||||
#[serde(flatten)]
|
||||
pub additional: std::collections::BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
/// TimeStamp defines a timestamp
|
||||
///
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
|
Loading…
Reference in a new issue