petrochenko-pavel-a / raml-js-parser2-issues

0 stars 0 forks source link

Add additional `xml` node for type declarations that allows configuring serialization of type instances to XML #9

Closed VasiliyLysokobylko closed 8 years ago

VasiliyLysokobylko commented 8 years ago

In RC1, the specification does not contain information about the serialization of type instances to XML. As the serialization to XML may be a complex process, RAML 1.0 RC2 introduces an additional xml node for type declarations that allows to configure how type instances should be serialised to XML.

The value of the xml node is a map that contains the following properties:

Name Type Description
attribute? boolean If attribute is set to true, a type instance should be serialized as an XML attribute. It can only be true for scalar types.

Default: false
wrapped? boolean If wrapped is set to true, a type instance should be wrapped in its own XML element. It can not be true for scalar types and it can not be true at the same moment when attribute is true.

Default: false
name? string Allows to override the name of the XML element or XML attribute in it's XML representation.

Default: the name of the type
namespace? string Allows to configure the name of the XML namespace.
prefix? string Allows to configure the prefix which will be used during serialization to XML.

The following is a type declaration example that uses the xml node:

types:
  Person:
    properties:
      name:
        type: string
        xml:
          attribute: true # serialize it as an XML attribute
          name: "fullname" # attribute should be called fullname
      addresses:
        type: Address[]
        xml:
          wrapped: true # serialize it into it's own <addresses>...</addresses> XML element
  Address:
    properties:
      street: string
      city: string

The example above may be serialized into the following XML:

<Person fullname="John Doe">
  <addresses>
     <Address>…</Address>
     ...
  </addresses>
</Person>
VasiliyLysokobylko commented 8 years ago

https://github.com/raml-org/raml-spec/issues/329

petrochenko-pavel-a commented 8 years ago

Supported in the parser and in type system