Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow XML maps to be flattened #205

Merged
merged 2 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions docs/source/spec/xml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down Expand Up @@ -147,6 +147,62 @@ following document:
<member>bar</member>
<member>baz</member>

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

<MyMapEntry>
<key>foo</key>
<value>bar</value>
</MyMapEntry>
<MyMapEntry>
<key>bar</key>
<value>baz</value>
</MyMapEntry>


.. _xmlName-trait:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -31,6 +50,15 @@
"smithy.api#xmlFlattened": true
}
}
},
"ValidStructure3": {
"type": "structure",
"members": {
"flatmap": {
"target": "NotFlatMap",
"smithy.api#xmlFlattened": true
}
}
}
}
}
Expand Down