You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the one of several appendixes to be added to clarify
the most obscure details of Parameter Object and Encoding Object
serialization.
This clarifies the correspondence between OAS fields and RFC6570
operators, and acknowledges that some field values and combinations
do not have analogues. It provides further guidance for how to
use RFC6570 implementations to support these configurations.
This includes a SHOULD directive regarding using RFC6570 expansion
with the non-RFC6570 styles, as the use of "explode" and
"allowReserved" does not otherwise make any sense. It perhaps
could be a MUST.
Examples are included to show both typical usage, and how to
work around the lack of exact RFC6570 equivalences for certain
configurations.
Copy file name to clipboardExpand all lines: versions/3.0.4.md
+212
Original file line number
Diff line number
Diff line change
@@ -1073,6 +1073,8 @@ Field Name | Type | Description
1073
1073
<a name="parameterExample"></a>example | Any | Example of the parameter's potential value. The example SHOULD match the specified schema and encoding properties if present. The `example` field is mutually exclusive of the `examples` field. Furthermore, if referencing a `schema` that contains an example, the `example` value SHALL _override_ the example provided by the schema. To represent examples of media types that cannot naturally be represented in JSON or YAML, a string value can contain the example with escaping where necessary.
1074
1074
<a name="parameterExamples"></a>examples | Map[ `string`, [Example Object](#exampleObject) \| [Reference Object](#referenceObject)] | Examples of the parameter's potential value. Each example SHOULD contain a value in the correct format as specified in the parameter encoding. The `examples` field is mutually exclusive of the `example` field. Furthermore, if referencing a `schema` that contains an example, the `examples` value SHALL _override_ the example provided by the schema.
1075
1075
1076
+
See also [Appendix C: Using RFC6570 Implementations](#usingRFC6570Implementations) for additional guidance.
1077
+
1076
1078
###### Fixed Fields and considerations for use with `content`
1077
1079
1078
1080
For more complex scenarios, the [`content`](#parameterContent) property can define the media type and schema of the parameter, as well as give examples of its use.
@@ -1622,6 +1624,8 @@ Field Name | Type | Description
1622
1624
1623
1625
This object MAY be extended with [Specification Extensions](#specificationExtensions).
1624
1626
1627
+
See also [Appendix C: Using RFC6570 Implementations](#usingRFC6570Implementations) for additional guidance.
1628
+
1625
1629
##### Encoding Object Example
1626
1630
1627
1631
`multipart/form-data` allows for binary parts:
@@ -3523,3 +3527,211 @@ Version | Date | Notes
3523
3527
1.2 | 2014-03-14 | Initial release of the formal document.
3524
3528
1.1 | 2012-08-22 | Release of Swagger 1.1
3525
3529
1.0 | 2011-08-10 | First release of the Swagger Specification
3530
+
3531
+
## <a name="usingRFC6570Implementations"></a>Appendix C: Using RFC6570 Implementations
3532
+
3533
+
Serialization is defined in terms of RFC6570 URI Templates in two scenarios:
3534
+
3535
+
Object | Condition
3536
+
------ | ---------
3537
+
[Parameter Object](#parameterObject) | When `schema` is present
3538
+
[Encoding Object](#encodingObject) | When encoding for `application/x-www-form-urlencoded` and any of `style`, `explode`, or `allowReserved` are used
3539
+
3540
+
Implementations of this specification MAY use an implementation of RFC6570 to perform variable expansion, however, some caveats apply.
3541
+
3542
+
### Equivalences Between Fields and RFC6570 Operators
3543
+
3544
+
Certain field values translate to RFC6570 operators (or lack thereof):
3545
+
3546
+
field | value | equivalent
3547
+
----- | ----- | ----------
3548
+
style | simple | _n/a_
3549
+
style | matrix | `;` prefix operator
3550
+
style | label | `.` prefix operator
3551
+
style | form | `?` prefix operator
3552
+
allowReserved | `false` | _n/a_
3553
+
allowReserved | `true` | `+` prefix operator
3554
+
explode | `false` | _n/a_
3555
+
explode | `true` | `*` modifier suffix
3556
+
3557
+
Multiple `style: form` parameters are equivalent to a single RFC6570 [variable list](https://www.rfc-editor.org/rfc/rfc6570#section-2.2) using the `?` prefix operator:
3558
+
3559
+
```YAML
3560
+
parameters:
3561
+
- name: foo
3562
+
in: query
3563
+
schema:
3564
+
type: object
3565
+
explode: true
3566
+
- name: bar
3567
+
in: query
3568
+
schema:
3569
+
type: string
3570
+
```
3571
+
3572
+
This example is equivalent to RFC6570's `{?foo*,bar}`, and ***NOT*** `{?foo*}{&bar}`, which is problematic because if `foo` is not defined, the result will be an invalid URI.
3573
+
The `&` prefix operator has no equivalent in the Parameter Object.
3574
+
3575
+
### Non-RFC6570 Field Values and Combinations
3576
+
3577
+
Configurations with no direct RFC6570 equivalent SHOULD also be handled according to RFC6570.
3578
+
Implementations MAY create a properly delimited URI Template with variables for individual names and values using RFC6570 regular or reserved expansion (based on `allowReserved`).
3579
+
3580
+
This includes:
3581
+
* the styles `pipeDelimited`, `spaceDelimited`, and `deepObject`, which have no equivalents at all
3582
+
* the combination of the style `form` with `allowReserved: true`, which is not allowed because only one prefix operator can be used at a time
3583
+
* any parameter name that is not a legal RFC6570 variable name (alphanumerics, `_`, and percent-encoded characters)
3584
+
3585
+
The Parameter Object's `name` field has a much more permissive syntax than [RFC6570 variable name syntax](https://www.rfc-editor.org/rfc/rfc6570#section-2.3).
3586
+
A parameter name that includes characters outside of the allowed RFC6570 variable character set MUST be percent-encoded before it can be used in a URI Template, and MUST set `allowReserved: true` to avoid double percent-encoding.
3587
+
3588
+
### Examples
3589
+
3590
+
Let's say we want to use the following data in a form query string, where `formulas` is exploded, and `words` is not:
3591
+
3592
+
```YAML
3593
+
formulas:
3594
+
a: x+y
3595
+
b: x/y
3596
+
c: x^y
3597
+
words:
3598
+
- math
3599
+
- is
3600
+
- fun
3601
+
```
3602
+
3603
+
#### RFC6570-Equivalent Expansion
3604
+
3605
+
This array of parameter objects uses regular `style: form` expansion, fully supported by RFC6570:
3606
+
3607
+
```YAML
3608
+
parameters:
3609
+
- name: formulas
3610
+
in: query
3611
+
schema:
3612
+
type: object
3613
+
additionalProperties:
3614
+
type: string
3615
+
explode: true
3616
+
- name: words
3617
+
in: query
3618
+
schema:
3619
+
type: array
3620
+
items:
3621
+
type: string
3622
+
```
3623
+
3624
+
This translates to the following URI Template:
3625
+
3626
+
```urlencoded
3627
+
{?formulas*,words}
3628
+
```
3629
+
3630
+
when expanded with the data given earlier, we get:
3631
+
3632
+
```urlencoded
3633
+
?a=x%2By&b=x%2Fy&c=x%5Ey&words=math,is,fun
3634
+
```
3635
+
3636
+
#### Expansion With Non-RFC6570-Supported Options
3637
+
3638
+
But now let's say that (for some reason), we really want that `/` in the `b` formula to show up as-is in the query string, and we want our words to be space-separated like in a written phrase.
3639
+
To do that, we'll add `allowReserved: true` to `formulas`, and change to `style: spaceDelimited` for `words`:
3640
+
3641
+
```YAML
3642
+
parameters:
3643
+
- name: formulas
3644
+
in: query
3645
+
schema:
3646
+
type: object
3647
+
additionalProperties:
3648
+
type: string
3649
+
explode: true
3650
+
allowReserved: true
3651
+
- name: words
3652
+
in: query
3653
+
style: spaceDelimited
3654
+
schema:
3655
+
type: array
3656
+
items:
3657
+
type: string
3658
+
```
3659
+
3660
+
We can't combine the `?` and `+` RFC6570 prefixes, and there's no way with RFC6570 to replace the `,` separator with a space character.
3661
+
So we need to restructure the data to fit a manually constructed URI Template that passes all of the pieces through the right sort of expansion.
3662
+
3663
+
Here is one such template.
3664
+
The exact variable names are unimportant, but in this example "f" and "w" are meant to suggest "formulas" and "words", while "n" and "v" suggest "name" and "value":
We'll also need to pre-process the names and values for `formaulas` because while `/` and most other reserved characters are allowed in the query string by RFC3986, `[`, `]`, and `#` [are not](https://datatracker.ietf.org/doc/html/rfc3986#appendix-A), and `&`, `=`, and `+` all have [special behavior](https://www.rfc-editor.org/rfc/rfc1866#section-8.2.1) in the `application/x-www-form-urlencoded` format, which is what we are using in the query string.
3671
+
3672
+
Setting `allowReserved: true` does _not_ make reserved characters that are not allowed in URIs allowed, it just allows them to be _passed through expansion unchanged._
3673
+
Therefore, any tooling still needs to percent-encode those characters because reserved expansion will not do it, but it _will_ leave the percent-encoded triples unchanged.
3674
+
See also Appendix D for further guidance on percent-encoding and form media types, including guidance on handling the delimiter characters for `spaceDelimited`, `pipeDelimited`, and `deepObject` in parameter names and values.
3675
+
3676
+
So here is our data structure that arranges the names and values to suit the template above, where names and values for `formulas` have `[]#&=+` pre-percent encoded (although only `+` appears in this example):
3677
+
3678
+
```YAML
3679
+
fn0: a
3680
+
fv0: x%2By
3681
+
fn1: b
3682
+
fv1: x/y
3683
+
fn2: c
3684
+
fv2: x^y
3685
+
wn: words
3686
+
wv0: math
3687
+
wv1: is
3688
+
wv2: fun
3689
+
```
3690
+
3691
+
Expanding our manually assembled template with our restructured data yields the following query string:
3692
+
3693
+
```urlencoded
3694
+
?a=x%2By&b=x/y&c=x%5Ey&words=math%20is%20fun
3695
+
3696
+
```
3697
+
The `/` and the pre-percent-encoded `%2B` have been left alone, but the disallowed `^` character (inside a value) and space characters (in the template but outside of the expanded variables) were percent-encoded.
3698
+
3699
+
#### Undefined Values and Manual URI Template Construction
3700
+
3701
+
Care must be taken when manually constructing templates to handle the values that [RFC6570 considers to be _undefined_](https://datatracker.ietf.org/doc/html/rfc6570#section-2.3) correctly:
3702
+
3703
+
```YAML
3704
+
formulas: {}
3705
+
words:
3706
+
- hello
3707
+
- world
3708
+
```
3709
+
3710
+
Using this data with our original RFC6570-friendly URI Template, `{?formulas*,words}`, produces the following:
3711
+
3712
+
3713
+
```urlencoded
3714
+
?words=hello,world
3715
+
```
3716
+
3717
+
This means that the manually constructed URI Template and restructured data need to leave out the `formulas` object entirely so that the `words` parameter is the first and only parameter in the query string.
0 commit comments