Default encoding of scalars
As in Json we have some default handling of the common scalars like utcDateTime
Scalar Type | Default Encoding | Encoding name |
---|
utcDateTime | xs:dateTime | TypeSpec.Xml.Encoding.xmlDateTime |
offsetDateTime | xs:dateTime | TypeSpec.Xml.Encoding.xmlDateTime |
plainDate | xs:date | TypeSpec.Xml.Encoding.xmlDate |
plainTime | xs:time | TypeSpec.Xml.Encoding.xmlTime |
duration | xs:duration | TypeSpec.Xml.Encoding.xmlDuration |
bytes | xs:base64Binary | TypeSpec.Xml.Encoding.xmlBase64Binary |
Examples
1. Array of primitive types
TypeSpec |
Xml |
OpenAPI3 |
@encodedName("application/xml", "XmlPet")
|
|
|
@encodedName("application/xml", "XmlPet") @encodedName("application/xml", "ItemsTags")
|
|
|
@encodedName("application/xml", "ItemsName") scalar tag extends string; @encodedName("application/xml", "XmlPet")
|
<ItemsName>abc</ItemsName> <ItemsName>def</ItemsName>
|
|
@encodedName("application/xml", "ItemsName") scalar tag extends string; @encodedName("application/xml", "XmlPet") @encodedName("application/xml", "ItemsTags")
|
<ItemsName>abc</ItemsName> <ItemsName>def</ItemsName>
|
|
2. Complex array types
TypeSpec |
Xml |
OpenAPI3 |
@encodedName("application/xml", "XmlPet") @encodedName("application/xml", "XmlTag")
|
|
$ref: "#/definitions/Tag"
|
@encodedName("application/xml", "XmlPet") @encodedName("application/xml", "XmlTag")
|
|
$ref: "#/definitions/Tag"
|
@encodedName("application/xml", "XmlPet") @encodedName("application/xml", "ItemsTags") @encodedName("application/xml", "XmlTag")
|
|
$ref: "#/definitions/Tag"
|
@encodedName("application/xml", "XmlPet") @encodedName("application/xml", "ItemsTags") @encodedName("application/xml", "XmlTag")
|
|
$ref: "#/definitions/Tag"
|
3. Nested models
TypeSpec |
Xml |
OpenAPI3 |
|
|
$ref: "#/components/schemas/Author"
|
@encodedName("application/xml", "XmlAuthor")
|
|
- $ref: "#/components/schemas/Author" name: "author" # Here we have to redefine this name otherwise in OpenAPI semantic the `XmlAuthor` name would be used
|
@encodedName("application/xml", "xml-author")
|
|
- $ref: "#/components/schemas/Author"
|
4. Attributes
TypeSpec |
Xml |
OpenAPI3 |
|
<xml-title>string</xml-title>
|
|
TypeSpec |
Xml |
OpenAPI3 |
@Xml.ns("smp", "http://example.com/schema")
|
<smp:Book xmlns:smp="http://example.com/schema">
|
namespace: "http://example.com/schema"
|
@Xml.ns("smp", "http://example.com/schema") @Xml.ns("smp", "http://example.com/schema") @Xml.ns("ns2", "http://example.com/ns2")
|
<smp:Book xmlns:smp="http://example.com/schema" xmlns:sn2="http://example.com/ns2"> <smp:title>string</smp:title> <ns2:author>string</ns2:author>
|
namespace: "http://example.com/schema" namespace: "http://example.com/ns2" namespace: "http://example.com/schema"
|
TypeSpec |
Xml |
OpenAPI3 |
smp: "http://example.com/schema",
|
<smp:Book xmlns:smp="http://example.com/schema">
|
namespace: "http://example.com/schema"
|
smp: "http://example.com/schema", ns2: "http://example.com/ns2",
|
<smp:Book xmlns:smp="http://example.com/schema" xmlns:sn2="http://example.com/ns2"> <smp:title>string</smp:title> <ns2:author>string</ns2:author>
|
namespace: "http://example.com/schema" namespace: "http://example.com/ns2" namespace: "http://example.com/schema"
|
6. Property setting the text of the node
TypeSpec |
Xml |
OpenAPI3 |
@Xml.attribute language: string; @Xml.unwrapped content: string;
|
<BlobName language="abc">
|
x-ms-text: true # on autorest emitter
|