redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

spec-compliant response codes

Open adamaltman opened this issue 1 year ago • 2 comments

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:

  1. Given any valid OpenAPI in YAML format with at least one numeric response code (not 2XX for example).
  2. Run lint
  3. See that the issue is not caught.

Expected behavior

  1. Lint should identify the error.
  2. 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

adamaltman avatar Dec 02 '23 20:12 adamaltman

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.

lornajane avatar Dec 18 '23 13:12 lornajane

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.

tatomyr avatar Dec 18 '23 15:12 tatomyr