Skip to content

Commit b9b1028

Browse files
authored
Merge pull request #5198 from karenetheridge/ether/3.1-parameter-styles-more
v3.1: edits to parameter sections
2 parents b59cb5e + e890239 commit b9b1028

11 files changed

+213
-22
lines changed

src/oas.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,13 +1134,13 @@ See [Appendix E](#appendix-e-percent-encoding-and-form-media-types) for a detail
11341134
There are four possible parameter locations specified by the `in` field:
11351135

11361136
* path - Used together with [Path Templating](#path-templating), where the parameter value is actually part of the operation's URL. This does not include the host or base path of the API. For example, in `/items/{itemId}`, the path parameter is `itemId`.
1137-
* query - Parameters that are appended to the URL. For example, in `/items?id=###`, the query parameter is `id`.
1137+
* query - Parameters that are appended to the URL with the `?` character (or for subsequent query parameters, with the `&` character).
11381138
* header - Custom headers that are expected as part of the request. Note that [RFC7230](https://tools.ietf.org/html/rfc7230#section-3.2) states header names are case insensitive.
11391139
* cookie - Used to pass a specific cookie value to the API.
11401140

11411141
##### Fixed Fields
11421142

1143-
The rules for serialization of the parameter are specified in one of two ways.
1143+
The rules for serialization and deserialization of the parameter are specified in one of two ways.
11441144
Parameter Objects MUST include either a `content` field or a `schema` field, but not both.
11451145
See [Appendix B](#appendix-b-data-type-conversion) for a discussion of converting values of various types to string representations.
11461146

@@ -1177,7 +1177,7 @@ Serializing with `schema` is NOT RECOMMENDED for `in: "cookie"` parameters; see
11771177
| <a name="parameter-style"></a>style | `string` | Describes how the parameter value will be serialized depending on the type of the parameter value. Default values (based on value of `in`): for `"query"` - `"form"`; for `"path"` - `"simple"`; for `"header"` - `"simple"`; for `"cookie"` - `"form"`. |
11781178
| <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. |
11791179
| <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 in the query string](https://datatracker.ietf.org/doc/html/rfc3986#section-3.4) (`[`, `]`, `#`), or have a special meaning in `application/x-www-form-urlencoded` (`-`, `&`, `+`); see [URL Percent-Encoding](#url-percent-encoding) for details. This field only applies to parameters with an `in` value of `query`. The default value is `false`. |
1180-
| <a name="parameter-schema"></a>schema | [Schema Object](#schema-object) | The schema defining the type used for the parameter. |
1180+
| <a name="parameter-schema"></a>schema | [Schema Object](#schema-object) | The schema defining the type and other constraints used for the parameter. |
11811181
| <a name="parameter-example"></a>example | Any | Example of the parameter's potential value; see [Working With Examples](#working-with-examples). |
11821182
| <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). |
11831183

@@ -1277,14 +1277,14 @@ The following table shows serialized examples, as would be shown with the `examp
12771277
| label | true | _empty_ | .blue | .blue.black.brown | .R=100.G=200.B=150 |
12781278
| simple | false | _empty_ | blue | blue,black,brown | R,100,G,200,B,150 |
12791279
| simple | true | _empty_ | blue | blue,black,brown | R=100,G=200,B=150 |
1280-
| form | false | <span style="white-space: nowrap;">color=</span> | <span style="white-space: nowrap;">color=blue</span> | <span style="white-space: nowrap;">color=blue,black,brown</span> | <span style="white-space: nowrap;">color=R,100,G,200,B,150</span> |
1281-
| form | true | <span style="white-space: nowrap;">color=</span> | <span style="white-space: nowrap;">color=blue</span> | <span style="white-space: nowrap;">color=blue&color=black&color=brown</span> | <span style="white-space: nowrap;">R=100&G=200&B=150</span> |
1282-
| spaceDelimited</span> | false | _n/a_ | _n/a_ | <span style="white-space: nowrap;">color=blue%20black%20brown</span> | <span style="white-space: nowrap;">color=R%20100%20G%20200%20B%20150</span> |
1280+
| form | false | color= | color=blue | color=blue,black,brown | color=R,100,G,200,B,150 |
1281+
| form | true | color= | color=blue | color=blue&color=black&color=brown | R=100&G=200&B=150 |
1282+
| spaceDelimited | false | _n/a_ | _n/a_ | color=blue%20black%20brown | color=R%20100%20G%20200%20B%20150 |
12831283
| spaceDelimited | true | _n/a_ | _n/a_ | _n/a_ | _n/a_ |
1284-
| pipeDelimited | false | _n/a_ | _n/a_ | <span style="white-space: nowrap;">color=blue%7Cblack%7Cbrown</span> | <span style="white-space: nowrap;">color=R%7C100%7CG%7C200%7CB%7C150</span> |
1284+
| pipeDelimited | false | _n/a_ | _n/a_ | color=blue%7Cblack%7Cbrown | color=R%7C100%7CG%7C200%7CB%7C150 |
12851285
| pipeDelimited | true | _n/a_ | _n/a_ | _n/a_ | _n/a_ |
12861286
| deepObject | false | _n/a_ | _n/a_ | _n/a_ | _n/a_ |
1287-
| deepObject | true | _n/a_ | _n/a_ | _n/a_ | <span style="white-space: nowrap;">color%5BR%5D=100&color%5BG%5D=200&color%5BB%5D=150</span> |
1287+
| deepObject | true | _n/a_ | _n/a_ | _n/a_ | color%5BR%5D=100&color%5BG%5D=200&color%5BB%5D=150 |
12881288

12891289
##### Parameter Object Examples
12901290

@@ -4361,7 +4361,7 @@ parameters:
43614361
type: string
43624362
```
43634363

4364-
This example is equivalent to RFC6570's `{?foo*,bar}`, and **NOT** `{?foo*}{&bar}`. The latter is problematic because if `foo` is not defined, the result will be an invalid URI.
4364+
This example is equivalent to RFC6570's `{?foo*,bar}`, and **NOT** `{?foo*}{&bar}`. The latter is problematic because if `foo` is not defined (see [RFC6570 §2.3](https://www.rfc-editor.org/rfc/rfc6570#section-2.3) for details on what is considered undefined), the result will be an invalid URI.
43654365
The `&` prefix operator has no equivalent in the Parameter Object.
43664366

43674367
Note that RFC6570 does not specify behavior for compound values beyond the single level addressed by `explode`. The result of using objects or arrays where no behavior is clearly specified for them is implementation-defined.
@@ -4423,6 +4423,7 @@ parameters:
44234423
type: array
44244424
items:
44254425
type: string
4426+
explode: false
44264427
```
44274428
44284429
This translates to the following URI Template:

src/schemas/validation/schema.yaml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ $defs:
359359
- $ref: '#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-header'
360360
- $ref: '#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-query'
361361
- $ref: '#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-cookie'
362-
- $ref: '#/$defs/styles-for-form'
363362

364363
$defs:
365364
styles-for-path:
@@ -369,6 +368,8 @@ $defs:
369368
const: path
370369
then:
371370
properties:
371+
name:
372+
pattern: '^[^{}]+$'
372373
style:
373374
default: simple
374375
enum:
@@ -377,6 +378,8 @@ $defs:
377378
- simple
378379
required:
379380
const: true
381+
explode:
382+
default: false
380383
required:
381384
- required
382385

@@ -390,6 +393,8 @@ $defs:
390393
style:
391394
default: simple
392395
const: simple
396+
explode:
397+
default: false
393398

394399
styles-for-query:
395400
if:
@@ -408,6 +413,7 @@ $defs:
408413
allowReserved:
409414
default: false
410415
type: boolean
416+
$ref: '#/$defs/explode-for-form'
411417

412418
styles-for-cookie:
413419
if:
@@ -419,6 +425,7 @@ $defs:
419425
style:
420426
default: form
421427
const: form
428+
$ref: '#/$defs/explode-for-form'
422429

423430
$ref: '#/$defs/specification-extensions'
424431
unevaluatedProperties: false
@@ -508,6 +515,7 @@ $defs:
508515
properties:
509516
allowReserved:
510517
default: false
518+
$ref: '#/$defs/explode-for-form'
511519
explode:
512520
properties:
513521
style:
@@ -518,9 +526,8 @@ $defs:
518526
properties:
519527
style:
520528
default: form
521-
allOf:
522-
- $ref: '#/$defs/specification-extensions'
523-
- $ref: '#/$defs/styles-for-form'
529+
$ref: '#/$defs/explode-for-form'
530+
$ref: '#/$defs/specification-extensions'
524531
unevaluatedProperties: false
525532

526533
responses:
@@ -956,13 +963,12 @@ $defs:
956963
additionalProperties:
957964
type: string
958965

959-
styles-for-form:
966+
explode-for-form:
967+
$comment: for encoding objects, and query and cookie parameters, style=form is the default
960968
if:
961969
properties:
962970
style:
963971
const: form
964-
required:
965-
- style
966972
then:
967973
properties:
968974
explode:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
openapi: 3.1.0
2+
info:
3+
title: "allowReserved only permitted with in: query"
4+
version: 1.0.0
5+
components:
6+
headers:
7+
Style:
8+
schema:
9+
type: array
10+
style: simple
11+
explode: true
12+
allowReserved: true
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
openapi: 3.1.0
2+
info:
3+
title: allowReserved only permitted with in and style values that percent-encode
4+
version: 1.0.0
5+
components:
6+
parameters:
7+
style_form:
8+
name: my_form_cookie
9+
in: cookie
10+
# default style is form, therefore allowReserved is allowed
11+
allowReserved: true
12+
schema: {}
13+
style_cookie:
14+
name: my_cookie_cookie
15+
in: cookie
16+
style: cookie
17+
# no percent decoding for style=cookie, therefore allowReserved is not allowed
18+
schema: {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
openapi: 3.1.0
2+
info:
3+
title: allowReserved only permitted with in and style values that percent-encode
4+
version: 1.0.0
5+
components:
6+
parameters:
7+
header:
8+
name: my-header
9+
in: header
10+
allowReserved: false
11+
schema: {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
openapi: 3.1.0
2+
info:
3+
title: "allowReserved only permitted with in: query"
4+
version: 1.0.0
5+
components:
6+
parameters:
7+
path:
8+
name: my-path
9+
in: path
10+
allowReserved: false
11+
schema: {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
openapi: 3.1.0
2+
info:
3+
title: api
4+
version: 1.0.0
5+
components:
6+
parameters:
7+
path:
8+
name: my-path
9+
in: path
10+
required: true
11+
allowReserved: false
12+
schema: {}

tests/schema/pass/header-object-examples.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ components:
2222
schema:
2323
type: array
2424
style: simple
25-
explode: true
25+
explode: true

tests/schema/pass/parameter-object-examples.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ paths:
99
in: header
1010
description: token to be passed as a header
1111
required: true
12+
explode: false
1213
schema:
1314
type: array
1415
items:
1516
type: integer
1617
format: int64
1718
style: simple
18-
- name: username
19+
- name: usernames
1920
in: path
20-
description: username to fetch
21+
description: usernames to fetch
2122
required: true
23+
explode: false
2224
schema:
23-
type: string
25+
type: array
2426
- name: id
2527
in: query
26-
description: ID of the object to fetch
28+
description: IDs of the object to fetch
2729
required: false
2830
schema:
2931
type: array
@@ -51,4 +53,9 @@ paths:
5153
lat:
5254
type: number
5355
long:
54-
type: number
56+
type: number
57+
- in: cookie
58+
name: my_cookie1
59+
style: form
60+
explode: false
61+
schema: {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
openapi: 3.1.0
2+
info:
3+
title: "allowReserved only permitted with in: query"
4+
version: 1.0.0
5+
components:
6+
parameters:
7+
my_query:
8+
name: my_query
9+
in: query
10+
allowReserved: true
11+
schema: {}

0 commit comments

Comments
 (0)