Commit 5c64b476 authored by Nugine's avatar Nugine
Browse files

feat(codegen/minio): VersioningConfiguration

parent 20df9ea0
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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(_) => {}
        }

+4 −0
Original line number Diff line number Diff line
@@ -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 {
+19 −26
Original line number Diff line number Diff line
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()
}

/// <https://github.com/Nugine/s3s/issues/192>
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!(),
            },
    );
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ pub struct Struct {

    pub xml_name: Option<String>,
    pub is_error_type: bool,

    pub is_custom_extension: bool,
}

#[allow(clippy::struct_excessive_bools)]
+0 −5
Original line number Diff line number Diff line
@@ -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()
    }
Loading