Redocly / Redocly/redocly-cli

Linting does not catch default value types not conforming to specified field type

Open
#1,628 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p3 Type: Idea
Dominant language
TypeScript
Stars
1.5k
Forks
228
Avg merge
1d 14h
Merged PRs (30d)
48

Description

Redocly CLI does not seem to recognise when a fields default value does not conform to the type specified for that field. This also applies to the vscode extension.

Apologies if there is some config I am missing or already a plugin that adds this behaviour!

Steps to reproduce the behavior:

  1. Given this OpenAPI file:
openapi: 3.0.0
info:
  description: Example
  title: Example
  version: 1.0.0
  license: 
    name: Example License
    url: foo
servers:
  - url: /apis/v0
paths:
  /foo:
    get: 
      operationId: getFoo
      summary: bar
      responses: 
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: string
                default: 123
        '400':
          description: error 400
      security: 
        - foo_security:
          - read:foo
components: 
  securitySchemes:
    foo_security:
      type: oauth2
      flows:
        clientCredentials:
          tokenUrl: /openId/token
          scopes:
            read:foo: read foo
  1. Run redocly lint openapi.yaml
  2. See output

Expected Behaviour

I would expect there to be a warning or error for the default value of 123 not to match the type of string.

Redocly Version(s)

1.17.1

Node.js Version(s)

20

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running redocly lint openapi.yaml with the supplied OpenAPI example and trace the linting path that processes the schema's default value. Confirm that the completed change reports an error or warning when default: 123 is used with type: string, including the corresponding VS Code behavior if it shares the same validation path.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.