diff --git a/docs/source/spec/xml.rst b/docs/source/spec/xml.rst index a79e12ca549..1d035438ddc 100644 --- a/docs/source/spec/xml.rst +++ b/docs/source/spec/xml.rst @@ -98,13 +98,13 @@ Summary Moves serialized collection members from their collection element to that of the collection's container. Trait selector - ``:test(collection, member:of(structure) > collection)`` + ``:test(map, collection, member:of(structure) > :test(map, collection))`` - *Any list or set or any structure member that targets a list or set* + *Any map, list, or set or any structure member that targets a map, list, or set* Value type Annotation trait -Given the following structure definition, +Given the following list definition: .. tabs:: @@ -147,6 +147,62 @@ following document: bar baz +Given the following definition: + +.. tabs:: + + .. code-tab:: smithy + + @xmlFlattened + map MyMap { + key: String + value: String + } + + .. code-tab:: json + + { + "smithy": "0.4.0", + "smithy.example": { + "shapes": { + "MyMap": { + "type": "map", + "key": { + "target": "String" + }, + "value": { + "target": "String" + }, + "xmlFlattened": true, + "xmlName": "MyMapEntry" + } + } + } + } + +and the following values provided for ``MyMap``: + +.. code-block:: json + + { + "foo": "bar", + "bar": "baz" + } + +the XML representation of the value would be serialized with the following +document: + +.. code-block:: xml + + + foo + bar + + + bar + baz + + .. _xmlName-trait: diff --git a/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude-traits.smithy b/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude-traits.smithy index b235a68ddf2..fdaea0088f0 100644 --- a/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude-traits.smithy +++ b/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude-traits.smithy @@ -148,7 +148,7 @@ structure xmlAttribute {} /// Moves serialized collection members from their collection element to that of /// the collection's container. -@trait(selector: ":test(collection, member:of(structure) > collection)") +@trait(selector: ":test(map, collection, member:of(structure) > :test(map, collection))") @tags(["diff.error.const"]) structure xmlFlattened {} diff --git a/smithy-model/src/test/resources/software/amazon/smithy/model/errorfiles/validators/xml-flattened.json b/smithy-model/src/test/resources/software/amazon/smithy/model/errorfiles/validators/xml-flattened.json index 85bb0871548..b70c0d8bd4d 100644 --- a/smithy-model/src/test/resources/software/amazon/smithy/model/errorfiles/validators/xml-flattened.json +++ b/smithy-model/src/test/resources/software/amazon/smithy/model/errorfiles/validators/xml-flattened.json @@ -15,6 +15,25 @@ "target": "smithy.api#String" } }, + "FlatMap": { + "type": "map", + "key": { + "target": "String" + }, + "value": { + "target": "String" + }, + "smithy.api#xmlFlattened": true + }, + "NotFlatMap": { + "type": "map", + "key": { + "target": "String" + }, + "value": { + "target": "String" + } + }, "ValidStructure1": { "type": "structure", "members": { @@ -31,6 +50,15 @@ "smithy.api#xmlFlattened": true } } + }, + "ValidStructure3": { + "type": "structure", + "members": { + "flatmap": { + "target": "NotFlatMap", + "smithy.api#xmlFlattened": true + } + } } } }