diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e890fb86..c0783363 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,15 +1,21 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. # Please see the documentation for all configuration options: -# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference version: 2 updates: - - package-ecosystem: "cargo" # See documentation for possible values - directory: "/generator" # Location of package manifests + - package-ecosystem: "cargo" + directory: "/generator" schedule: - interval: "daily" - - package-ecosystem: "github-actions" # See documentation for possible values - directory: "/" # Location of package manifests + interval: "weekly" + groups: + cargo-crates: + patterns: + - "*" + - package-ecosystem: "github-actions" + directory: "/" schedule: - interval: "daily" + interval: "weekly" + groups: + github-actions: + patterns: + - "*" diff --git a/Cargo.toml b/Cargo.toml index 8c5d873c..266b80fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,3 +23,5 @@ members = [ "tripactions", "zoom" ] + +resolver = "2" diff --git a/Makefile b/Makefile index 85841316..9f6b9e0c 100644 --- a/Makefile +++ b/Makefile @@ -574,4 +574,4 @@ zoom: target/debug/generator $(ZOOM_SPEC) .PHONY: README.md README.md: ## Cleans client info in README.md. - @sed -i '/## Clients Generated/q' $@ + @sed -i'' '/## Clients Generated/q' $@ diff --git a/generator/src/functions.rs b/generator/src/functions.rs index 04600ca6..b18fa11c 100644 --- a/generator/src/functions.rs +++ b/generator/src/functions.rs @@ -5,8 +5,8 @@ use inflector::cases::{pascalcase::to_pascal_case, snakecase::to_snake_case}; use crate::{ clean_fn_name, clean_name, client::generate_servers, get_parameter_data, make_plural, - oid_to_object_name, path_to_operation_id, struct_name, template::parse, ExtractJsonMediaType, - ParameterDataExt, ReferenceOrExt, TypeId, TypeSpace, + oid_to_object_name, path_to_operation_id, struct_name, template::parse, ParameterDataExt, + ReferenceOrExt, TypeId, TypeSpace, }; #[derive(Debug, Default)] @@ -151,7 +151,7 @@ pub fn generate_files( let (body_param, body_func) = if let Some(b) = &o.request_body { if let Ok(b) = b.item() { - if b.is_binary()? { + if crate::is_binary(b)? { let (ct, _) = b.content.first().unwrap(); body_content_type_header = Some(ct.to_string()); diff --git a/generator/src/main.rs b/generator/src/main.rs index 14adaefd..cc64f84e 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -380,157 +380,72 @@ impl ParameterDataExt for openapiv3::ParameterData { } } -trait ExtractJsonMediaType { - fn is_binary(&self) -> Result; - fn content_json(&self) -> Result; +trait HasContent { + fn get_content(&self, key: &str) -> Option<&openapiv3::MediaType>; } -impl ExtractJsonMediaType for openapiv3::Response { - fn content_json(&self) -> Result { - // We do not need to check the length of the content because there might be - // more than one. For example, if xml or some other format is also defined. - if let Some(mt) = self.content.get("application/json") { - Ok(mt.clone()) - } else { - bail!( - "could not find application/json, only found {}", - self.content.keys().next().unwrap() - ); - } - } - - fn is_binary(&self) -> Result { - if self.content.is_empty() { - /* - * XXX If there are no content types, I guess it is not binary? - */ - return Ok(false); - } - - // We do not need to check the length of the content because there might be - // more than one. For example, if xml or some other format is also defined. - if let Some(mt) = self.content.get("application/octet-stream") { - if !mt.encoding.is_empty() { - bail!("XXX encoding"); - } - - if let Some(s) = &mt.schema { - use openapiv3::{SchemaKind, StringFormat, Type, VariantOrUnknownOrEmpty::Item}; - - if let Ok(s) = s.item() { - if s.schema_data.nullable { - bail!("XXX nullable binary?"); - } - if s.schema_data.default.is_some() { - bail!("XXX default binary?"); - } - if s.schema_data.discriminator.is_some() { - bail!("XXX binary discriminator?"); - } - match &s.schema_kind { - SchemaKind::Type(Type::String(st)) => { - if st.min_length.is_some() || st.max_length.is_some() { - bail!("binary min/max length"); - } - if !matches!(st.format, Item(StringFormat::Binary)) { - bail!("expected binary format string, got {:?}", st.format); - } - if st.pattern.is_some() { - bail!("XXX pattern"); - } - if !st.enumeration.is_empty() { - bail!("XXX binary enumeration {:?}", st); - } - return Ok(true); - } - x => { - bail!("XXX schemakind type {:?}", x); - } - } - } else { - return Ok(false); - } - } else { - bail!("binary thing had no schema?"); - } - } - - Ok(false) +impl HasContent for openapiv3::Response { + fn get_content(&self, key: &str) -> Option<&openapiv3::MediaType> { + self.content.get(key) } } -impl ExtractJsonMediaType for openapiv3::RequestBody { - fn content_json(&self) -> Result { - // We do not need to check the length of the content because there might be - // more than one. For example, if xml or some other format is also defined. - if let Some(mt) = self.content.get("application/json") { - Ok(mt.clone()) - } else { - bail!( - "could not find application/json, only found {}", - self.content.keys().next().unwrap() - ); - } +impl HasContent for openapiv3::RequestBody { + fn get_content(&self, key: &str) -> Option<&openapiv3::MediaType> { + self.content.get(key) } +} - fn is_binary(&self) -> Result { - if self.content.is_empty() { - /* - * XXX If there are no content types, I guess it is not binary? - */ - return Ok(false); +fn is_binary(this: &impl HasContent) -> Result { + // We do not need to check the length of the content because there might be + // more than one. For example, if xml or some other format is also defined. + if let Some(mt) = this.get_content("application/octet-stream") { + if !mt.encoding.is_empty() { + bail!("XXX encoding"); } - // We do not need to check the length of the content because there might be - // more than one. For example, if xml or some other format is also defined. - if let Some(mt) = self.content.get("application/octet-stream") { - if !mt.encoding.is_empty() { - bail!("XXX encoding"); - } - - if let Some(s) = &mt.schema { - use openapiv3::{SchemaKind, StringFormat, Type, VariantOrUnknownOrEmpty::Item}; + if let Some(s) = &mt.schema { + use openapiv3::{SchemaKind, StringFormat, Type, VariantOrUnknownOrEmpty::Item}; - if let Ok(s) = s.item() { - if s.schema_data.nullable { - bail!("XXX nullable binary?"); - } - if s.schema_data.default.is_some() { - bail!("XXX default binary?"); - } - if s.schema_data.discriminator.is_some() { - bail!("XXX binary discriminator?"); - } - match &s.schema_kind { - SchemaKind::Type(Type::String(st)) => { - if st.min_length.is_some() || st.max_length.is_some() { - bail!("binary min/max length"); - } - if !matches!(st.format, Item(StringFormat::Binary)) { - bail!("expected binary format string, got {:?}", st.format); - } - if st.pattern.is_some() { - bail!("XXX pattern"); - } - if !st.enumeration.is_empty() { - bail!("XXX enumeration"); - } - return Ok(true); + if let Ok(s) = s.item() { + if s.schema_data.nullable { + bail!("XXX nullable binary?"); + } + if s.schema_data.default.is_some() { + bail!("XXX default binary?"); + } + if s.schema_data.discriminator.is_some() { + bail!("XXX binary discriminator?"); + } + match &s.schema_kind { + SchemaKind::Type(Type::String(st)) => { + if st.min_length.is_some() || st.max_length.is_some() { + bail!("binary min/max length"); + } + if !matches!(st.format, Item(StringFormat::Binary)) { + bail!("expected binary format string, got {:?}", st.format); } - x => { - bail!("XXX schemakind type {:?}", x); + if st.pattern.is_some() { + bail!("XXX pattern"); } + if !st.enumeration.is_empty() { + bail!("XXX binary enumeration {:?}", st); + } + return Ok(true); + } + x => { + bail!("XXX schemakind type {:?}", x); } - } else { - return Ok(false); } } else { - bail!("binary thing had no schema?"); + return Ok(false); } + } else { + bail!("binary thing had no schema?"); } - - Ok(false) } + + Ok(false) } trait ReferenceOrExt {