Skip to content

Examples documentation #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions versions/3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,13 @@ Field Name | Type | Description
<a name="parameterExplode"></a>explode | `boolean` | When this is true, parameter values of type `array` or `object` generate seperate parameters for each value of the array, or key-value-pair of the map. For other types of parameters this property has no effect. The default value is false.
<a name="parameterAllowReserved"></a>allowReserved | `boolean` | Determines whether the parameter value should allow reserved characters, as defined by [RFC3986](https://tools.ietf.org/html/rfc3986#section-2.2) `:/?#[]@!$&'()*+,;=` to be included without percent-encoding. This property only applies to parameters with an `in` value of `query`. The default value is `false`.
<a name="parameterSchema"></a>schema | [Schema Object](#schemaObject) | The schema defining the type used for the parameter.
<a name="parameterExamples"></a>examples | [Examples Array](#examplesArray) | Examples of the content type. Each example in the Examples Array must be in the correct format as specified parameter encoding. The `examples` object is mutually exclusive to the `example` object. Furthermore, if referencing a `schema` which contains an example, the `examples` value will _override_ the example provided by the schema.
<a name="parameterExample"></a>example | [Example Object](#exampleObject) | Example of the content type. The example object _must_ be in the correct format as specified in the parameter encoding. The `example` object is mutually exclusive to the `examples` object. Furthermore, if referencing a `schema` which contains an example, the `example` value will _override_ the example provided by the the schema.

For more complex scenarios a `content` object can be used to define the media-type and schema of the parameter.
For more complex scenarios a `content` object can be used to define the media-type
and schema of the parameter. This option is mutually exclusive with the simple scenario
above. When `example` or `examples` are provided in conjunction with the `schema` object,
the example must follow the prescribed serialization strategy for the parameter.

Field Name | Type | Description
---|:---:|---
Expand Down Expand Up @@ -1068,8 +1073,8 @@ Each content type object provides schema and examples for a the media type ident
Field Name | Type | Description
---|:---:|---
<a name="contentTypeSchema"></a>schema | [Schema Object](#schemaObject) | The schema defining the type used for the request body.
<a name="contentTypeExamples"></a>examples | [Examples Array](#examplesArray) | Examples of the content type.
<a name="contentTypeExample"></a>example | [Example Object](#exampleObject) | Example of the content type.
<a name="contentTypeExamples"></a>examples | [Examples Array](#examplesArray) | Examples of the content type. Each example in the Examples Array must be in the correct format as specified in the _content_ type. The `examples` object is mutually exclusive to the `example` object. Furthermore, if referencing a `schema` which contains an example, the `examples` value will _override_ the example provided by the schema.
<a name="contentTypeExample"></a>example | [Example Object](#exampleObject) | Example of the content type. The example object _should_ be in the correct format as specified in the _content_ type. The `example` object is mutually exclusive to the `examples` object. Furthermore, if referencing a `schema` which contains an example, the `example` value will _override_ the the example provided by the schema.

##### Patterned Fields
Field Pattern | Type | Description
Expand Down Expand Up @@ -1102,10 +1107,10 @@ application/json:
schema:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inside a content object

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capturing a TDC discussion comment "I would expect that any tooling worth its salt would throw this out if it failed to parse, but that it would try to parse it."

$ref: "#/definitions/Pet"
examples:
# converted directly from YAML to JSON
- name: Fluffy
petType: Cat
- name: Rover
petType: Frog
- {"name": "Rover", "petType": "Frog"}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two examples are semantically equivalent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the json encoding inside the YAML (while correct) to be confusing; I don't think it is done elsewhere in the 3.0 spec.


```

Expand Down Expand Up @@ -2153,13 +2158,15 @@ description: Pets operations

#### <a name="examplesObject"></a>Examples Object
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the move to requestBody, this didn't make sense anymore


Anywhere an `example` may be given, allow a $ref object.
This does mean that `example`, structurally, can be either a string primitive or an object, like `additionalProperties`.
Anywhere an `example` may be given, a JSON Reference may be used, with the
explicit restriction that examples having a JSON format with object named
`$ref` are not allowed. This does mean that `example`, structurally, can be
either a string primitive or an object, similar to `additionalProperties`.

In locations where the field being provided an `example` is a scalar value _or_ has it's content-type definition determined by a higher-level construct (a response payload, for example, uses the `produces` attribute to select the correct message format), the plural `examples` shall be used, and the payload format be specified as a key to the example.

In all cases, the payload is expected to be compatible with the type schema for the value that it is accompanying.
Tooling Specifications may choose to validate compatibility automatically, and reject the example value(s) if they are not compatible.
In all cases, the payload is expected to be compatible with the type schema
for the value that it is accompanying. Tooling implementations may choose to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... more weight to using SHOULD instead of MUSt above.

validate compatibility automatically, and reject the example value(s) if they
are not compatible.

```yaml
# in a model
Expand All @@ -2181,22 +2188,21 @@ definitions:
- {"bar": "baz"}
'application/xml':
examples:
-
$ref: 'http://foo.bar#/examples/address-example.xml'
- $ref: 'http://foo.bar#/examples/address-example.xml'
'text/plain':
examples:
-
$ref: 'http://foo.bar#/examples/address-example.txt'
- $ref: 'http://foo.bar#/examples/address-example.txt'

# in a parameter

parameters:
- name: 'zip'
- name: 'zipCode'
in: 'query'
type: 'string'
format: 'zip'
example:
$ref: 'http://foo.bar#/examples/zip-example'
schema:
type: 'string'
format: 'zip-code'
example:
$ref: 'http://foo.bar#/examples/zip-example'
# in a response, note the plural `examples`:
responses:
200:
Expand Down