-
Notifications
You must be signed in to change notification settings - Fork 9.1k
v3.??? Data vs Serialized Examples in Example Objects #4647
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
base: v3.2-dev
Are you sure you want to change the base?
Conversation
@mikekistler fixed that example- it had been done with integers but those aren't interesting serialization cases! So I switched to strings. I also added some text about it being easier/less ambiguous to parse the serialized example and validate the data in many cases than to try to go the other way around. |
@mikekistler I have clarified the serialization rules in the latest added commit. |
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.
This will help clarify what examples are and how they should be used.
My comments are intended to clarify some points and also to make this change a more evolutionary transition.
examples: | ||
oneMinute: | ||
dataValue: 60 | ||
serializedValue: 'X-Rate-Limit-Reset: 60' |
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 love that you have added all these 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.
Honestly it was one of the best things about writing the PR and is what convinced me it's worth making a strong case for it.
|
||
##### Fixed Fields | ||
|
||
| Field Name | Type | Description | | ||
| ---- | :----: | ---- | | ||
| <a name="example-summary"></a>summary | `string` | Short description for the example. | | ||
| <a name="example-description"></a>description | `string` | Long description for the example. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation. | | ||
| <a name="example-value"></a>value | Any | Embedded literal example. The `value` field and `externalValue` field are mutually exclusive. To represent examples of media types that cannot naturally represented in JSON or YAML, use a string value to contain the example, escaping where necessary. | | ||
| <a name="example-external-value"></a>externalValue | `string` | A URI that identifies the literal example. This provides the capability to reference examples that cannot easily be included in JSON or YAML documents. The `value` field and `externalValue` field are mutually exclusive. See the rules for resolving [Relative References](#relative-references-in-api-description-uris). | | ||
| <a name="example-data-value"></a>dataValue | Any | An example of the data structure that MUST be valid according to the relevant [Schema Object](#schema-object). If this field is present, `externalDataValue`, `value`, and `externalValue` MUST be absent. | |
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.
Since JSON Schemas validate "instances", should we use "instance" instead of "data structure"?
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 couldn't decide which language was better. Easy to tweak at any point- I'll think about it as I do the other updates. [EDIT: I decided "instance" was too JSON Schema jargon-y, plus we go outside of the JSON Schema instance model with things like raw binary data.]
src/oas.md
Outdated
|
||
##### Example Object Examples | ||
Historically, the Example Object's `value` and `externalValue` field and the non-Schema Object singular `example` fields were intended to show examples of the serialized form, while allowing JSON or YAML examples to be included inline rather than as serialized strings. |
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 can't speak to the "original intent" for these fields -- I wasn't involved at the time. But I wonder if this was really consciously decided as the intent, and then somehow omitted from the spec, or if instead it was not really understood that there is a difference between the data value and serialized value and that is why the distinction was not included in the spec.
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.
@mikekistler I understand that tooling vendors have implemented it differently, but these quotes from 3.0.3 seem pretty clear to me, and we've debated this before and always agreed that the encoded/serialized form was the intent. AFAIK, this effort by you right now is the first time anyone deeply involved has taken the opposite position in terms of what the wording means:
From the Parameter Object:
When
example
orexamples
are provided in conjunction with the schema object, the example MUST follow the prescribed serialization strategy for the parameter.
From the Media Type Object example
field:
The example object SHOULD be in the correct format as specified by the media type.
From the Media Type Object examples
field:
Examples of the media type. Each example object SHOULD match the media type and specified schema if present.
From the Example Object value
field:
To represent examples of media types that cannot naturally represented in JSON or YAML, use a string value to contain the example, escaping where necessary.
From the Example Object externalValue
field:
This provides the capability to reference examples that cannot easily be included in JSON or YAML documents.
From the Example Object after the fixed fields table:
In all cases, the example value is expected to be compatible with the type schema of its associated value. Tooling implementations MAY choose to validate compatibility automatically, and reject the example value(s) if incompatible.
I honestly don't see how all of this above, taken together, can be interpreted in any other way.
{ | ||
"author": "A. Writer", | ||
"title": "An Older Book", | ||
"rating": 4.5 | ||
} |
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.
Should this serialized value be a string, which condensed white-space (as was done above)?
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.
@mikekistler it is a string, that's what the |
at the end of the serializedValue: |
does (YAML block literal).
As for minimizing, I did that for the parameter because it has to be shoved into the query string. This is presumed to be for a body, so it might be sent without that minimizing. But TBH I was just trying out all sorts of different things, I'm not super-attached to this.
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'll work on an update hopefully tonight, or at least before the meeting tomorrow morning.
{ | ||
"author": "A. Writer", | ||
"title": "An Older Book", | ||
"rating": 4.5 | ||
} |
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.
@mikekistler it is a string, that's what the |
at the end of the serializedValue: |
does (YAML block literal).
As for minimizing, I did that for the parameter because it has to be shoved into the query string. This is presumed to be for a body, so it might be sent without that minimizing. But TBH I was just trying out all sorts of different things, I'm not super-attached to this.
|
||
##### Fixed Fields | ||
|
||
| Field Name | Type | Description | | ||
| ---- | :----: | ---- | | ||
| <a name="example-summary"></a>summary | `string` | Short description for the example. | | ||
| <a name="example-description"></a>description | `string` | Long description for the example. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation. | | ||
| <a name="example-value"></a>value | Any | Embedded literal example. The `value` field and `externalValue` field are mutually exclusive. To represent examples of media types that cannot naturally represented in JSON or YAML, use a string value to contain the example, escaping where necessary. | | ||
| <a name="example-external-value"></a>externalValue | `string` | A URI that identifies the literal example. This provides the capability to reference examples that cannot easily be included in JSON or YAML documents. The `value` field and `externalValue` field are mutually exclusive. See the rules for resolving [Relative References](#relative-references-in-api-description-uris). | | ||
| <a name="example-data-value"></a>dataValue | Any | An example of the data structure that MUST be valid according to the relevant [Schema Object](#schema-object). If this field is present, `externalDataValue`, `value`, and `externalValue` MUST be absent. | |
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 couldn't decide which language was better. Easy to tweak at any point- I'll think about it as I do the other updates. [EDIT: I decided "instance" was too JSON Schema jargon-y, plus we go outside of the JSON Schema instance model with things like raw binary data.]
examples: | ||
oneMinute: | ||
dataValue: 60 | ||
serializedValue: 'X-Rate-Limit-Reset: 60' |
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.
Honestly it was one of the best things about writing the PR and is what convinced me it's worth making a strong case for it.
src/oas.md
Outdated
|
||
##### Example Object Examples | ||
Historically, the Example Object's `value` and `externalValue` field and the non-Schema Object singular `example` fields were intended to show examples of the serialized form, while allowing JSON or YAML examples to be included inline rather than as serialized strings. |
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.
@mikekistler I understand that tooling vendors have implemented it differently, but these quotes from 3.0.3 seem pretty clear to me, and we've debated this before and always agreed that the encoded/serialized form was the intent. AFAIK, this effort by you right now is the first time anyone deeply involved has taken the opposite position in terms of what the wording means:
From the Parameter Object:
When
example
orexamples
are provided in conjunction with the schema object, the example MUST follow the prescribed serialization strategy for the parameter.
From the Media Type Object example
field:
The example object SHOULD be in the correct format as specified by the media type.
From the Media Type Object examples
field:
Examples of the media type. Each example object SHOULD match the media type and specified schema if present.
From the Example Object value
field:
To represent examples of media types that cannot naturally represented in JSON or YAML, use a string value to contain the example, escaping where necessary.
From the Example Object externalValue
field:
This provides the capability to reference examples that cannot easily be included in JSON or YAML documents.
From the Example Object after the fixed fields table:
In all cases, the example value is expected to be compatible with the type schema of its associated value. Tooling implementations MAY choose to validate compatibility automatically, and reject the example value(s) if incompatible.
I honestly don't see how all of this above, taken together, can be interpreted in any other way.
@mikekistler I have updated quite a few things, and left other things the same, with the upshot being that this PR is only about adding new fields to the Example Object and showing their use:
|
There's a lot of support for this change and especially for the examples that are added. We need to discuss naming before merging, but we think this can go into 3.2. |
Co-authored-by: Dan Hudlow <[email protected]>
@OAI/tsc and all, I have filed several issues to split out various related conversations and keep this PR moving to conclusion:
|
This is most of what we would do for the first and most essential of three Example Object related proposals I went over in the last TDC call. I'm posting it because:
Please look through this and particularly focus on how this allowed me to change our in-spec examples to make many things more clear, and show how OAD authors can similarly make their intent clear.
Note that the changes to the XML examples don't (I think) assume the
nodeType
change in PR #4592, but I might have lost track of that if you see something strange there. The point is that this helps tremendously in showing expected XML behavior.