@@ -1128,20 +1128,20 @@ A request body with a referenced model definition.
1128
1128
"schema": {
1129
1129
"$ref": "#/components/schemas/User"
1130
1130
},
1131
- "examples": [ "http://foo.bar/examples/user-example.json" ]
1131
+ "examples": [ "http://foo.bar/other-api.yaml#/components/ examples/user-example.json" ]
1132
1132
},
1133
1133
"application/xml": {
1134
1134
"schema": {
1135
1135
"$ref": "#/components/schemas/User"
1136
1136
},
1137
- "examples": [ "http://foo.bar/examples/user-example.xml" ]
1137
+ "examples": [ "http://foo.bar/other-api.yaml#/components/ examples/user-example.xml" ]
1138
1138
},
1139
1139
"text/plain": {
1140
- "examples": [ "http://foo.bar/examples/user-example.txt" ]
1140
+ "examples": [ "http://foo.bar/other-api.yaml#/components/ examples/user-example.txt" ]
1141
1141
},
1142
1142
"*/*": {
1143
1143
"example": {
1144
- "$ref": "http://foo.bar/examples/user-example.whatever"
1144
+ "$ref": "http://foo.bar/other-api.yaml#/components/ examples/user-example.whatever"
1145
1145
}
1146
1146
}
1147
1147
}
@@ -1155,18 +1155,18 @@ content:
1155
1155
schema:
1156
1156
$ref: '#/components/schemas/User'
1157
1157
examples:
1158
- - 'http://foo.bar/examples/user-example.json'
1158
+ - 'http://foo.bar/other-api.yaml#/components/ examples/user-example.json'
1159
1159
'application/xml':
1160
1160
schema:
1161
1161
$ref: '#/components/schemas/User'
1162
1162
examples:
1163
- - 'http://foo.bar/examples/user-example.xml'
1163
+ - 'http://foo.bar/other-api.yaml#/components/ examples/user-example.xml'
1164
1164
'text/plain':
1165
1165
examples:
1166
- - 'http://foo.bar/examples/user-example.txt'
1166
+ - 'http://foo.bar/other-api.yaml#/components/ examples/user-example.txt'
1167
1167
'*/*':
1168
1168
example:
1169
- $ref: 'http://foo.bar/examples/user-example.whatever'
1169
+ $ref: 'http://foo.bar/other-api.yaml#/components/ examples/user-example.whatever'
1170
1170
` ` `
1171
1171
1172
1172
A body parameter that is an array of string values :
@@ -2355,7 +2355,12 @@ description: Pets operations
2355
2355
2356
2356
# ### <a name="examplesObject"></a>Examples Object
2357
2357
2358
- Anywhere an `example` may be given, a JSON Reference MAY be used, with the
2358
+ Instead of a single `example`, you may provide an array of
2359
+ [Example Object](#exampleObject) values named `examples'.
2360
+ ` example` and `examples` are mutually exclusive.
2361
+
2362
+ Anywhere an `example` may be given (including in the Examples Object array),
2363
+ a JSON Reference MAY be used, with the
2359
2364
explicit restriction that examples having a JSON format with object named
2360
2365
` $ref` are not allowed. This does mean that `example`, structurally, can be
2361
2366
either a string primitive or an object, similar to `additionalProperties`.
@@ -2365,42 +2370,133 @@ for the value that it is accompanying. Tooling implementations MAY choose to
2365
2370
validate compatibility automatically, and reject the example value(s) if they
2366
2371
are not compatible.
2367
2372
2373
+ Here is a single `example` in a model [Schema Object](#schemaObject):
2374
+
2375
+ ` ` ` json
2376
+ "components" : {
2377
+ "schemas" : {
2378
+ "identity" : {
2379
+ "properties" : {
2380
+ "name" : {
2381
+ "type" : "string"
2382
+ }
2383
+ },
2384
+ "example" : {
2385
+ "$ref" : "#/components/examples/identity"
2386
+ }
2387
+ }
2388
+ }
2389
+ ` ` `
2390
+ }
2391
+
2368
2392
` ` ` yaml
2369
- # in a model
2370
- schemas:
2371
- properties:
2372
- name:
2373
- type: string
2393
+ components:
2394
+ schemas:
2395
+ identity:
2396
+ properties:
2397
+ name:
2398
+ type: string
2374
2399
example:
2375
- $ref: http://foo.bar#/examples/name-example
2400
+ $ref: "#/components/examples/identity"
2401
+ ` ` `
2376
2402
2377
- # in a request body, note the plural ` examples` as the Content-Type is set to `*`:
2403
+ Below is an `examples` array in a [Request Body Object](#requestBodyObject),
2404
+ showing two in-line examples and references
2405
+ to examples in the document's [Components Object](#componentsObject):
2406
+
2407
+ ` ` ` json
2408
+ "requestBody" : {
2409
+ "content" : {
2410
+ "application/json" : {
2411
+ "schema" : {
2412
+ "$ref" : "#/components/schemas/Address"
2413
+ },
2414
+ "examples" : [ {
2415
+ "street" : "119 N Weatherly Ave.",
2416
+ "zip" : "55405"
2417
+ }, {
2418
+ "street" : "119 N Weatherly Ave",
2419
+ "street2" : "Apt. D",
2420
+ "city" : "Minneapolis",
2421
+ "state" : "MN",
2422
+ "zip" : "55405",
2423
+ "type" : "residence"
2424
+ }, {
2425
+ "$ref" : "#/components/examples/alt-address"
2426
+ } ]
2427
+ },
2428
+ "application/xml" : {
2429
+ "examples" : [ {
2430
+ "$ref" : "#/components/examples/simple-address.xml"
2431
+ }, {
2432
+ "$ref" : "#/components/examples/complete-address.xml"
2433
+ } ]
2434
+ },
2435
+ "text/plain" : {
2436
+ "examples" : [ {
2437
+ "$ref" : "#/components/examples/address-example.txt"
2438
+ } ]
2439
+ }
2440
+ }
2441
+ }
2442
+ ` ` `
2443
+
2444
+ ` ` ` yaml
2378
2445
requestBody:
2379
2446
content:
2380
2447
'application/json':
2381
2448
schema:
2382
2449
$ref: '#/components/schemas/Address'
2383
2450
examples:
2384
- - {"foo": "bar"}
2385
- - {"bar": "baz"}
2451
+ - { "street": "119 N Weatherly Ave.", "zip" : "55405" }
2452
+ - street: 119 N Weatherly Ave
2453
+ street2: Apt. D
2454
+ city: Minneapolis
2455
+ state: MN
2456
+ zip : '55405'
2457
+ type: residence
2458
+ - $ref: '#/components/examples/alt-address'
2386
2459
'application/xml':
2387
2460
examples:
2388
- - $ref : ' http://foo.bar#/examples/address-example.xml'
2461
+ - $ref: '#/components/examples/simple-address.xml'
2462
+ - $ref: '#/components/examples/complete-address.xml'
2389
2463
'text/plain':
2390
2464
examples:
2391
- - $ref : ' http://foo.bar#/examples/address-example.txt'
2392
-
2393
- # in a parameter
2394
-
2465
+ - $ref: '#/components/examples/address-example.txt'
2466
+ ` ` `
2467
+ This shows referencing an example component from another OpenAPI definition,
2468
+ in a [Parameter Object](#parameterObject):
2469
+ ` ` ` yaml
2395
2470
parameters:
2396
2471
- name: 'zipCode'
2397
2472
in: 'query'
2398
2473
schema:
2399
2474
type: 'string'
2400
2475
format: 'zip-code'
2401
2476
example:
2402
- $ref : ' http://foo.bar#/examples/zip-example'
2403
- # in a response, note the plural `examples`:
2477
+ $ref: 'http://foo.bar/other-api.yaml#/components/examples/zip-example'
2478
+ ` ` `
2479
+
2480
+ Finally, in a [Response Object](#responseObject):
2481
+
2482
+ ` ` ` json
2483
+ "responses" : {
2484
+ "200" : {
2485
+ "description" : "your car appointment has been booked",
2486
+ "content" : {
2487
+ "application/json" : {
2488
+ "schema" : {
2489
+ "$ref" : "#/components/schemas/SuccessResponse"
2490
+ },
2491
+ "example" : {
2492
+ "$ref" : "http://foo.bar/other-api.yaml#/components/examples/address-example.json"
2493
+ }
2494
+ }
2495
+ }
2496
+ }
2497
+ }` ` `
2498
+
2499
+ ` ` ` yaml
2404
2500
responses:
2405
2501
'200':
2406
2502
description: your car appointment has been booked
@@ -2409,7 +2505,7 @@ schemas:
2409
2505
schema:
2410
2506
$ref: '#/components/schemas/SuccessResponse'
2411
2507
example:
2412
- $ref : http://foo.bar# /examples/address-example.json
2508
+ $ref: http://foo.bar/other-api.yaml#/components /examples/address-example.json
2413
2509
` ` `
2414
2510
2415
2511
# ### <a name="referenceObject"></a>Reference Object
0 commit comments