diff --git a/codegen/src/v1/aws_conv.rs b/codegen/src/v1/aws_conv.rs index 3b3a2ab..a4fa3a0 100644 --- a/codegen/src/v1/aws_conv.rs +++ b/codegen/src/v1/aws_conv.rs @@ -38,7 +38,11 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { rust::Type::List(_) => continue, rust::Type::Map(_) => continue, rust::Type::StrEnum(_) => {} - rust::Type::Struct(_) => {} + rust::Type::Struct(ty) => { + if ty.is_custom_extension { + continue; + } + } rust::Type::StructEnum(_) => {} } diff --git a/codegen/src/v1/dto.rs b/codegen/src/v1/dto.rs index 6248efa..e0c97a8 100644 --- a/codegen/src/v1/dto.rs +++ b/codegen/src/v1/dto.rs @@ -213,6 +213,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes xml_name: shape.traits.xml_name().map(o), is_error_type: shape.traits.error().is_some(), + is_custom_extension: shape.traits.minio(), }); insert(rs_shape_name, ty); } @@ -264,6 +265,7 @@ fn patch_types(space: &mut RustTypes) { doc: ty.doc.clone(), xml_name: None, is_error_type: false, + is_custom_extension: false, }; ty.fields.iter().for_each(|x| assert!(x.name != "request")); @@ -309,6 +311,7 @@ fn unify_operation_types(ops: &Operations, space: &mut RustTypes) { doc: None, xml_name: None, is_error_type: false, + is_custom_extension: false, } } else { assert!(op.smithy_input.ends_with("Request")); @@ -328,6 +331,7 @@ fn unify_operation_types(ops: &Operations, space: &mut RustTypes) { doc: None, xml_name: None, is_error_type: false, + is_custom_extension: false, } } else { if op.smithy_output == op.output { diff --git a/codegen/src/v1/minio.rs b/codegen/src/v1/minio.rs index 004af2a..e4ade2b 100644 --- a/codegen/src/v1/minio.rs +++ b/codegen/src/v1/minio.rs @@ -1,44 +1,37 @@ -use core::str; - -use super::o; use super::smithy; -use super::smithy::BooleanShape; -use super::smithy::StructureMember; - -use serde_json::json; fn git_branch() -> String { let output = std::process::Command::new("git") .args(["rev-parse", "--abbrev-ref", "HEAD"]) .output() .unwrap(); - let stdout = str::from_utf8(&output.stdout).unwrap(); + let stdout = core::str::from_utf8(&output.stdout).unwrap(); stdout.trim().to_owned() } +/// pub fn patch(model: &mut smithy::Model) { let branch_name = git_branch(); if !matches!(branch_name.as_str(), "minio" | "feat/minio") { return; } - model.shapes.insert( - o("com.amazonaws.s3#ForceDelete"), - smithy::Shape::Boolean(BooleanShape { - traits: smithy::Traits::default(), - }), - ); + let patches = smithy::Model::load_json("model/minio-patches.json"); - let ty = "com.amazonaws.s3#DeleteBucketRequest"; - let Some(smithy::Shape::Structure(shape)) = model.shapes.get_mut(ty) else { panic!() }; - shape.members.insert( - o("ForceDelete"), - StructureMember { - target: o("com.amazonaws.s3#ForceDelete"), - traits: smithy::Traits::from_value(json!( { - "smithy.api#httpHeader": "x-minio-force-delete", - "s3s#minio": "" - })), - }, - ); + for (shape_name, patch) in patches.shapes { + match model.shapes.get_mut(&shape_name) { + None => { + model.shapes.insert(shape_name, patch); + } + Some(shape) => match shape { + smithy::Shape::Structure(shape) => { + let smithy::Shape::Structure(patch) = patch else { panic!() }; + for (field_name, member) in patch.members { + assert!(shape.members.insert(field_name, member).is_none()); + } + } + _ => unimplemented!(), + }, + } + } } diff --git a/codegen/src/v1/rust.rs b/codegen/src/v1/rust.rs index 978ee9a..0682654 100644 --- a/codegen/src/v1/rust.rs +++ b/codegen/src/v1/rust.rs @@ -71,6 +71,8 @@ pub struct Struct { pub xml_name: Option, pub is_error_type: bool, + + pub is_custom_extension: bool, } #[allow(clippy::struct_excessive_bools)] diff --git a/codegen/src/v2/smithy.rs b/codegen/src/v2/smithy.rs index d2b7911..36e74ea 100644 --- a/codegen/src/v2/smithy.rs +++ b/codegen/src/v2/smithy.rs @@ -255,11 +255,6 @@ impl Traits { self.get("smithy.api#error")?.as_str() } - pub fn from_value(value: Value) -> Self { - let Value::Object(map) = value else { panic!() }; - Self(Some(map)) - } - pub fn minio(&self) -> bool { self.get("s3s#minio").is_some() } diff --git a/crates/s3s/src/dto/generated.rs b/crates/s3s/src/dto/generated.rs index e2930ad..6eff782 100644 --- a/crates/s3s/src/dto/generated.rs +++ b/crates/s3s/src/dto/generated.rs @@ -1,4 +1,4 @@ -//! Auto generated by `codegen/src/v1/dto.rs:350` +//! Auto generated by `codegen/src/v1/dto.rs:354` #![allow(clippy::empty_structs_with_brackets)] #![allow(clippy::too_many_lines)] diff --git a/crates/s3s/tests/xml.rs b/crates/s3s/tests/xml.rs index a9a068d..a6a57a0 100644 --- a/crates/s3s/tests/xml.rs +++ b/crates/s3s/tests/xml.rs @@ -275,3 +275,21 @@ fn assume_role_output() { let val = deserialize::(xml.as_bytes()).unwrap(); test_serde(&val); } + +// #[test] +// fn minio_versioning_configuration() { +// let xml = r#" +// +// Enabled +// +// a +// +// +// b +// +// true +// +// "#; +// let val = deserialize::(xml.as_bytes()).unwrap(); +// test_serde(&val); +// } diff --git a/model/minio-patches.json b/model/minio-patches.json new file mode 100644 index 0000000..71e0014 --- /dev/null +++ b/model/minio-patches.json @@ -0,0 +1,59 @@ +{ + "smithy": "2.0", + "shapes": { + "com.amazonaws.s3#ForceDelete": { + "type": "boolean" + }, + "com.amazonaws.s3#DeleteBucketRequest": { + "type": "structure", + "members": { + "ForceDelete": { + "target": "com.amazonaws.s3#ForceDelete", + "traits": { + "smithy.api#httpHeader": "x-minio-force-delete", + "s3s#minio": "" + } + } + } + }, + "com.amazonaws.s3#ExcludeFolders": { + "type": "boolean" + }, + "com.amazonaws.s3#ExcludedPrefix": { + "type": "structure", + "members": { + "Prefix": { + "target": "com.amazonaws.s3#Prefix" + } + }, + "traits": { + "s3s#minio": "" + } + }, + "com.amazonaws.s3#ExcludedPrefixes": { + "type": "list", + "member": { + "target": "com.amazonaws.s3#ExcludedPrefix" + } + }, + "com.amazonaws.s3#VersioningConfiguration": { + "type": "structure", + "members": { + "ExcludedPrefixes": { + "target": "com.amazonaws.s3#ExcludedPrefixes", + "traits": { + "s3s#minio": "", + "smithy.api#xmlFlattened": "", + "smithy.api#xmlName": "ExcludedPrefixes" + } + }, + "ExcludeFolders": { + "target": "com.amazonaws.s3#ExcludeFolders", + "traits": { + "s3s#minio": "" + } + } + } + } + } +} \ No newline at end of file