redocly-cli
redocly-cli copied to clipboard
spec-compliant response codes
Describe the bug
This excerpt is incorrect but the lint tool doesn't catch that the 200 needs to be a string '200' and the yaml parses it into a number:
paths:
/foo:
get:
responses:
200:
Quoting the spec:
This field MUST be enclosed in quotation marks (for example, “200”) for compatibility between JSON and YAML.
To Reproduce Steps to reproduce the behavior:
- Given any valid OpenAPI in YAML format with at least one numeric response code (not 2XX for example).
- Run lint
- See that the issue is not caught.
Expected behavior
- Lint should identify the error.
- Maybe we should have a decorator to correct the error.
Logs
n/a
OpenAPI description
3.0/3.1
Redocly Version(s)
1.0-1.5
Node.js Version(s)
18
Additional context
Inspired by #1331
If I understood this correctly, it's not do-able with configurable rules since we'd need to check the type of a key.
Update: had a quick look at a custom plugin but it looks like the data is already stringified when it gets to that stage - we need to look at the internals and hook in earlier to pick up this scenario.
The YAML parser we're using doesn't distinguish between numeral and string keys on the AST level. We may need to use another parser to detect what the key type actually is.