Unverified Commit 8215aaf1 authored by Nugine's avatar Nugine Committed by GitHub
Browse files

fix(codegen): optional object attributes (#346)

parent 37b39eae
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -103,9 +103,6 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) {
                    let field_ty = &rust_types[field.type_.as_str()];

                    let needs_unwrap = 'unwrap: {
                        if field.type_ == "OptionalObjectAttributesList" {
                            break 'unwrap true;
                        }
                        if is_op_input(&ty.name, ops) && field.option_type.not() && field.is_required {
                            break 'unwrap true;
                        }
+0 −3
Original line number Diff line number Diff line
@@ -152,9 +152,6 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes
                            break 'optional true;
                        }
                        if is_op_input && is_required.not() {
                            if field_type.ends_with("List") {
                                break 'optional false;
                            }
                            break 'optional true;
                        }
                        is_required.not() && default_value.is_none()
+12 −7
Original line number Diff line number Diff line
@@ -425,13 +425,18 @@ fn codegen_op_http_de(op: &Operation, rust_types: &RustTypes) {
                            let field_type = &rust_types[&field.type_];

                            if let rust::Type::List(_) = field_type {
                                assert!(field.name == "object_attributes" || field.name == "optional_object_attributes");
                                if field.is_required {
                                    assert!(field.option_type.not());
                                    g!("let {}: {} = http::parse_list_header(req, &{header})?;", field.name, field.type_,);
                                } else {
                                    assert!(field.option_type);
                                    g!(
                                    "let {}: {} = http::parse_list_header(req, &{header}, {})?;",
                                        "let {}: Option<{}> = http::parse_opt_list_header(req, &{header})?;",
                                        field.name,
                                        field.type_,
                                    field.is_required
                                    );
                                }
                            } else if let rust::Type::Timestamp(ts_ty) = field_type {
                                assert!(field.option_type);
                                let fmt = ts_ty.format.as_deref().unwrap_or("HttpDate");
+6 −6
Original line number Diff line number Diff line
@@ -4945,7 +4945,7 @@ impl AwsConversion for s3s::dto::ListObjectVersionsInput {
            expected_bucket_owner: try_from_aws(x.expected_bucket_owner)?,
            key_marker: try_from_aws(x.key_marker)?,
            max_keys: try_from_aws(x.max_keys)?,
            optional_object_attributes: unwrap_from_aws(x.optional_object_attributes, "optional_object_attributes")?,
            optional_object_attributes: try_from_aws(x.optional_object_attributes)?,
            prefix: try_from_aws(x.prefix)?,
            request_payer: try_from_aws(x.request_payer)?,
            version_id_marker: try_from_aws(x.version_id_marker)?,
@@ -4960,7 +4960,7 @@ impl AwsConversion for s3s::dto::ListObjectVersionsInput {
        y = y.set_expected_bucket_owner(try_into_aws(x.expected_bucket_owner)?);
        y = y.set_key_marker(try_into_aws(x.key_marker)?);
        y = y.set_max_keys(try_into_aws(x.max_keys)?);
        y = y.set_optional_object_attributes(Some(try_into_aws(x.optional_object_attributes)?));
        y = y.set_optional_object_attributes(try_into_aws(x.optional_object_attributes)?);
        y = y.set_prefix(try_into_aws(x.prefix)?);
        y = y.set_request_payer(try_into_aws(x.request_payer)?);
        y = y.set_version_id_marker(try_into_aws(x.version_id_marker)?);
@@ -5023,7 +5023,7 @@ impl AwsConversion for s3s::dto::ListObjectsInput {
            expected_bucket_owner: try_from_aws(x.expected_bucket_owner)?,
            marker: try_from_aws(x.marker)?,
            max_keys: try_from_aws(x.max_keys)?,
            optional_object_attributes: unwrap_from_aws(x.optional_object_attributes, "optional_object_attributes")?,
            optional_object_attributes: try_from_aws(x.optional_object_attributes)?,
            prefix: try_from_aws(x.prefix)?,
            request_payer: try_from_aws(x.request_payer)?,
        })
@@ -5037,7 +5037,7 @@ impl AwsConversion for s3s::dto::ListObjectsInput {
        y = y.set_expected_bucket_owner(try_into_aws(x.expected_bucket_owner)?);
        y = y.set_marker(try_into_aws(x.marker)?);
        y = y.set_max_keys(try_into_aws(x.max_keys)?);
        y = y.set_optional_object_attributes(Some(try_into_aws(x.optional_object_attributes)?));
        y = y.set_optional_object_attributes(try_into_aws(x.optional_object_attributes)?);
        y = y.set_prefix(try_into_aws(x.prefix)?);
        y = y.set_request_payer(try_into_aws(x.request_payer)?);
        y.build().map_err(S3Error::internal_error)
@@ -5094,7 +5094,7 @@ impl AwsConversion for s3s::dto::ListObjectsV2Input {
            expected_bucket_owner: try_from_aws(x.expected_bucket_owner)?,
            fetch_owner: try_from_aws(x.fetch_owner)?,
            max_keys: try_from_aws(x.max_keys)?,
            optional_object_attributes: unwrap_from_aws(x.optional_object_attributes, "optional_object_attributes")?,
            optional_object_attributes: try_from_aws(x.optional_object_attributes)?,
            prefix: try_from_aws(x.prefix)?,
            request_payer: try_from_aws(x.request_payer)?,
            start_after: try_from_aws(x.start_after)?,
@@ -5110,7 +5110,7 @@ impl AwsConversion for s3s::dto::ListObjectsV2Input {
        y = y.set_expected_bucket_owner(try_into_aws(x.expected_bucket_owner)?);
        y = y.set_fetch_owner(try_into_aws(x.fetch_owner)?);
        y = y.set_max_keys(try_into_aws(x.max_keys)?);
        y = y.set_optional_object_attributes(Some(try_into_aws(x.optional_object_attributes)?));
        y = y.set_optional_object_attributes(try_into_aws(x.optional_object_attributes)?);
        y = y.set_prefix(try_into_aws(x.prefix)?);
        y = y.set_request_payer(try_into_aws(x.request_payer)?);
        y = y.set_start_after(try_into_aws(x.start_after)?);
+6 −6
Original line number Diff line number Diff line
@@ -4949,7 +4949,7 @@ impl AwsConversion for s3s::dto::ListObjectVersionsInput {
            expected_bucket_owner: try_from_aws(x.expected_bucket_owner)?,
            key_marker: try_from_aws(x.key_marker)?,
            max_keys: try_from_aws(x.max_keys)?,
            optional_object_attributes: unwrap_from_aws(x.optional_object_attributes, "optional_object_attributes")?,
            optional_object_attributes: try_from_aws(x.optional_object_attributes)?,
            prefix: try_from_aws(x.prefix)?,
            request_payer: try_from_aws(x.request_payer)?,
            version_id_marker: try_from_aws(x.version_id_marker)?,
@@ -4964,7 +4964,7 @@ impl AwsConversion for s3s::dto::ListObjectVersionsInput {
        y = y.set_expected_bucket_owner(try_into_aws(x.expected_bucket_owner)?);
        y = y.set_key_marker(try_into_aws(x.key_marker)?);
        y = y.set_max_keys(try_into_aws(x.max_keys)?);
        y = y.set_optional_object_attributes(Some(try_into_aws(x.optional_object_attributes)?));
        y = y.set_optional_object_attributes(try_into_aws(x.optional_object_attributes)?);
        y = y.set_prefix(try_into_aws(x.prefix)?);
        y = y.set_request_payer(try_into_aws(x.request_payer)?);
        y = y.set_version_id_marker(try_into_aws(x.version_id_marker)?);
@@ -5027,7 +5027,7 @@ impl AwsConversion for s3s::dto::ListObjectsInput {
            expected_bucket_owner: try_from_aws(x.expected_bucket_owner)?,
            marker: try_from_aws(x.marker)?,
            max_keys: try_from_aws(x.max_keys)?,
            optional_object_attributes: unwrap_from_aws(x.optional_object_attributes, "optional_object_attributes")?,
            optional_object_attributes: try_from_aws(x.optional_object_attributes)?,
            prefix: try_from_aws(x.prefix)?,
            request_payer: try_from_aws(x.request_payer)?,
        })
@@ -5041,7 +5041,7 @@ impl AwsConversion for s3s::dto::ListObjectsInput {
        y = y.set_expected_bucket_owner(try_into_aws(x.expected_bucket_owner)?);
        y = y.set_marker(try_into_aws(x.marker)?);
        y = y.set_max_keys(try_into_aws(x.max_keys)?);
        y = y.set_optional_object_attributes(Some(try_into_aws(x.optional_object_attributes)?));
        y = y.set_optional_object_attributes(try_into_aws(x.optional_object_attributes)?);
        y = y.set_prefix(try_into_aws(x.prefix)?);
        y = y.set_request_payer(try_into_aws(x.request_payer)?);
        y.build().map_err(S3Error::internal_error)
@@ -5098,7 +5098,7 @@ impl AwsConversion for s3s::dto::ListObjectsV2Input {
            expected_bucket_owner: try_from_aws(x.expected_bucket_owner)?,
            fetch_owner: try_from_aws(x.fetch_owner)?,
            max_keys: try_from_aws(x.max_keys)?,
            optional_object_attributes: unwrap_from_aws(x.optional_object_attributes, "optional_object_attributes")?,
            optional_object_attributes: try_from_aws(x.optional_object_attributes)?,
            prefix: try_from_aws(x.prefix)?,
            request_payer: try_from_aws(x.request_payer)?,
            start_after: try_from_aws(x.start_after)?,
@@ -5114,7 +5114,7 @@ impl AwsConversion for s3s::dto::ListObjectsV2Input {
        y = y.set_expected_bucket_owner(try_into_aws(x.expected_bucket_owner)?);
        y = y.set_fetch_owner(try_into_aws(x.fetch_owner)?);
        y = y.set_max_keys(try_into_aws(x.max_keys)?);
        y = y.set_optional_object_attributes(Some(try_into_aws(x.optional_object_attributes)?));
        y = y.set_optional_object_attributes(try_into_aws(x.optional_object_attributes)?);
        y = y.set_prefix(try_into_aws(x.prefix)?);
        y = y.set_request_payer(try_into_aws(x.request_payer)?);
        y = y.set_start_after(try_into_aws(x.start_after)?);
Loading