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
+209
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.
@@ -1623,6 +1625,8 @@ Field Name | Type | Description
1623
1625
1624
1626
This object MAY be extended with [Specification Extensions](#specificationExtensions).
1625
1627
1628
+
See also [Appendix C: Using RFC6570 Implementations](#usingRFC6570Implementations) for additional guidance.
1629
+
1626
1630
##### Encoding Object Example
1627
1631
1628
1632
`multipart/form-data` allows for binary parts:
@@ -3524,3 +3528,208 @@ Version | Date | Notes
3524
3528
1.2 | 2014-03-14 | Initial release of the formal document.
3525
3529
1.1 | 2012-08-22 | Release of Swagger 1.1
3526
3530
1.0 | 2011-08-10 | First release of the Swagger Specification
3531
+
3532
+
## <a name="usingRFC6570Implementations"></a>Appendix C: Using RFC6570 Implementations
3533
+
3534
+
Serialization is defined in terms of RFC6570 URI Templates in two scenarios:
3535
+
3536
+
Object | Condition
3537
+
------ | ---------
3538
+
[Parameter Object](#parameterObject) | When `schema` is present
3539
+
[Encoding Object](#encodingObject) | When encoding for `application/x-www-form-urlencoded` and any of `style`, `explode`, or `allowReserved` are used
3540
+
3541
+
Implementations of this specification MAY use an implementation of RFC6570 to perform variable expansion, however, some caveats apply.
3542
+
3543
+
### Equivalences Between Fields and RFC6570 Operators
3544
+
3545
+
Certain field values translate to RFC6570 operators (or lack thereof):
3546
+
3547
+
field | value | equivalent
3548
+
----- | ----- | ----------
3549
+
style | simple | _n/a_
3550
+
style | matrix | `;` prefix operator
3551
+
style | label | `.` prefix operator
3552
+
style | form | `?` prefix operator
3553
+
allowReserved | `false` | _n/a_
3554
+
allowReserved | `true` | `+` prefix operator
3555
+
explode | `false` | _n/a_
3556
+
explode | `true` | `*` modifier suffix
3557
+
3558
+
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:
3559
+
3560
+
```YAML
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
+
- name: formulas
3609
+
in: query
3610
+
schema:
3611
+
type: object
3612
+
additionalProperties
3613
+
type: string
3614
+
explode: true
3615
+
- name: words
3616
+
in: query
3617
+
schema:
3618
+
type: array
3619
+
items:
3620
+
type: string
3621
+
```
3622
+
3623
+
This translates to the following URI Template:
3624
+
3625
+
```urlencoded
3626
+
{?formulas*,words}
3627
+
```
3628
+
3629
+
when expanded with the data given earlier, we get:
3630
+
3631
+
```urlencoded
3632
+
?a=x%2By&b=x%2Fy&c=x%5Ey&words=math,is,fun
3633
+
```
3634
+
3635
+
#### Expansion With Non-RFC6570-Supported Options
3636
+
3637
+
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.
3638
+
To do that, we'll add `allowReserved: true` to `formulas`, and change to `style: spaceDelimited` for `words`:
3639
+
3640
+
```YAML
3641
+
- name: formulas
3642
+
in: query
3643
+
schema:
3644
+
type: object
3645
+
additionalProperties
3646
+
type: string
3647
+
explode: true
3648
+
allowReserved: true
3649
+
- name: words
3650
+
in: query
3651
+
style: spaceDelimited
3652
+
schema:
3653
+
type: array
3654
+
items:
3655
+
type: string
3656
+
```
3657
+
3658
+
We can't combine the `?` and `+` RFC6570 prefixes, and there's no way with RFC6570 to replace the `,` separator with a space character.
3659
+
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.
3660
+
3661
+
Here is one such template.
3662
+
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.
3669
+
3670
+
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._
3671
+
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.
3672
+
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.
3673
+
3674
+
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):
3675
+
3676
+
```YAML
3677
+
fn0: a
3678
+
fv0: x%2By
3679
+
fn1: b
3680
+
fv1: x/y
3681
+
fn2: c
3682
+
fv2: x^y
3683
+
wn: words
3684
+
wv0: math
3685
+
wv1: is
3686
+
wv2: fun
3687
+
```
3688
+
3689
+
Expanding our manually assembled template with our restructured data yields the following query string:
3690
+
3691
+
```urlencoded
3692
+
?a=x%2By&b=x/y&c=x%5Ey&words=math%20is%20fun
3693
+
3694
+
```
3695
+
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.
3696
+
3697
+
#### Undefined Values and Manual URI Template Construction
3698
+
3699
+
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:
3700
+
3701
+
```YAML
3702
+
formulas: {}
3703
+
words:
3704
+
- hello
3705
+
- world
3706
+
```
3707
+
3708
+
Using this data with our original RFC6570-friendly URI Template, `{?formulas*,words}`, produces the following:
3709
+
3710
+
3711
+
```urlencoded
3712
+
?words=hello,world
3713
+
```
3714
+
3715
+
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