replace numeric keys in yaml files with strings #2120
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I have replaced numeric keys in OpenAPI documents with strings, in accordance with the OpenAPI spec.
Motivation and Context
The OpenAPI spec requires that OpenAPI documents be expressable in JSON (v2 and v3). YAML allows any type to be an object key, but OpenAPI does not. v3 has an explicit note to this effect in its Format section; it applies to v2 as well.
I think swagger-editor should show an error when given YAML with non-string keys, but that doesn't look possible. The YAML parser (js-yaml) silently stringifies any object keys which are not strings, so swagger-editor's internals never see the integer keys. This is not the usual behavior of YAML parsers (and arguably not correct). I've opened an issue about this at nodeca/js-yaml#538, but that's beyond the scope of this issue.
Pending that issue, swagger-editor can at least be fixed to not show an invalid API document when you open the editor.
This has come up over at OAI/OpenAPI-Specification#2171
and stoplightio/spectral#955
How Has This Been Tested?
Given the YAML parser gives identical results parsing string and integer keys, and that's all I've changed, no tests or code should need any change.
Checklist
My PR contains...
src/
is unmodified: changes to documentation, CI, metadata, etc.)package.json
)My changes...
Documentation
Automated tests