-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Description
Responses Object spec says that: This field MUST be enclosed in quotation marks (for example, “200”) for compatibility between JSON and YAML (https://github.com/OAI/OpenAPI-Specification/blob/157a4c81ae537ef793b2bee368bc00d88b461de8/versions/3.0.2.md#patterned-fields-1)
Is it really needed?
Json only allows strings as keys and at least in PHP numeric keys are auto-encoded to strings.
Yaml allows both, but in PHP numeric keys are always type-casted to an int, like 200, instead of "200"
- proof of PHP array typecasting - https://3v4l.org/F8slo
- my tests showing how keys are encoded into json and yaml - https://github.com/orisai/openapi/blob/314b0ce647bd5b5878eced14cfe67b82915d1f12/tests/Unit/Spec/ResponsesTest.php#L109-L139 (current build failures are related to caching issues, code is correct)
Because it is probably not possible to create workaround for this in PHP, we could solve it only by adding a flag to yaml encoder to make integer keys strings (in case array is not auto-indexed from 0)
But the preferred way would be to remove string key requirement from specification.