Redocly / redocly-cli

⚒️ Redocly CLI makes OpenAPI easy. Lint/validate to any standard, generate beautiful docs, and more.
https://redocly.com/docs/cli/
MIT License
905 stars 137 forks source link

spec-compliant response codes #1347

Open adamaltman opened 9 months ago

adamaltman commented 9 months ago

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

lornajane commented 8 months ago

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.

tatomyr commented 8 months ago

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.