diff --git a/codegen-test/model/misc.smithy b/codegen-test/model/misc.smithy index f33306da83..20cd3ea043 100644 --- a/codegen-test/model/misc.smithy +++ b/codegen-test/model/misc.smithy @@ -15,7 +15,8 @@ service MiscService { ], } -/// To not regress on https://github.com/awslabs/smithy-rs/pull/1266 +/// This operation tests that (de)serializing required values from a nested +/// shape works correctly. @http(uri: "/operation", method: "GET") operation OperationWithInnerRequiredShape { input: OperationWithInnerRequiredShapeInput, @@ -26,13 +27,84 @@ structure OperationWithInnerRequiredShapeInput { inner: InnerShape } +structure OperationWithInnerRequiredShapeOutput { + inner: InnerShape +} + structure InnerShape { @required requiredInnerMostShape: InnermostShape } structure InnermostShape { - aString: String + @required + aString: String, + + @required + aBoolean: Boolean, + + @required + aByte: Byte, + + @required + aShort: Short, + + @required + anInt: Integer, + + @required + aLong: Long, + + @required + aFloat: Float, + + @required + aDouble: Double, + + // TODO(https://github.com/awslabs/smithy-rs/issues/312) + // @required + // aBigInteger: BigInteger, + + // @required + // aBigDecimal: BigDecimal, + + @required + aTimestamp: Timestamp, + + @required + aDocument: Timestamp, + + @required + aStringList: AStringList, + + @required + aStringMap: AMap, + + @required + aStringSet: AStringSet, + + @required + aBlob: Blob, + + @required + aUnion: AUnion } -structure OperationWithInnerRequiredShapeOutput { } +list AStringList { + member: String +} + +list AStringSet { + member: String +} + +map AMap { + key: String, + value: Timestamp +} + +union AUnion { + i32: Integer, + string: String, + time: Timestamp, +} diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/JsonSerializerGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/JsonSerializerGenerator.kt index f9174218ce..2272eff87e 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/JsonSerializerGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/serialize/JsonSerializerGenerator.kt @@ -347,26 +347,26 @@ class JsonSerializerGenerator( ) } is BlobShape -> rust( - "$writer.string_unchecked(&#T(${value.name}.as_ref()));", + "$writer.string_unchecked(&#T(${value.asRef()}));", RuntimeType.Base64Encode(runtimeConfig) ) is TimestampShape -> { val timestampFormat = httpBindingResolver.timestampFormat(context.shape, HttpLocation.DOCUMENT, EPOCH_SECONDS) val timestampFormatType = RuntimeType.TimestampFormat(runtimeConfig, timestampFormat) - rust("$writer.date_time(${value.name}, #T)?;", timestampFormatType) + rust("$writer.date_time(${value.asRef()}, #T)?;", timestampFormatType) } is CollectionShape -> jsonArrayWriter(context) { arrayName -> - serializeCollection(Context(arrayName, context.valueExpression, target)) + serializeCollection(Context(arrayName, value, target)) } is MapShape -> jsonObjectWriter(context) { objectName -> - serializeMap(Context(objectName, context.valueExpression, target)) + serializeMap(Context(objectName, value, target)) } is StructureShape -> jsonObjectWriter(context) { objectName -> - serializeStructure(StructContext(objectName, context.valueExpression.name, target)) + serializeStructure(StructContext(objectName, value.asRef(), target)) } is UnionShape -> jsonObjectWriter(context) { objectName -> - serializeUnion(Context(objectName, context.valueExpression, target)) + serializeUnion(Context(objectName, value, target)) } is DocumentShape -> rust("$writer.document(${value.asRef()});") else -> TODO(target.toString())