Skip to content

Commit aa48bea

Browse files
committed
Example Object example updates
1 parent c82e017 commit aa48bea

File tree

1 file changed

+63
-80
lines changed

1 file changed

+63
-80
lines changed

src/oas.md

Lines changed: 63 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,100 +2128,83 @@ With the Example Object, such values can alternatively be handled through the `e
21282128

21292129
##### Example Object Examples
21302130

2131-
In a request body:
2131+
###### JSON Examples
21322132

2133-
```yaml
2134-
requestBody:
2135-
content:
2136-
'application/json':
2137-
schema:
2138-
$ref: '#/components/schemas/Address'
2139-
examples:
2140-
foo:
2141-
summary: A foo example
2142-
value:
2143-
foo: bar
2144-
bar:
2145-
summary: A bar example
2146-
value:
2147-
bar: baz
2148-
application/xml:
2149-
examples:
2150-
xmlExample:
2151-
summary: This is an example in XML
2152-
externalValue: https://example.org/examples/address-example.xml
2153-
text/plain:
2154-
examples:
2155-
textExample:
2156-
summary: This is a text example
2157-
externalValue: https://foo.bar/examples/address-example.txt
2158-
```
2159-
2160-
In a parameter:
2133+
When writing in YAML, JSON syntax can be used for `dataValue` (as shown in the `noRating` example) but is not required.
2134+
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.
21612135

21622136
```yaml
2163-
parameters:
2164-
- name: zipCode
2165-
in: query
2137+
content:
2138+
application/json:
21662139
schema:
2167-
type: string
2168-
format: zip-code
2140+
type: object
2141+
required:
2142+
- author
2143+
- title
2144+
properties:
2145+
author:
2146+
type: string
2147+
title:
2148+
type: string
2149+
rating:
2150+
type: number
2151+
minimum: 1
2152+
maximum: 5
2153+
multipleOf: 0.5
21692154
examples:
2170-
zip-example:
2171-
$ref: '#/components/examples/zip-example'
2172-
```
2173-
2174-
In a response:
2155+
noRating:
2156+
summary: A not-yet-rated work
2157+
dataValue: {
2158+
"author": "A. Writer",
2159+
"title": "The Newest Book"
2160+
}
2161+
withRating:
2162+
summary: A work with an average rating of 4.5 stars
2163+
dataValue:
2164+
author: A. Writer
2165+
title: An Older Book
2166+
rating: 4.5
2167+
serializedValue: |
2168+
{
2169+
"author": "A. Writer",
2170+
"title": "An Older Book",
2171+
"rating": 4.5
2172+
}
2173+
```
2174+
2175+
###### Binary Examples
2176+
2177+
This example shows both `externalDataValue` and `externalSerializedValue` to emphasize that no encoding is taking place, but it is also valid to show only one or the other.
21752178

21762179
```yaml
2177-
responses:
2178-
'200':
2179-
description: your car appointment has been booked
2180-
content:
2181-
application/json:
2182-
schema:
2183-
$ref: '#/components/schemas/SuccessResponse'
2184-
examples:
2185-
confirmation-success:
2186-
$ref: '#/components/examples/confirmation-success'
2187-
```
2188-
2189-
Two different uses of JSON strings:
2190-
2191-
First, a request or response body that is just a JSON string (not an object containing a string):
2192-
2193-
```yaml
2194-
application/json:
2195-
schema:
2196-
type: string
2197-
examples:
2198-
jsonBody:
2199-
description: 'A body of just the JSON string "json"'
2200-
value: json
2180+
content:
2181+
image/png:
2182+
schema: {}
2183+
examples:
2184+
Red:
2185+
externalDataValue: ./examples/2-by-2-red-pixels.png
2186+
serializedDataValue: ./examples/2-by-2-red-pixels.png
22012187
```
22022188

2203-
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\""`.
2189+
###### Boolean Query Parameter Examples
22042190

2205-
In contrast, a JSON string encoded inside of a URL-style form body:
2191+
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:
22062192

22072193
```yaml
2208-
application/x-www-form-urlencoded:
2209-
schema:
2210-
type: object
2211-
properties:
2212-
jsonValue:
2213-
type: string
2214-
encoding:
2215-
jsonValue:
2216-
contentType: application/json
2217-
examples:
2218-
jsonFormValue:
2219-
description: 'The JSON string "json" as a form value'
2220-
value: jsonValue=%22json%22
2194+
name: flag
2195+
in: query
2196+
required: true
2197+
schema:
2198+
type: boolean
2199+
examples:
2200+
"true":
2201+
dataValue: true
2202+
serializedValue: flag=true
2203+
"false":
2204+
dataValue: false
2205+
serializedValue: flag=false
22212206
```
22222207

2223-
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.
2224-
22252208
#### Link Object
22262209

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

0 commit comments

Comments
 (0)