Skip to content

Commit 042e708

Browse files
committed
Allow Parameter/Header examples w/content
Parameter and Header serialization is complex, particularly when using the `content` field to use a Media Type Object. In such scenarios, the serialization occurs in two steps: The first step is to serialize the data to the media type, which can be captured by the `examples` field of the Media Type Object. The second is the encoding/escaping of the media type document for use in a URI, HTTP header, or other ___location with its own rules. Sometimes the part needing illustration with an example is at one level, sometimes at another, and sometimes it is helpful to show both. For simplicity, the "data" examples are always treated as the overall input data, so they would be the same at both levels. This is also because it is not always possible to show each step, particularly when there are binary serializations. This allows showing either step (or both steps) with both data and serialization, depending on what makes sense for the use case.
1 parent 2c7432c commit 042e708

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/oas.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,8 @@ See [Appendix B](#appendix-b-data-type-conversion) for a discussion of convertin
968968
###### Common Fixed Fields
969969

970970
These fields MAY be used with either `content` or `schema`.
971+
When `example` or `examples` are provided in conjunction with the `schema` field, the example SHOULD match the specified schema and follow the prescribed serialization strategy for the parameter.
972+
The `example` and `examples` fields are mutually exclusive.
971973

972974
| Field Name | Type | Description |
973975
| ---- | :----: | ---- |
@@ -977,6 +979,8 @@ These fields MAY be used with either `content` or `schema`.
977979
| <a name="parameter-required"></a>required | `boolean` | Determines whether this parameter is mandatory. If the [parameter ___location](#parameter-in) is `"path"`, this field is **REQUIRED** and its value MUST be `true`. Otherwise, the field MAY be included and its default value is `false`. |
978980
| <a name="parameter-deprecated"></a> deprecated | `boolean` | Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is `false`. |
979981
| <a name="parameter-allow-empty-value"></a> allowEmptyValue | `boolean` | If `true`, clients MAY pass a zero-length string value in place of parameters that would otherwise be omitted entirely, which the server SHOULD interpret as the parameter being unused. Default value is `false`. If [`style`](#parameter-style) is used, and if [behavior is _n/a_ (cannot be serialized)](#style-examples), the value of `allowEmptyValue` SHALL be ignored. Interactions between this field and the parameter's [Schema Object](#schema-object) are implementation-defined. This field is valid only for `query` parameters. <br><br>**Deprecated:** Use of this field is NOT RECOMMENDED, and it is likely to be removed in a later revision. |
982+
| <a name="parameter-example"></a>example | Any | Example of the parameter's potential value; see [Working With Examples](#working-with-examples). |
983+
| <a name="parameter-examples"></a>examples | Map[ `string`, [Example Object](#example-object) \| [Reference Object](#reference-object)] | Examples of the parameter's potential value; see [Working With Examples](#working-with-examples). |
980984

981985
This object MAY be extended with [Specification Extensions](#specification-extensions).
982986

@@ -985,8 +989,6 @@ Note that while `"Cookie"` as a `name` is not forbidden if `in` is `"header"`, t
985989
###### Fixed Fields for use with `schema`
986990

987991
For simpler scenarios, a [`schema`](#parameter-schema) and [`style`](#parameter-style) can describe the structure and syntax of the parameter.
988-
When `example` or `examples` are provided in conjunction with the `schema` field, the example SHOULD match the specified schema and follow the prescribed serialization strategy for the parameter.
989-
The `example` and `examples` fields are mutually exclusive.
990992

991993
These fields MUST NOT be used with `in: "querystring"`.
992994
@@ -998,8 +1000,6 @@ Serializing with `schema` is NOT RECOMMENDED for `in: "cookie"` parameters, `in:
9981000
| <a name="parameter-explode"></a>explode | `boolean` | When this is true, parameter values of type `array` or `object` generate separate parameters for each value of the array or key-value pair of the map. For other types of parameters this field has no effect. When [`style`](#parameter-style) is `"form"`, the default value is `true`. For all other styles, the default value is `false`. Note that despite `false` being the default for `deepObject`, the combination of `false` with `deepObject` is undefined. |
9991001
| <a name="parameter-allow-reserved"></a>allowReserved | `boolean` | When this is true, parameter values are serialized using reserved expansion, as defined by [RFC6570](https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.3), which allows [RFC3986's reserved character set](https://datatracker.ietf.org/doc/html/rfc3986#section-2.2), as well as percent-encoded triples, to pass through unchanged, while still percent-encoding all other disallowed characters (including `%` outside of percent-encoded triples). Applications are still responsible for percent-encoding reserved characters that are not allowed by the rules of the `in` destination or media type, or are [not allowed in the path by this specification](#path-templating); see Appendices [C](#appendix-c-using-rfc6570-based-serialization) and [E](#appendix-e-percent-encoding-and-form-media-types) for details. The default value is `false`. |
10001002
| <a name="parameter-schema"></a>schema | [Schema Object](#schema-object) | The schema defining the type used for the parameter. |
1001-
| <a name="parameter-example"></a>example | Any | Example of the parameter's potential value; see [Working With Examples](#working-with-examples). |
1002-
| <a name="parameter-examples"></a>examples | Map[ `string`, [Example Object](#example-object) \| [Reference Object](#reference-object)] | Examples of the parameter's potential value; see [Working With Examples](#working-with-examples). |
10031003

10041004
See also [Appendix C: Using RFC6570-Based Serialization](#appendix-c-using-rfc6570-based-serialization) for additional guidance.
10051005

@@ -2423,11 +2423,16 @@ The Header Object follows the structure of the [Parameter Object](#parameter-obj
24232423

24242424
These fields MAY be used with either `content` or `schema`.
24252425

2426+
When `example` or `examples` are provided in conjunction with the `schema` field, the example SHOULD match the specified schema and follow the prescribed serialization strategy for the header.
2427+
The `example` and `examples` fields are mutually exclusive.
2428+
24262429
| Field Name | Type | Description |
24272430
| ---- | :----: | ---- |
24282431
| <a name="header-description"></a>description | `string` | A brief description of the header. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation. |
24292432
| <a name="header-required"></a>required | `boolean` | Determines whether this header is mandatory. The default value is `false`. |
24302433
| <a name="header-deprecated"></a> deprecated | `boolean` | Specifies that the header is deprecated and SHOULD be transitioned out of usage. Default value is `false`. |
2434+
| <a name="header-example"></a>example | Any | Example of the header's potential value; see [Working With Examples](#working-with-examples). |
2435+
| <a name="header-examples"></a>examples | Map[ `string`, [Example Object](#example-object) \| [Reference Object](#reference-object)] | Examples of the header's potential value; see [Working With Examples](#working-with-examples). |
24312436

24322437
This object MAY be extended with [Specification Extensions](#specification-extensions).
24332438

@@ -2440,9 +2445,6 @@ Serializing headers with `schema` can be problematic due to the URI percent-enco
24402445
The `allowReserved` field can disable most but not all of this behavior.
24412446
See [Appendix D](#appendix-d-serializing-headers-and-cookies) for details and further guidance.
24422447

2443-
When `example` or `examples` are provided in conjunction with the `schema` field, the example SHOULD match the specified schema and follow the prescribed serialization strategy for the header.
2444-
The `example` and `examples` fields are mutually exclusive.
2445-
24462448
| Field Name | Type | Description |
24472449
| ---- | :----: | ---- |
24482450
| <a name="header-style"></a>style | `string` | Describes how the header value will be serialized. The default (and only legal value for headers) is `"simple"`. |

src/schemas/validation/schema.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ $defs:
366366
- required:
367367
- content
368368
allOf:
369+
- $ref: '#/$defs/examples'
370+
- $ref: '#/$defs/specification-extensions'
369371
- if:
370372
properties:
371373
in:
@@ -403,7 +405,6 @@ $defs:
403405
default: false
404406
type: boolean
405407
allOf:
406-
- $ref: '#/$defs/examples'
407408
- $ref: '#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-path'
408409
- $ref: '#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-header'
409410
- $ref: '#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-query'
@@ -474,7 +475,6 @@ $defs:
474475
default: form
475476
const: form
476477

477-
$ref: '#/$defs/specification-extensions'
478478
unevaluatedProperties: false
479479

480480
parameter-or-reference:
@@ -733,6 +733,9 @@ $defs:
733733
type: boolean
734734
$ref: '#/$defs/examples'
735735
$ref: '#/$defs/specification-extensions'
736+
allOf:
737+
- $ref: '#/$defs/examples'
738+
- $ref: '#/$defs/specification-extensions'
736739
unevaluatedProperties: false
737740

738741
header-or-reference:

0 commit comments

Comments
 (0)