Skip to content

Commit 5e028a6

Browse files
authored
Merge pull request #4672 from handrews/ex-obj-ex
2 parents 2c7432c + 6faaed3 commit 5e028a6

File tree

1 file changed

+62
-80
lines changed

1 file changed

+62
-80
lines changed

src/oas.md

Lines changed: 62 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,100 +2140,82 @@ With the Example Object, such values can alternatively be handled through the `e
21402140

21412141
##### Example Object Examples
21422142

2143-
In a request body:
2143+
###### JSON Examples
21442144

2145-
```yaml
2146-
requestBody:
2147-
content:
2148-
'application/json':
2149-
schema:
2150-
$ref: '#/components/schemas/Address'
2151-
examples:
2152-
foo:
2153-
summary: A foo example
2154-
value:
2155-
foo: bar
2156-
bar:
2157-
summary: A bar example
2158-
value:
2159-
bar: baz
2160-
application/xml:
2161-
examples:
2162-
xmlExample:
2163-
summary: This is an example in XML
2164-
externalValue: https://example.org/examples/address-example.xml
2165-
text/plain:
2166-
examples:
2167-
textExample:
2168-
summary: This is a text example
2169-
externalValue: https://foo.bar/examples/address-example.txt
2170-
```
2171-
2172-
In a parameter:
2145+
When writing in YAML, JSON syntax can be used for `dataValue` (as shown in the `noRating` example) but is not required.
2146+
While this example shows the behavior of both `dataValue` and `serializedValue` for JSON (in the 'withRating` example), in most cases only the data form is needed.
21732147

21742148
```yaml
2175-
parameters:
2176-
- name: zipCode
2177-
in: query
2149+
content:
2150+
application/json:
21782151
schema:
2179-
type: string
2180-
format: zip-code
2152+
type: object
2153+
required:
2154+
- author
2155+
- title
2156+
properties:
2157+
author:
2158+
type: string
2159+
title:
2160+
type: string
2161+
rating:
2162+
type: number
2163+
minimum: 1
2164+
maximum: 5
2165+
multipleOf: 0.5
21812166
examples:
2182-
zip-example:
2183-
$ref: '#/components/examples/zip-example'
2184-
```
2185-
2186-
In a response:
2167+
noRating:
2168+
summary: A not-yet-rated work
2169+
dataValue: {
2170+
"author": "A. Writer",
2171+
"title": "The Newest Book"
2172+
}
2173+
withRating:
2174+
summary: A work with an average rating of 4.5 stars
2175+
dataValue:
2176+
author: A. Writer
2177+
title: An Older Book
2178+
rating: 4.5
2179+
serializedValue: |
2180+
{
2181+
"author": "A. Writer",
2182+
"title": "An Older Book",
2183+
"rating": 4.5
2184+
}
2185+
```
2186+
2187+
###### Binary Examples
2188+
2189+
Fully binary data is shown using `externalValue`:
21872190

21882191
```yaml
2189-
responses:
2190-
'200':
2191-
description: your car appointment has been booked
2192-
content:
2193-
application/json:
2194-
schema:
2195-
$ref: '#/components/schemas/SuccessResponse'
2196-
examples:
2197-
confirmation-success:
2198-
$ref: '#/components/examples/confirmation-success'
2199-
```
2200-
2201-
Two different uses of JSON strings:
2202-
2203-
First, a request or response body that is just a JSON string (not an object containing a string):
2204-
2205-
```yaml
2206-
application/json:
2207-
schema:
2208-
type: string
2209-
examples:
2210-
jsonBody:
2211-
description: 'A body of just the JSON string "json"'
2212-
value: json
2192+
content:
2193+
image/png:
2194+
schema: {}
2195+
examples:
2196+
Red:
2197+
externalValue: ./examples/2-by-2-red-pixels.png
22132198
```
22142199

2215-
In the above example, we can just show the JSON string (or any JSON value) as-is, rather than stuffing a serialized JSON value into a JSON string, which would have looked like `"\"json\""`.
2200+
###### Boolean Query Parameter Examples
22162201

2217-
In contrast, a JSON string encoded inside of a URL-style form body:
2202+
Since there is no standard for serializing boolean values (as discussed in [Appendix B](#appendix-b-data-type-conversion)), this example uses `dataValue` and `serializedValue` to show how booleans are serialized for this particular parameter:
22182203

22192204
```yaml
2220-
application/x-www-form-urlencoded:
2221-
schema:
2222-
type: object
2223-
properties:
2224-
jsonValue:
2225-
type: string
2226-
encoding:
2227-
jsonValue:
2228-
contentType: application/json
2229-
examples:
2230-
jsonFormValue:
2231-
description: 'The JSON string "json" as a form value'
2232-
value: jsonValue=%22json%22
2205+
name: flag
2206+
in: query
2207+
required: true
2208+
schema:
2209+
type: boolean
2210+
examples:
2211+
"true":
2212+
dataValue: true
2213+
serializedValue: flag=true
2214+
"false":
2215+
dataValue: false
2216+
serializedValue: flag=false
22332217
```
22342218

2235-
In this example, the JSON string had to be serialized before encoding it into the URL form value, so the example includes the quotation marks that are part of the JSON serialization, which are then URL percent-encoded.
2236-
22372219
#### Link Object
22382220

22392221
The Link Object represents a possible design-time link for a response.

0 commit comments

Comments
 (0)