Loading codegen/src/v1/aws_conv.rs +2 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { match name.as_str() { "SelectObjectContentRequest" => continue, "SelectObjectContentInput" => continue, "AssumeRoleOutput" => continue, _ if super::sts::NAMES.iter().any(|n| n.eq_ignore_ascii_case(name)) => continue, _ => {} } Loading codegen/src/v1/dto.rs +2 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,8 @@ use rust_utils::default::default; use serde_json::Value; pub fn to_type_name(shape_name: &str) -> &str { shape_name.strip_prefix("com.amazonaws.s3#").unwrap() let Some((_, name)) = shape_name.split_once('#') else { panic!() }; name } pub type RustTypes = BTreeMap<String, rust::Type>; Loading codegen/src/v1/mod.rs +8 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ mod error; mod headers; mod ops; mod s3_trait; mod sts; mod xml; mod aws_conv; Loading @@ -17,7 +18,13 @@ mod aws_proxy; use codegen_writer::Codegen; pub fn run() { let model = smithy::Model::load_json("model/s3.json"); let model = { let mut s3_model = smithy::Model::load_json("model/s3.json"); let mut sts_model = smithy::Model::load_json("model/sts.json"); sts::reduce(&mut sts_model); s3_model.shapes.append(&mut sts_model.shapes); s3_model }; let ops = ops::collect_operations(&model); let rust_types = dto::collect_rust_types(&model, &ops); Loading codegen/src/v1/sts.rs 0 → 100644 +54 −0 Original line number Diff line number Diff line use crate::v2::smithy; use crate::v2::utils::o; use std::mem; use std::ops::Not; use heck::ToUpperCamelCase; pub const NAMES: &[&str] = &[ "AssumeRoleResponse", "AssumedRoleUser", "Credentials", "nonNegativeIntegerType", "sourceIdentityType", "arnType", "accessKeyIdType", "accessKeySecretType", "dateType", "tokenType", "assumedRoleIdType", ]; pub fn reduce(model: &mut smithy::Model) { for (shape_name, mut shape) in mem::take(&mut model.shapes) { let Some((_, name)) = shape_name.split_once('#') else { panic!() }; if NAMES.contains(&name).not() { continue; } let Some((_, name)) = shape_name.split_once('#') else { panic!() }; let new_name = match name { "AssumeRoleResponse" => o("AssumeRoleOutput"), _ if name.as_bytes()[0].is_ascii_lowercase() => name.to_upper_camel_case(), _ => o(name), }; if let smithy::Shape::Structure(ref mut shape) = shape { for member in shape.members.values_mut() { let Some((_, name)) = member.target.split_once('#') else { panic!() }; let new_name = match name { _ if name.as_bytes()[0].is_ascii_lowercase() => name.to_upper_camel_case(), _ => continue, }; member.target = member.target.replace(name, &new_name); } if name == "AssumeRoleResponse" { shape.traits.set("smithy.api#xmlName", name.into()); } } let new_shape_name = format!("com.amazonaws.s3#{new_name}"); assert!(model.shapes.insert(new_shape_name, shape).is_none()); } } codegen/src/v1/xml.rs +35 −8 Original line number Diff line number Diff line Loading @@ -29,13 +29,17 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { for (&ty_name, &xml_name) in &root_type_names { match xml_name { Some(xml_name) if xml_name != ty_name => { if can_impl_serialize(ty_name) { g!("// Serialize: {ty_name} {xml_name:?}"); } if can_impl_deserialize(rust_types, ty_name) { g!("// Deserialize: {ty_name} {xml_name:?}"); } } _ => { if can_impl_serialize(ty_name) { g!("// Serialize: {ty_name}"); } if can_impl_deserialize(rust_types, ty_name) { g!("// Deserialize: {ty_name}"); } Loading @@ -44,8 +48,10 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { } g!(); for ty_name in &field_type_names { if can_impl_serialize_content(ty_name) { g!("// SerializeContent: {ty_name}"); if can_impl_deserialize(rust_types, ty_name) { } if can_impl_deserialize_content(rust_types, ty_name) { g!("// DeserializeContent: {ty_name}"); } } Loading Loading @@ -100,7 +106,7 @@ fn collect_xml_types<'a>( } { let extra = ["Progress", "Stats"]; let extra = ["Progress", "Stats", "AssumeRoleOutput"]; for ty_name in extra { root_type_names.insert(ty_name, None); field_type_names.insert(ty_name); Loading Loading @@ -153,7 +159,28 @@ fn collect_xml_types<'a>( (root_type_names, field_type_names) } const SPECIAL_TYPES: &[&str] = &["AssumeRoleOutput"]; fn can_impl_serialize(ty_name: &str) -> bool { if SPECIAL_TYPES.contains(&ty_name) { return false; } can_impl_serialize_content(ty_name) } fn can_impl_serialize_content(_ty_name: &str) -> bool { true } fn can_impl_deserialize(rust_types: &RustTypes, ty_name: &str) -> bool { if SPECIAL_TYPES.contains(&ty_name) { return false; } can_impl_deserialize_content(rust_types, ty_name) } fn can_impl_deserialize_content(rust_types: &RustTypes, ty_name: &str) -> bool { let rust_type = &rust_types[ty_name]; match rust_type { rust::Type::Struct(ty) => { Loading Loading @@ -191,7 +218,7 @@ fn codegen_xml_serde(ops: &Operations, rust_types: &RustTypes, root_type_names: // https://github.com/Nugine/s3s/issues/2 let xml_name = xml_name.or(ty.xml_name.as_deref()).unwrap_or(&ty.name); { if can_impl_serialize(&ty.name) { g!("impl Serialize for {} {{", ty.name); g!("fn serialize<W: Write>(&self, s: &mut Serializer<W>) -> SerResult {{"); Loading Loading @@ -280,7 +307,7 @@ fn codegen_xml_serde_content(ops: &Operations, rust_types: &RustTypes, field_typ #[allow(clippy::too_many_lines)] fn codegen_xml_serde_content_struct(_ops: &Operations, rust_types: &RustTypes, ty: &rust::Struct) { { if can_impl_serialize_content(&ty.name) { g!("impl SerializeContent for {} {{", ty.name); g!( "fn serialize_content<W: Write>(&self, {}: &mut Serializer<W>) -> SerResult {{", Loading Loading @@ -341,7 +368,7 @@ fn codegen_xml_serde_content_struct(_ops: &Operations, rust_types: &RustTypes, t g!("}}"); g!(); } if can_impl_deserialize(rust_types, &ty.name) { if can_impl_deserialize_content(rust_types, &ty.name) { g!("impl<'xml> DeserializeContent<'xml> for {} {{", ty.name); g!( "fn deserialize_content({}: &mut Deserializer<'xml>) -> DeResult<Self> {{", Loading Loading
codegen/src/v1/aws_conv.rs +2 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { match name.as_str() { "SelectObjectContentRequest" => continue, "SelectObjectContentInput" => continue, "AssumeRoleOutput" => continue, _ if super::sts::NAMES.iter().any(|n| n.eq_ignore_ascii_case(name)) => continue, _ => {} } Loading
codegen/src/v1/dto.rs +2 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,8 @@ use rust_utils::default::default; use serde_json::Value; pub fn to_type_name(shape_name: &str) -> &str { shape_name.strip_prefix("com.amazonaws.s3#").unwrap() let Some((_, name)) = shape_name.split_once('#') else { panic!() }; name } pub type RustTypes = BTreeMap<String, rust::Type>; Loading
codegen/src/v1/mod.rs +8 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ mod error; mod headers; mod ops; mod s3_trait; mod sts; mod xml; mod aws_conv; Loading @@ -17,7 +18,13 @@ mod aws_proxy; use codegen_writer::Codegen; pub fn run() { let model = smithy::Model::load_json("model/s3.json"); let model = { let mut s3_model = smithy::Model::load_json("model/s3.json"); let mut sts_model = smithy::Model::load_json("model/sts.json"); sts::reduce(&mut sts_model); s3_model.shapes.append(&mut sts_model.shapes); s3_model }; let ops = ops::collect_operations(&model); let rust_types = dto::collect_rust_types(&model, &ops); Loading
codegen/src/v1/sts.rs 0 → 100644 +54 −0 Original line number Diff line number Diff line use crate::v2::smithy; use crate::v2::utils::o; use std::mem; use std::ops::Not; use heck::ToUpperCamelCase; pub const NAMES: &[&str] = &[ "AssumeRoleResponse", "AssumedRoleUser", "Credentials", "nonNegativeIntegerType", "sourceIdentityType", "arnType", "accessKeyIdType", "accessKeySecretType", "dateType", "tokenType", "assumedRoleIdType", ]; pub fn reduce(model: &mut smithy::Model) { for (shape_name, mut shape) in mem::take(&mut model.shapes) { let Some((_, name)) = shape_name.split_once('#') else { panic!() }; if NAMES.contains(&name).not() { continue; } let Some((_, name)) = shape_name.split_once('#') else { panic!() }; let new_name = match name { "AssumeRoleResponse" => o("AssumeRoleOutput"), _ if name.as_bytes()[0].is_ascii_lowercase() => name.to_upper_camel_case(), _ => o(name), }; if let smithy::Shape::Structure(ref mut shape) = shape { for member in shape.members.values_mut() { let Some((_, name)) = member.target.split_once('#') else { panic!() }; let new_name = match name { _ if name.as_bytes()[0].is_ascii_lowercase() => name.to_upper_camel_case(), _ => continue, }; member.target = member.target.replace(name, &new_name); } if name == "AssumeRoleResponse" { shape.traits.set("smithy.api#xmlName", name.into()); } } let new_shape_name = format!("com.amazonaws.s3#{new_name}"); assert!(model.shapes.insert(new_shape_name, shape).is_none()); } }
codegen/src/v1/xml.rs +35 −8 Original line number Diff line number Diff line Loading @@ -29,13 +29,17 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { for (&ty_name, &xml_name) in &root_type_names { match xml_name { Some(xml_name) if xml_name != ty_name => { if can_impl_serialize(ty_name) { g!("// Serialize: {ty_name} {xml_name:?}"); } if can_impl_deserialize(rust_types, ty_name) { g!("// Deserialize: {ty_name} {xml_name:?}"); } } _ => { if can_impl_serialize(ty_name) { g!("// Serialize: {ty_name}"); } if can_impl_deserialize(rust_types, ty_name) { g!("// Deserialize: {ty_name}"); } Loading @@ -44,8 +48,10 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { } g!(); for ty_name in &field_type_names { if can_impl_serialize_content(ty_name) { g!("// SerializeContent: {ty_name}"); if can_impl_deserialize(rust_types, ty_name) { } if can_impl_deserialize_content(rust_types, ty_name) { g!("// DeserializeContent: {ty_name}"); } } Loading Loading @@ -100,7 +106,7 @@ fn collect_xml_types<'a>( } { let extra = ["Progress", "Stats"]; let extra = ["Progress", "Stats", "AssumeRoleOutput"]; for ty_name in extra { root_type_names.insert(ty_name, None); field_type_names.insert(ty_name); Loading Loading @@ -153,7 +159,28 @@ fn collect_xml_types<'a>( (root_type_names, field_type_names) } const SPECIAL_TYPES: &[&str] = &["AssumeRoleOutput"]; fn can_impl_serialize(ty_name: &str) -> bool { if SPECIAL_TYPES.contains(&ty_name) { return false; } can_impl_serialize_content(ty_name) } fn can_impl_serialize_content(_ty_name: &str) -> bool { true } fn can_impl_deserialize(rust_types: &RustTypes, ty_name: &str) -> bool { if SPECIAL_TYPES.contains(&ty_name) { return false; } can_impl_deserialize_content(rust_types, ty_name) } fn can_impl_deserialize_content(rust_types: &RustTypes, ty_name: &str) -> bool { let rust_type = &rust_types[ty_name]; match rust_type { rust::Type::Struct(ty) => { Loading Loading @@ -191,7 +218,7 @@ fn codegen_xml_serde(ops: &Operations, rust_types: &RustTypes, root_type_names: // https://github.com/Nugine/s3s/issues/2 let xml_name = xml_name.or(ty.xml_name.as_deref()).unwrap_or(&ty.name); { if can_impl_serialize(&ty.name) { g!("impl Serialize for {} {{", ty.name); g!("fn serialize<W: Write>(&self, s: &mut Serializer<W>) -> SerResult {{"); Loading Loading @@ -280,7 +307,7 @@ fn codegen_xml_serde_content(ops: &Operations, rust_types: &RustTypes, field_typ #[allow(clippy::too_many_lines)] fn codegen_xml_serde_content_struct(_ops: &Operations, rust_types: &RustTypes, ty: &rust::Struct) { { if can_impl_serialize_content(&ty.name) { g!("impl SerializeContent for {} {{", ty.name); g!( "fn serialize_content<W: Write>(&self, {}: &mut Serializer<W>) -> SerResult {{", Loading Loading @@ -341,7 +368,7 @@ fn codegen_xml_serde_content_struct(_ops: &Operations, rust_types: &RustTypes, t g!("}}"); g!(); } if can_impl_deserialize(rust_types, &ty.name) { if can_impl_deserialize_content(rust_types, &ty.name) { g!("impl<'xml> DeserializeContent<'xml> for {} {{", ty.name); g!( "fn deserialize_content({}: &mut Deserializer<'xml>) -> DeResult<Self> {{", Loading