Skip to content

Commit 1cbf196

Browse files
handrewsfehguy
andcommitted
Merge pull request OAI#636 from OAI/issue-544
Add examples object [Manually ported merge] Co-authored-by: Tony Tam <tony@eatbacon.org>
2 parents 8920126 + 0810ef1 commit 1cbf196

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Diff for: dev/oas.md

+49
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,55 @@ name: pet
11631163
description: Pets operations
11641164
```
11651165

1166+
#### <a name="examplesObject"></a>Examples Object
1167+
1168+
Anywhere an `example` may be given, allow a $ref object. This does mean that `example`, structurally, can be either a string primitive or an object, like `additionalProperties`.
1169+
1170+
In locations where the field being provided an `example` is a scalar value _or_ has it's content-type definition determined by a higher-level construct (a response payload, for example, uses the `produces` attribute to select the correct message format), the plural `examples` shall be used, and the payload format be specified as a key to the example.
1171+
1172+
In all cases, the payload is expected to be compatible with the type schema for the value that it is accompanying. Tooling vendors may choose to valide compatibility automatically, and reject the example value(s) if they are not compatible.
1173+
1174+
```yaml
1175+
# in a model
1176+
definitions:
1177+
properties:
1178+
name:
1179+
type: string
1180+
example:
1181+
$ref: http://foo.bar#/examples/name-example
1182+
1183+
# in a parameter, note the plural `examples` as the content-type is set by `consumes`:
1184+
parameters:
1185+
- name: address
1186+
in: body
1187+
schema:
1188+
$ref: '#/definitions/Address'
1189+
examples:
1190+
'application/json':
1191+
$ref: 'http://foo.bar#/examples/address-example.json'
1192+
'application/xml':
1193+
$ref: 'http://foo.bar#/examples/address-example.xml'
1194+
'text/plain':
1195+
$ref: 'http://foo.bar#/examples/address-example.txt'
1196+
default:
1197+
$ref: 'http://foo.bar#/examples/address-example.whatever'
1198+
- name: 'zip'
1199+
in: 'query'
1200+
type: 'string'
1201+
format: 'zip'
1202+
example:
1203+
$ref: 'http://foo.bar#/examples/zip-example'
1204+
# in a response, note the plural `examples`:
1205+
responses:
1206+
200:
1207+
description: your car appointment has been booked
1208+
schema:
1209+
$ref: '#/definitions/SuccessResponse'
1210+
examples:
1211+
'application/json':
1212+
$ref: http://foo.bar#/examples/address-example.json
1213+
```
1214+
11661215
#### <a name="referenceObject"></a>Reference Object
11671216
11681217
A simple object to allow referencing other definitions in the specification. It can be used to reference parameters and responses that are defined at the top level for reuse.

0 commit comments

Comments
 (0)