Skip to content

Commit

Permalink
Merge pull request #205 from JordonPhillips/flatmaps
Browse files Browse the repository at this point in the history
Allow XML maps to be flattened
  • Loading branch information
JordonPhillips authored Nov 15, 2019
2 parents 0461aed + c558b31 commit f302ec5
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
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

0 comments on commit f302ec5

Please sign in to comment.