Loading codegen/Cargo.toml +3 −3 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ publish = false [dependencies] heck = "0.4.1" regex = "1.7.1" serde = { version = "1.0.152", features = ["derive"] } serde_json = { version = "1.0.93", features = ["preserve_order"] } regex = "1.7.3" serde = { version = "1.0.159", features = ["derive"] } serde_json = { version = "1.0.95", features = ["preserve_order"] } serde_urlencoded = "0.7.1" codegen/src/aws_conv.rs +32 −16 Original line number Diff line number Diff line use heck::ToUpperCamelCase; use crate::dto::RustTypes; use crate::f; use crate::gen::Codegen; use crate::ops::Operations; use crate::rust; use heck::ToSnakeCase; use heck::ToUpperCamelCase; pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) { g.lines([ "//! Auto generated by codegen/src/aws_conv.rs", "//! Auto generated by codegen/src/aws_conv.rs", // "", "use super::*;", "", "use aws_sdk_s3::input::*;", "use aws_sdk_s3::output::*;", "use aws_sdk_s3::model::*;", "use aws_sdk_s3::error::*;", "", ]); for (name, rust_type) in rust_types { Loading @@ -39,10 +35,10 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) { } let s3s_path = f!("s3s::dto::{name}"); let aws_name = aws_ty_name(name); let aws_path = aws_ty_path(name, ops, rust_types); g.ln(f!("impl AwsConversion for {s3s_path} {{")); g.ln(f!(" type Target = {aws_name};")); g.ln(f!(" type Target = {aws_path};")); g.ln("type Error = S3Error;"); g.lf(); Loading Loading @@ -85,18 +81,18 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) { "CRC32C" => "Crc32C".to_owned(), _ => s3s_variant_name.to_upper_camel_case(), }; g.ln(f!("{aws_name}::{aws_variant_name} => Self::from_static(Self::{s3s_variant_name}),")); g.ln(f!("{aws_path}::{aws_variant_name} => Self::from_static(Self::{s3s_variant_name}),")); } g.ln(f!("{aws_name}::Unknown(_) => Self::from(x.as_str().to_owned()),")); g.ln(f!("{aws_path}::Unknown(_) => Self::from(x.as_str().to_owned()),")); g.ln("_ => Self::from(x.as_str().to_owned()),"); g.ln("})"); } rust::Type::StructEnum(ty) => { g.ln("Ok(match x {"); for variant in &ty.variants { g.ln(f!("{aws_name}::{0}(v) => Self::{0}(try_from_aws(v)?),", variant.name)); g.ln(f!("{aws_path}::{0}(v) => Self::{0}(try_from_aws(v)?),", variant.name)); } g.ln(f!("_ => unimplemented!(\"unknown variant of {aws_name}: {{x:?}}\"),")); g.ln(f!("_ => unimplemented!(\"unknown variant of {aws_path}: {{x:?}}\"),")); g.ln("})"); } _ => panic!(), Loading Loading @@ -144,12 +140,12 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) { } } rust::Type::StrEnum(_) => { g.ln(f!("Ok({aws_name}::from(x.as_str()))")); g.ln(f!("Ok({aws_path}::from(x.as_str()))")); } rust::Type::StructEnum(ty) => { g.ln("Ok(match x {"); for variant in &ty.variants { g.ln(f!("Self::{0}(v) => {aws_name}::{0}(try_into_aws(v)?),", variant.name)); g.ln(f!("Self::{0}(v) => {aws_path}::{0}(try_into_aws(v)?),", variant.name)); } g.ln(f!("_ => unimplemented!(\"unknown variant of {}: {{x:?}}\"),", ty.name)); g.ln("})"); Loading Loading @@ -183,6 +179,26 @@ fn aws_ty_name(name: &str) -> &str { } } fn aws_ty_path(name: &str, ops: &Operations, rust_types: &RustTypes) -> String { let aws_name = aws_ty_name(name); for suffix in ["Input", "Output", "Error"] { if let Some(op_name) = name.strip_suffix(suffix) { if ops.contains_key(op_name) { return f!("aws_sdk_s3::operation::{}::{aws_name}", op_name.to_snake_case()); } } } if let Some(rust::Type::Struct(ty)) = rust_types.get(name) { if ty.is_error_type { return f!("aws_sdk_s3::types::error::{aws_name}"); } } f!("aws_sdk_s3::types::{aws_name}") } fn is_op_input(name: &str, ops: &Operations) -> bool { if let Some(op) = name.strip_suffix("Input") { if ops.contains_key(op) { Loading codegen/src/dto.rs +4 −0 Original line number Diff line number Diff line Loading @@ -192,6 +192,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes doc: shape.traits.doc().map(ToOwned::to_owned), xml_name: shape.traits.xml_name().map(o), is_error_type: shape.traits.error().is_some(), }); insert(name, ty); } Loading Loading @@ -235,6 +236,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes fields: ty.fields.iter().filter(|x| x.position == "xml").cloned().collect(), doc: ty.doc.clone(), xml_name: None, is_error_type: false, }; ty.fields.iter().for_each(|x| assert!(x.name != "request")); Loading Loading @@ -270,6 +272,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes fields: default(), doc: None, xml_name: None, is_error_type: false, } } else { assert!(op.smithy_input.ends_with("Request")); Loading @@ -288,6 +291,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes fields: default(), doc: None, xml_name: None, is_error_type: false, } } else { if op.smithy_output == op.output { Loading codegen/src/rust.rs +1 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ pub struct Struct { pub doc: Option<String>, pub xml_name: Option<String>, pub is_error_type: bool, } #[derive(Debug, Clone)] Loading codegen/src/smithy.rs +4 −0 Original line number Diff line number Diff line Loading @@ -231,4 +231,8 @@ impl Traits { .as_u64() .map(|v| v as u16) } pub fn error(&self) -> Option<&str> { self.get("smithy.api#error")?.as_str() } } Loading
codegen/Cargo.toml +3 −3 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ publish = false [dependencies] heck = "0.4.1" regex = "1.7.1" serde = { version = "1.0.152", features = ["derive"] } serde_json = { version = "1.0.93", features = ["preserve_order"] } regex = "1.7.3" serde = { version = "1.0.159", features = ["derive"] } serde_json = { version = "1.0.95", features = ["preserve_order"] } serde_urlencoded = "0.7.1"
codegen/src/aws_conv.rs +32 −16 Original line number Diff line number Diff line use heck::ToUpperCamelCase; use crate::dto::RustTypes; use crate::f; use crate::gen::Codegen; use crate::ops::Operations; use crate::rust; use heck::ToSnakeCase; use heck::ToUpperCamelCase; pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) { g.lines([ "//! Auto generated by codegen/src/aws_conv.rs", "//! Auto generated by codegen/src/aws_conv.rs", // "", "use super::*;", "", "use aws_sdk_s3::input::*;", "use aws_sdk_s3::output::*;", "use aws_sdk_s3::model::*;", "use aws_sdk_s3::error::*;", "", ]); for (name, rust_type) in rust_types { Loading @@ -39,10 +35,10 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) { } let s3s_path = f!("s3s::dto::{name}"); let aws_name = aws_ty_name(name); let aws_path = aws_ty_path(name, ops, rust_types); g.ln(f!("impl AwsConversion for {s3s_path} {{")); g.ln(f!(" type Target = {aws_name};")); g.ln(f!(" type Target = {aws_path};")); g.ln("type Error = S3Error;"); g.lf(); Loading Loading @@ -85,18 +81,18 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) { "CRC32C" => "Crc32C".to_owned(), _ => s3s_variant_name.to_upper_camel_case(), }; g.ln(f!("{aws_name}::{aws_variant_name} => Self::from_static(Self::{s3s_variant_name}),")); g.ln(f!("{aws_path}::{aws_variant_name} => Self::from_static(Self::{s3s_variant_name}),")); } g.ln(f!("{aws_name}::Unknown(_) => Self::from(x.as_str().to_owned()),")); g.ln(f!("{aws_path}::Unknown(_) => Self::from(x.as_str().to_owned()),")); g.ln("_ => Self::from(x.as_str().to_owned()),"); g.ln("})"); } rust::Type::StructEnum(ty) => { g.ln("Ok(match x {"); for variant in &ty.variants { g.ln(f!("{aws_name}::{0}(v) => Self::{0}(try_from_aws(v)?),", variant.name)); g.ln(f!("{aws_path}::{0}(v) => Self::{0}(try_from_aws(v)?),", variant.name)); } g.ln(f!("_ => unimplemented!(\"unknown variant of {aws_name}: {{x:?}}\"),")); g.ln(f!("_ => unimplemented!(\"unknown variant of {aws_path}: {{x:?}}\"),")); g.ln("})"); } _ => panic!(), Loading Loading @@ -144,12 +140,12 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) { } } rust::Type::StrEnum(_) => { g.ln(f!("Ok({aws_name}::from(x.as_str()))")); g.ln(f!("Ok({aws_path}::from(x.as_str()))")); } rust::Type::StructEnum(ty) => { g.ln("Ok(match x {"); for variant in &ty.variants { g.ln(f!("Self::{0}(v) => {aws_name}::{0}(try_into_aws(v)?),", variant.name)); g.ln(f!("Self::{0}(v) => {aws_path}::{0}(try_into_aws(v)?),", variant.name)); } g.ln(f!("_ => unimplemented!(\"unknown variant of {}: {{x:?}}\"),", ty.name)); g.ln("})"); Loading Loading @@ -183,6 +179,26 @@ fn aws_ty_name(name: &str) -> &str { } } fn aws_ty_path(name: &str, ops: &Operations, rust_types: &RustTypes) -> String { let aws_name = aws_ty_name(name); for suffix in ["Input", "Output", "Error"] { if let Some(op_name) = name.strip_suffix(suffix) { if ops.contains_key(op_name) { return f!("aws_sdk_s3::operation::{}::{aws_name}", op_name.to_snake_case()); } } } if let Some(rust::Type::Struct(ty)) = rust_types.get(name) { if ty.is_error_type { return f!("aws_sdk_s3::types::error::{aws_name}"); } } f!("aws_sdk_s3::types::{aws_name}") } fn is_op_input(name: &str, ops: &Operations) -> bool { if let Some(op) = name.strip_suffix("Input") { if ops.contains_key(op) { Loading
codegen/src/dto.rs +4 −0 Original line number Diff line number Diff line Loading @@ -192,6 +192,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes doc: shape.traits.doc().map(ToOwned::to_owned), xml_name: shape.traits.xml_name().map(o), is_error_type: shape.traits.error().is_some(), }); insert(name, ty); } Loading Loading @@ -235,6 +236,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes fields: ty.fields.iter().filter(|x| x.position == "xml").cloned().collect(), doc: ty.doc.clone(), xml_name: None, is_error_type: false, }; ty.fields.iter().for_each(|x| assert!(x.name != "request")); Loading Loading @@ -270,6 +272,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes fields: default(), doc: None, xml_name: None, is_error_type: false, } } else { assert!(op.smithy_input.ends_with("Request")); Loading @@ -288,6 +291,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes fields: default(), doc: None, xml_name: None, is_error_type: false, } } else { if op.smithy_output == op.output { Loading
codegen/src/rust.rs +1 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ pub struct Struct { pub doc: Option<String>, pub xml_name: Option<String>, pub is_error_type: bool, } #[derive(Debug, Clone)] Loading
codegen/src/smithy.rs +4 −0 Original line number Diff line number Diff line Loading @@ -231,4 +231,8 @@ impl Traits { .as_u64() .map(|v| v as u16) } pub fn error(&self) -> Option<&str> { self.get("smithy.api#error")?.as_str() } }