Skip to content

Commit 9709537

Browse files
committed
Expand examples, link from field description.
1 parent 564b2ce commit 9709537

File tree

1 file changed

+145
-12
lines changed

1 file changed

+145
-12
lines changed

src/oas.md

Lines changed: 145 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,7 +3198,7 @@ When using a Schema Object with XML, if no XML Object is present, the behavior i
31983198
| <a name="xml-wrapped"></a>wrapped | `boolean` | MAY be used only for an array definition. Signifies whether the array is wrapped (for example, `<books><book/><book/></books>`) or unwrapped (`<book/><book/>`). Default value is `false`. The definition takes effect only when defined alongside `type` being `"array"` (outside the `items`). If `nodeType` is present, this field MUST NOT be present.<br /><br />**Deprecated:** Set `nodeType: "element"` explicitly in place of `wrapped: true` |
31993199

32003200
Note that when generating an XML document from object data, the order of the nodes is undefined.
3201-
Use `prefixItems` to control node ordering.
3201+
Use `prefixItems` to control node ordering as shown under [Ordered Elements and Text](#ordered-elements-and-text).
32023202

32033203
See [Appendix B](#appendix-b-data-type-conversion) for a discussion of converting values of various types to string representations.
32043204

@@ -3509,35 +3509,168 @@ components:
35093509
</Documentation>
35103510
```
35113511

3512-
###### Element With Text Before and After a Child Element
3512+
Alternatively, the named root element could be set at the point of use and the root element disabled on the component:
35133513

3514-
In this example, `prefixItems` is used to control the ordering.
3515-
Since `prefixItems` works with arrays, we need to explicitly set the `nodeType` to `element`.
3516-
Within `prefixItems`, we need to explicitly set the `nodeType` of the `text` nodes, but do not need a name, while the data node's default `nodeType` of `element` is correct, but it needs an explicit `name`:
3514+
```yaml
3515+
paths:
3516+
/docs:
3517+
get:
3518+
responses:
3519+
"200":
3520+
content:
3521+
application/xml:
3522+
xml:
3523+
nodeType: element
3524+
name: StoredDocument
3525+
$ref: "#/components/schemas/Documentation"
3526+
put:
3527+
requestBody:
3528+
required: true
3529+
content:
3530+
application/xml:
3531+
xml:
3532+
nodeType: element
3533+
name: UpdatedDocument
3534+
$ref: "#/components/schemas/Documentation"
3535+
responses:
3536+
"201": {}
3537+
components:
3538+
schemas:
3539+
Documentation:
3540+
xml:
3541+
nodeType: none
3542+
type: object
3543+
properties:
3544+
content:
3545+
type: string
3546+
contentMediaType: text/html
3547+
xml:
3548+
nodeType: cdata
3549+
```
3550+
3551+
The GET response XML:
3552+
3553+
```xml
3554+
<StoredDocument>
3555+
<![CDATA[<html><head><title>Awesome Docs</title></head><body></body><html>]]>
3556+
</StoredDocument>
3557+
```
3558+
3559+
The PUT request XML:
3560+
3561+
```xml
3562+
<UpdatedDocument>
3563+
<![CDATA[<html><head><title>Awesome Docs</title></head><body></body><html>]]>
3564+
</UpdatedDocument>
3565+
```
3566+
3567+
The in-memory instance data for all three of the above XML documents:
3568+
3569+
```json
3570+
{
3571+
"content": "<html><head><title>Awesome Docs</title></head><body></body><html>"
3572+
}
3573+
```
3574+
3575+
###### Ordered Elements and Text
3576+
3577+
To control the exact order of elements, use the `prefixItems` keyword.
3578+
With this approach, it is necessary to set the element names using the XML Object as they would otherwise all inherit the parent's name despite being different elements in a specific order.
3579+
It is also necessary to set `nodeType: "element"` explicitly on the array in order to get an element containing the sequence.
3580+
3581+
This first ordered example shows a sequence of elements, as well as the recommended serialization of `null` for elements:
35173582

35183583
```yaml
35193584
components:
35203585
schemas:
3521-
Report:
3586+
OneTwoThree:
3587+
xml:
3588+
nodeType: element
35223589
type: array
3590+
minLength: 3
3591+
maxLength: 3
3592+
prefixItems:
3593+
- xml:
3594+
name: One
3595+
type: string
3596+
- xml:
3597+
name: Two
3598+
type: object
3599+
required:
3600+
- unit
3601+
- value
3602+
properties:
3603+
unit:
3604+
type: string
3605+
xml:
3606+
nodeType: attribute
3607+
value:
3608+
type: number
3609+
xml:
3610+
nodeType: text
3611+
- xml:
3612+
name: Three
3613+
type:
3614+
- boolean
3615+
- "null"
3616+
```
3617+
3618+
```xml
3619+
<OneTwoThree>
3620+
<One>Some text</One>
3621+
<Two unit="cubits">42</Two>
3622+
<Three xsi:nil="true" />
3623+
</OneTwoThree>
3624+
```
3625+
3626+
The in-memory instance data that would produce the above XML snippet with the preceding schema would be:
3627+
3628+
```json
3629+
[
3630+
"Some Text",
3631+
{
3632+
"unit": "cubits",
3633+
"value": 42
3634+
},
3635+
null
3636+
]
3637+
```
3638+
3639+
In this next example, the `name` needs to be set for the element, while the `nodeType` needs to be set for the text nodes.
3640+
3641+
```yaml
3642+
components:
3643+
schemas:
3644+
Report:
35233645
xml:
35243646
nodeType: element
3647+
type: array
35253648
prefixItems:
3526-
- type: string
3527-
xml:
3649+
- xml:
35283650
nodeType: text
3529-
- type: number
3530-
xml:
3651+
type: string
3652+
- xml:
35313653
name: data
3532-
- type: string
3533-
xml:
3654+
type: number
3655+
- xml:
35343656
nodeType: text
3657+
type: string
35353658
```
35363659

35373660
```xml
35383661
<Report>Some preamble text.<data>42</data>Some postamble text.</Report>
35393662
```
35403663

3664+
The in-memory instance data structure for the above example would be:
3665+
3666+
```json
3667+
[
3668+
"Some preamble text."
3669+
42,
3670+
"Some postamble text."
3671+
]
3672+
```
3673+
35413674
#### Security Scheme Object
35423675

35433676
Defines a security scheme that can be used by the operations.

0 commit comments

Comments
 (0)