Commit f8f28ea9 authored by Nugine's avatar Nugine
Browse files

codegen: patch PartNumberMarker

parent 321c12b9
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -95,6 +95,11 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) {
                        continue;
                    }

                    if field.type_ == "PartNumberMarker" || field.type_ == "NextPartNumberMarker" {
                        g!("{s3s_field_name}: x.{aws_field_name}.as_deref().map(integer_from_string).transpose()?,");
                        continue;
                    }

                    let field_ty = &rust_types[field.type_.as_str()];

                    let needs_unwrap = 'unwrap: {
@@ -187,6 +192,11 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) {
                        s => s,
                    };

                    if field.type_ == "PartNumberMarker" || field.type_ == "NextPartNumberMarker" {
                        g!("y = y.set_{aws_field_name}(x.{s3s_field_name}.map(string_from_integer));");
                        continue;
                    }

                    if field.option_type {
                        g!("y = y.set_{aws_field_name}(try_into_aws(x.{s3s_field_name})?);");
                    } else {
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) {
        "use super::*;",
        "",
        "use crate::conv::{try_from_aws, try_into_aws};",
        "use crate::conv::string_from_integer;",
        "",
        "use s3s::S3;",
        "use s3s::{S3Request, S3Response};",
@@ -81,6 +82,11 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) {
                //     continue;
                // }

                if field.type_ == "PartNumberMarker" || field.type_ == "NextPartNumberMarker" {
                    g!("b = b.set_{aws_field_name}(input.{s3s_field_name}.map(string_from_integer));");
                    continue;
                }

                if field.option_type {
                    g!("b = b.set_{aws_field_name}(try_into_aws(input.{s3s_field_name})?);");
                } else {
+12 −0
Original line number Diff line number Diff line
@@ -252,6 +252,18 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes
}

fn patch_types(space: &mut RustTypes) {
    // patch PartNumberMarker
    // FIXME: https://github.com/awslabs/aws-sdk-rust/issues/1318
    {
        let Some(rust::Type::Alias(ty)) = space.get_mut("PartNumberMarker") else { panic!() };
        assert_eq!(ty.type_, "String");
        "i32".clone_into(&mut ty.type_);

        let Some(rust::Type::Alias(ty)) = space.get_mut("NextPartNumberMarker") else { panic!() };
        assert_eq!(ty.type_, "String");
        "i32".clone_into(&mut ty.type_);
    }

    // patch Tag
    {
        let Some(rust::Type::Struct(ty)) = space.get_mut("Tag") else { panic!() };
+12 −12
Original line number Diff line number Diff line
@@ -3309,7 +3309,7 @@ impl AwsConversion for s3s::dto::GetObjectAttributesInput {
            key: unwrap_from_aws(x.key, "key")?,
            max_parts: try_from_aws(x.max_parts)?,
            object_attributes: unwrap_from_aws(x.object_attributes, "object_attributes")?,
            part_number_marker: try_from_aws(x.part_number_marker)?,
            part_number_marker: x.part_number_marker.as_deref().map(integer_from_string).transpose()?,
            request_payer: try_from_aws(x.request_payer)?,
            sse_customer_algorithm: try_from_aws(x.sse_customer_algorithm)?,
            sse_customer_key: try_from_aws(x.sse_customer_key)?,
@@ -3325,7 +3325,7 @@ impl AwsConversion for s3s::dto::GetObjectAttributesInput {
        y = y.set_key(Some(try_into_aws(x.key)?));
        y = y.set_max_parts(try_into_aws(x.max_parts)?);
        y = y.set_object_attributes(Some(try_into_aws(x.object_attributes)?));
        y = y.set_part_number_marker(try_into_aws(x.part_number_marker)?);
        y = y.set_part_number_marker(x.part_number_marker.map(string_from_integer));
        y = y.set_request_payer(try_into_aws(x.request_payer)?);
        y = y.set_sse_customer_algorithm(try_into_aws(x.sse_customer_algorithm)?);
        y = y.set_sse_customer_key(try_into_aws(x.sse_customer_key)?);
@@ -3376,8 +3376,8 @@ impl AwsConversion for s3s::dto::GetObjectAttributesParts {
        Ok(Self {
            is_truncated: try_from_aws(x.is_truncated)?,
            max_parts: try_from_aws(x.max_parts)?,
            next_part_number_marker: try_from_aws(x.next_part_number_marker)?,
            part_number_marker: try_from_aws(x.part_number_marker)?,
            next_part_number_marker: x.next_part_number_marker.as_deref().map(integer_from_string).transpose()?,
            part_number_marker: x.part_number_marker.as_deref().map(integer_from_string).transpose()?,
            parts: try_from_aws(x.parts)?,
            total_parts_count: try_from_aws(x.total_parts_count)?,
        })
@@ -3387,8 +3387,8 @@ impl AwsConversion for s3s::dto::GetObjectAttributesParts {
        let mut y = Self::Target::builder();
        y = y.set_is_truncated(try_into_aws(x.is_truncated)?);
        y = y.set_max_parts(try_into_aws(x.max_parts)?);
        y = y.set_next_part_number_marker(try_into_aws(x.next_part_number_marker)?);
        y = y.set_part_number_marker(try_into_aws(x.part_number_marker)?);
        y = y.set_next_part_number_marker(x.next_part_number_marker.map(string_from_integer));
        y = y.set_part_number_marker(x.part_number_marker.map(string_from_integer));
        y = y.set_parts(try_into_aws(x.parts)?);
        y = y.set_total_parts_count(try_into_aws(x.total_parts_count)?);
        Ok(y.build())
@@ -5169,7 +5169,7 @@ impl AwsConversion for s3s::dto::ListPartsInput {
            expected_bucket_owner: try_from_aws(x.expected_bucket_owner)?,
            key: unwrap_from_aws(x.key, "key")?,
            max_parts: try_from_aws(x.max_parts)?,
            part_number_marker: try_from_aws(x.part_number_marker)?,
            part_number_marker: x.part_number_marker.as_deref().map(integer_from_string).transpose()?,
            request_payer: try_from_aws(x.request_payer)?,
            sse_customer_algorithm: try_from_aws(x.sse_customer_algorithm)?,
            sse_customer_key: try_from_aws(x.sse_customer_key)?,
@@ -5184,7 +5184,7 @@ impl AwsConversion for s3s::dto::ListPartsInput {
        y = y.set_expected_bucket_owner(try_into_aws(x.expected_bucket_owner)?);
        y = y.set_key(Some(try_into_aws(x.key)?));
        y = y.set_max_parts(try_into_aws(x.max_parts)?);
        y = y.set_part_number_marker(try_into_aws(x.part_number_marker)?);
        y = y.set_part_number_marker(x.part_number_marker.map(string_from_integer));
        y = y.set_request_payer(try_into_aws(x.request_payer)?);
        y = y.set_sse_customer_algorithm(try_into_aws(x.sse_customer_algorithm)?);
        y = y.set_sse_customer_key(try_into_aws(x.sse_customer_key)?);
@@ -5209,9 +5209,9 @@ impl AwsConversion for s3s::dto::ListPartsOutput {
            is_truncated: try_from_aws(x.is_truncated)?,
            key: try_from_aws(x.key)?,
            max_parts: try_from_aws(x.max_parts)?,
            next_part_number_marker: try_from_aws(x.next_part_number_marker)?,
            next_part_number_marker: x.next_part_number_marker.as_deref().map(integer_from_string).transpose()?,
            owner: try_from_aws(x.owner)?,
            part_number_marker: try_from_aws(x.part_number_marker)?,
            part_number_marker: x.part_number_marker.as_deref().map(integer_from_string).transpose()?,
            parts: try_from_aws(x.parts)?,
            request_charged: try_from_aws(x.request_charged)?,
            storage_class: try_from_aws(x.storage_class)?,
@@ -5230,9 +5230,9 @@ impl AwsConversion for s3s::dto::ListPartsOutput {
        y = y.set_is_truncated(try_into_aws(x.is_truncated)?);
        y = y.set_key(try_into_aws(x.key)?);
        y = y.set_max_parts(try_into_aws(x.max_parts)?);
        y = y.set_next_part_number_marker(try_into_aws(x.next_part_number_marker)?);
        y = y.set_next_part_number_marker(x.next_part_number_marker.map(string_from_integer));
        y = y.set_owner(try_into_aws(x.owner)?);
        y = y.set_part_number_marker(try_into_aws(x.part_number_marker)?);
        y = y.set_part_number_marker(x.part_number_marker.map(string_from_integer));
        y = y.set_parts(try_into_aws(x.parts)?);
        y = y.set_request_charged(try_into_aws(x.request_charged)?);
        y = y.set_storage_class(try_into_aws(x.storage_class)?);
+9 −0
Original line number Diff line number Diff line
@@ -30,3 +30,12 @@ where
        None => Err(s3_error!(InternalError, "missing field: {}", field_name)),
    }
}

#[must_use]
pub fn string_from_integer(x: i32) -> String {
    x.to_string()
}

pub fn integer_from_string(x: &str) -> S3Result<i32> {
    x.parse::<i32>().map_err(S3Error::internal_error)
}
Loading