-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Updated Examples #1035
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
Updated Examples #1035
Conversation
…dm/examples-syntax # Conflicts: # versions/3.0.md
Does this address a specific issue? |
@whitlockjc Yes, #488 |
I recommend simpler terminology -- Example Object for |
@DavidBiesack But the "described example object" that is mapped by the "examples" object is not the same object as is used in "example". That's why we have the new name. It has the summary, description and value property. There isn't much benefit in creating a distinct object for the map of "described example objects" which is why I just identified it as a Map. This is a convention we started using in Components. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to rename the existing Example Object since it is not an object (in the JSON sense), it is really just an Example Value (may be a non-object number, string, boolean, array). Rename your Described Example Object as Example Object. Then your Examples Object could be a map of Example Objects each of which has summary
, description
, value
, x-^
. Further, any $ref
for an example must be only within examples
Examples Object; one cannot use $ref
in an example
Also, consider changing valueUri
to use $ref
versions/3.0.md
Outdated
@@ -53,12 +53,12 @@ Additional utilities can also take advantage of the resulting files, such as tes | |||
- [Callback Object](#callbackObject) | |||
- [Headers Object](#headersObject) | |||
- [Example Object](#exampleObject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest renaming Example Object as Example Value since it is not an JSON object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a reasonable approach. I must admit, I did like the "Described Example" moniker but Example Value
is more accurate than Example Object
for the current usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Funny.. I felt the Described Example moniker was slightly awkward.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok, I'm not too emotionally attached to it :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the valueUrl
concept survives, consider whether having a name that is more similar to externalDocs
which has some similarities here (non-$ref style references), like externalValue
or externalExample
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
versions/3.0.md
Outdated
@@ -53,12 +53,12 @@ Additional utilities can also take advantage of the resulting files, such as tes | |||
- [Callback Object](#callbackObject) | |||
- [Headers Object](#headersObject) | |||
- [Example Object](#exampleObject) | |||
- [Described Example Object](#describedExampleObject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... then this can be Example Object
versions/3.0.md
Outdated
@@ -408,7 +408,7 @@ Field Name | Type | Description | |||
<a name="componentsSchemas"></a> schemas | Map[`string`, [Schema Object](#schemaObject)] | An object to hold reusable [Schema Objects](#schemaObject). | |||
<a name="componentsResponses"></a> responses | Map[`string`, [Response Object](#responseObject)] | An object to hold reusable [Response Objects](#responseObject). | |||
<a name="componentsParameters"></a> parameters | Map[`string`, [Parameter Object](#parameterObject)] | An object to hold reusable [Parameter Objects](#parameterObject). | |||
<a name="componentsExamples"></a> examples | Map[`string`, [Example Object](#exampleObject)] | An object to hold reusable [Example Objects](#exampleObject). | |||
<a name="componentsExamples"></a> examples | Map[`string`, [Described Example Object](#describedExampleObject)] | An object to hold reusable [Described Example Objects](#describedExampleObject). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... then this could be Map[string, Example Object]
versions/3.0.md
Outdated
@@ -938,8 +938,8 @@ Field Name | Type | Description | |||
<a name="parameterExplode"></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 property has no effect. When [`style`](#parameterStyle) is `form`, the default value is `true`. For all other styles, 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) \| [Reference Object](#referenceObject)] | The schema defining the type used for the parameter. | |||
<a name="parameterExamples"></a>examples | [[Example Object](#exampleObject) \| [Reference Object](#referenceObject)] | Examples of the content type. Each example in the Examples array SHOULD 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 SHALL _override_ the example provided by the schema. | |||
<a name="parameterExample"></a>example | [Example Object](#exampleObject) \| [Reference Object](#referenceObject) | Example of the content type. The example object SHOULD 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 SHALL _override_ the example provided by the schema. | |||
<a name="parameterExample"></a>example | [Example Object](#exampleObject) | Example of the media type. The example object SHOULD 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 SHALL _override_ the the example provided by the schema. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest changing to Example Value and "example value SHOULD ..."
versions/3.0.md
Outdated
<a name="parameterExamples"></a>examples | [[Example Object](#exampleObject) \| [Reference Object](#referenceObject)] | Examples of the content type. Each example in the Examples array SHOULD 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 SHALL _override_ the example provided by the schema. | ||
<a name="parameterExample"></a>example | [Example Object](#exampleObject) \| [Reference Object](#referenceObject) | Example of the content type. The example object SHOULD 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 SHALL _override_ the example provided by the schema. | ||
<a name="parameterExample"></a>example | [Example Object](#exampleObject) | Example of the media type. The example object SHOULD 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 SHALL _override_ the the example provided by the schema. | ||
<a name="parameterExamples"></a>examples | Map[ `string`, [Described Example Object](#describedExampleObject) \| [Reference Object](#referenceObject)] | Described Examples of the media type. Each described example SHOULD contain a value in the correct format as specified in the parameter encoding. The `examples` object is mutually exclusive to the `example` object. Furthermore, if referencing a `schema` which contains an example, the `examples` value SHALL _override_ the example provided by the schema. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Map[ string
, Example Object ...
@@ -1822,9 +1894,9 @@ X-Rate-Limit-Reset: | |||
|
|||
#### <a name="exampleObject"></a>Example Object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
becomes <a name="exampleValue"></a>Example Value
versions/3.0.md
Outdated
|
||
##### Example Example | ||
##### Example Object Example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
becomes Example Value Example
versions/3.0.md
Outdated
@@ -1848,6 +1920,84 @@ breed: Mixed | |||
|
|||
``` | |||
|
|||
#### <a name="describedExampleObject"></a>Described Example Object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
becomes <a name="exampleObject"></a>Example Object
versions/3.0.md
Outdated
##### Fixed Fields | ||
Field Name | Type | Description | ||
---|:---:|--- | ||
<a name="describedExampleSummary"></a>summary | `string` | Short description for the example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop "described" throughout
versions/3.0.md
Outdated
<a name="describedExampleSummary"></a>summary | `string` | Short description for the example. | ||
<a name="describedExampleDescription"></a>description | `string` | Long description for the example. | ||
<a name="describedExampleValue"></a>value | [Example Object](#exampleObject) | Embedded literal example. The `value` field and `valueUrl` field are mutually exclusive. | ||
<a name="describedExampleValueUrl"></a>valueUrl | `string` | A URL that points to the literal example. This provides the ability to reference examples that cannot easily be included in JSON or YAML documents. The `value` field and `valueUrl` field are mutually exclusive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using $ref : uri
instead of valueUri
.
This way, it can also be a pointer to a value elsewhere in the OpenAPI definition, or it can be an external resource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can't be done like that as then we would lose the summary
and description
properties. The alternative would be this:
examples:
foo:
summary: this is a referenced example value
value:
$ref: http://example.com/reuse.json#/example/one
The downside to this, is that you can no longer reference example values that are not JSON or YAML. Based on the conversation with @fehguy the other day, I am recommending that we add wording to the reference object definition that $ref can only point to JSON or YAML content.
By using valueUrl
we can have something special for examples that may be other formats. (and later schemas, but shhhhhh, don't say that out loud).
The other reason I decided against using reference objects in the value
property is that you can already reference described examples either in the current document or externally, so why do we also need to reference the value. If you are going to re-use, you would likely want the summary/description too.
Changed made based on TDC review.
|
Looks good to me! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
versions/3.0.md
Outdated
type: string | ||
examples: | ||
name: | ||
$ref: http://example.org/petapi-examples/OpenApi.json#/components/examples/name-example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openapi.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks good. Some of my comments are nitpicking, one or two are note. Other than that, .
versions/3.0.md
Outdated
name: | ||
$ref: http://example.org/petapi-examples/OpenApi.json#/components/examples/name-example | ||
|
||
# in a request body, note the plural `examples` as the Content-Type is set to `*`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Content-Type is set to *
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be */*
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be. The comment itself doesn't seem in place though because nothing in the example describes a wildcard content type.
versions/3.0.md
Outdated
@@ -2412,6 +2532,7 @@ schemas: | |||
$ref: http://foo.bar#/examples/address-example.json | |||
``` | |||
|
|||
>>>>>>> refs/remotes/origin/OpenAPI.next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job merging your conflict @darrelmiller. 🥇 (joke of course)
versions/3.0.md
Outdated
"name": "Ferguson", | ||
"id": 2 | ||
}] | ||
"examples": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we dropped examples
, this needs to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we support example
and examples
elsewhere but not here? Was removing this intentional? It doesn't seem to be because on line 2812 you use examples
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea behind removing examples
was that unlike other places, there's no content
here and no media types described. Providing multiple examples for a model is out of context and doesn't serve a lot of value. You'd need to combine the schema with a media type to define how it's actually serialized. You could argue that even the example
should be dropped for that reason.
versions/3.0.md
Outdated
id: 1 | ||
- name: Ferguson | ||
id: 2 | ||
cat: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
versions/3.0.md
Outdated
@@ -938,8 +937,8 @@ Field Name | Type | Description | |||
<a name="parameterExplode"></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 property has no effect. When [`style`](#parameterStyle) is `form`, the default value is `true`. For all other styles, 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) \| [Reference Object](#referenceObject)] | The schema defining the type used for the parameter. | |||
<a name="parameterExamples"></a>examples | [[Example Object](#exampleObject) \| [Reference Object](#referenceObject)] | Examples of the content type. Each example in the Examples array SHOULD 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 SHALL _override_ the example provided by the schema. | |||
<a name="parameterExample"></a>example | [Example Object](#exampleObject) \| [Reference Object](#referenceObject) | Example of the content type. The example object SHOULD 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 SHALL _override_ the example provided by the schema. | |||
<a name="parameterExample"></a>example | Any | Example of the media type. The example object SHOULD 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 SHALL _override_ the the example provided by the schema. To represent examples of media types that cannot naturally represented in JSON or YAML, a string value can be used to contain the example with escaping where necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, "correct format" makes sense but should we be more explicit, something to the effect of "it should adhere to the schema specified in the parameter encoding"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two issues here. If the parameter encoding says XML, then the example needs to be XML. That's what I meant by correct format. Saying that the example should conform to the schema is a different requirement. Let me try and come up with words that say both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"it should make sense, don't do anything crazy"
versions/3.0.md
Outdated
<a name="parameterExamples"></a>examples | [[Example Object](#exampleObject) \| [Reference Object](#referenceObject)] | Examples of the content type. Each example in the Examples array SHOULD 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 SHALL _override_ the example provided by the schema. | ||
<a name="parameterExample"></a>example | [Example Object](#exampleObject) \| [Reference Object](#referenceObject) | Example of the content type. The example object SHOULD 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 SHALL _override_ the example provided by the schema. | ||
<a name="parameterExample"></a>example | Any | Example of the media type. The example object SHOULD 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 SHALL _override_ the the example provided by the schema. To represent examples of media types that cannot naturally represented in JSON or YAML, a string value can be used to contain the example with escaping where necessary. | ||
<a name="parameterExamples"></a>examples | Map[ `string`, [Example Object](#exampleObject) \| [Reference Object](#referenceObject)] | Examples of the media type. Each example SHOULD contain a value in the correct format as specified in the parameter encoding. The `examples` object is mutually exclusive to the `example` object. Furthermore, if referencing a `schema` which contains an example, the `examples` value SHALL _override_ the example provided by the schema. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
@@ -1128,20 +1127,38 @@ A request body with a referenced model definition. | |||
"schema": { | |||
"$ref": "#/components/schemas/User" | |||
}, | |||
"examples": [ "http://foo.bar/examples/user-example.json" ] | |||
"examples": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the value. Since examples
is no longer an array if items, what is the significance of the map key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears to be a free-form description/label/name but the intent is not explained in the "Examples Object" description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key allows referencing/reusing the specific example in a $ref
I forgot to start a review, my bad. Review done, comments above. |
This proposal attempts to address the issues raised in #488
The "Example Object" has been updated. This object now supports the following scenarios:
a) multiple examples are required,
b) when short
summary
or longdescription
is needed, orc) when an example needs to be reused using a reference object.
For simpler scenarios where only one example is required, you can inline a single example.
For scenarios where the example is for a media type that is not JSON or YAML the value can be externalized using the
externalValue
property instead of thevalue
property. The value retrieved when dereferencing this URL must match the media type/ encoding associated with described example object.For Content Objects, Parameter Objects and Header Objects, you can use either a inline
example
or a map of described example objects calledexamples
, but not both. Schema objects only support inlineexample
as in OpenAPI V2.