diff --git a/Cargo.toml b/Cargo.toml index 7fb81cb..763caa5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ rc-map = ["serde/rc"] rc-str = ["serde/rc"] rc-val = ["serde/rc"] rc-vec = ["serde/rc"] -tags-all = ["tag-attack-detection", "tag-authentication-management", "tag-client-attribute-certificate", "tag-client-initial-access", "tag-client-registration-policy", "tag-client-role-mappings", "tag-client-scopes", "tag-clients", "tag-component", "tag-groups", "tag-identity-providers", "tag-key", "tag-protocol-mappers", "tag-realms-admin", "tag-role-mapper", "tag-roles", "tag-roles-by-id", "tag-scope-mappings", "tag-users"] +tags-all = ["tag-attack-detection", "tag-authentication-management", "tag-client-attribute-certificate", "tag-client-initial-access", "tag-client-registration-policy", "tag-client-role-mappings", "tag-client-scopes", "tag-clients", "tag-component", "tag-groups", "tag-identity-providers", "tag-key", "tag-organizations", "tag-protocol-mappers", "tag-realms-admin", "tag-role-mapper", "tag-roles", "tag-roles-by-id", "tag-scope-mappings", "tag-users"] tag-attack-detection = [] tag-authentication-management = [] tag-client-attribute-certificate = [] @@ -34,6 +34,7 @@ tag-component = [] tag-groups = [] tag-identity-providers = [] tag-key = [] +tag-organizations = [] tag-protocol-mappers = [] tag-realms-admin = [] tag-role-mapper = [] diff --git a/examples/openapi.rs b/examples/openapi.rs index fea6fe8..076f129 100644 --- a/examples/openapi.rs +++ b/examples/openapi.rs @@ -16,7 +16,7 @@ enum Cli { const RESERVED_WORDS: &[&str] = &["type", "self", "static", "use"]; mod openapi { - use std::{borrow::Cow, fmt::Display, str::FromStr, sync::Arc}; + use std::{borrow::Cow, collections::HashSet, fmt::Display, str::FromStr, sync::Arc}; use heck::{ToLowerCamelCase, ToSnakeCase, ToUpperCamelCase}; use indexmap::IndexMap; @@ -133,12 +133,17 @@ mod openapi { self.0.get(&ContentType::ApplicationOctetStream) } + fn as_html_form(&self) -> Option<&ContentSchema> { + self.0.get(&ContentType::HtmlForm) + } + fn as_any(&self) -> Option<&ContentSchema> { self.0.get(&ContentType::Any) } fn as_content_schema(&self) -> Option<&ContentSchema> { self.as_json() + .or(self.as_html_form()) .or(self.as_text_plain()) .or(self.as_binary_text()) .or(self.as_any()) @@ -158,6 +163,7 @@ mod openapi { self.as_json() .map(|_| format!("json(&{body_name})")) .or(self.as_text_plain().map(|_| format!("body({body_name})"))) + .or(self.as_html_form().map(|_| format!("form(&{body_name})"))) } fn to_rust_reqwest_parse_body_call(&self) -> Option<(Cow<'_, str>, Option>)> { @@ -169,6 +175,7 @@ mod openapi { .or(self.as_text_plain()) .map(|_| ("text", Some(".map(From::from)")))) .or(self.as_binary_blob().map(|_| ("bytes", None))) + .or(self.as_html_form().map(|_| ("form", None))) .map(|(method, conv)| (method.into(), conv.map(From::from))) } } @@ -195,6 +202,7 @@ mod openapi { #[derive(Debug, Deserialize)] struct Responses(IndexMap); + #[derive(Debug)] struct ReturnType<'rt> { value: Cow<'rt, str>, body: Option>, @@ -701,7 +709,7 @@ mod openapi { } } - #[derive(Debug, Deserialize)] + #[derive(Debug, Deserialize, PartialEq, Eq, Hash)] #[serde(untagged)] pub enum ObjectSchema

{ Struct(SchemaStruct

), @@ -736,11 +744,17 @@ mod openapi { } } - #[derive(Debug, Deserialize)] + #[derive(Debug, Deserialize, PartialEq, Eq)] pub struct SchemaStruct

{ pub properties: IndexMap, } + impl std::hash::Hash for SchemaStruct

{ + fn hash(&self, state: &mut H) { + self.properties.as_slice().hash(state); + } + } + impl SchemaStruct { fn to_rust_type_definition(&self, name: &str, ref_mode: RefMode) -> String { let mut fields = self @@ -844,12 +858,17 @@ pub struct {name} {{ } impl SchemaStruct { - fn to_rust_type(&self, _: RefMode) -> Cow { - todo!() + fn to_rust_type(&self, ref_mode: RefMode) -> Cow { + let property_types: HashSet<&Kind> = self.properties.values().collect(); + let property_type = match property_types.into_iter().collect::>().as_slice() { + &[property_type_kind] => property_type_kind.to_rust_type(ref_mode), + _ => "Value".into(), + }; + format!("TypeMap",).into() } } - #[derive(Debug, Deserialize)] + #[derive(Debug, Deserialize, PartialEq, Eq, Hash)] #[serde(rename_all = "camelCase")] pub struct SchemaMap

{ pub additional_properties: P, @@ -874,7 +893,7 @@ pub struct {name} {{ } } - #[derive(Debug, Deserialize)] + #[derive(Debug, Deserialize, PartialEq, Eq, Hash)] #[serde(rename_all = "camelCase")] pub struct SchemaAllOf

{ pub all_of: Vec

, @@ -932,7 +951,7 @@ pub enum {name} {{ Std, } - #[derive(Debug, Deserialize)] + #[derive(Debug, Deserialize, PartialEq, Eq, Hash)] #[serde(untagged)] pub enum Kind { Generic(Generic), @@ -999,7 +1018,7 @@ pub enum {name} {{ } } - #[derive(Debug, Deserialize)] + #[derive(Debug, Deserialize, PartialEq, Eq, Hash)] pub struct Property { #[serde(default)] deprecated: bool, @@ -1024,7 +1043,7 @@ pub enum {name} {{ } } - #[derive(Debug, Deserialize)] + #[derive(Debug, Deserialize, PartialEq, Eq, Hash)] #[serde(rename_all = "lowercase", tag = "type")] pub enum Generic { Array { @@ -1040,13 +1059,13 @@ pub enum {name} {{ String, } - #[derive(Debug, Deserialize)] + #[derive(Debug, Deserialize, PartialEq, Eq, Hash)] pub struct Ref { #[serde(rename = "$ref")] pub reference: String, } - #[derive(Debug, Deserialize)] + #[derive(Debug, Deserialize, PartialEq, Eq, Hash)] #[serde(rename_all = "lowercase")] pub enum IntegerFormat { Int32,