Redocly / Redocly/redocly-cli

$.components.schemas.*.example are not validated when no path reference them.

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

Nobody has claimed this yet.

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

Description

Describe the bug

It seems that examples in $.components.schemas are not validated if they are not referenced from a path.

Usually schemas are references from a path. However, x-tags allow to sometimes break this rule.
Observed behavior means that examples of those schemas are not validated which is unexpected and error prone.

To Reproduce
Steps to reproduce the behavior:

  1. Given any redocly.yaml file
  2. And this OpenAPI file(s)
openapi: 3.1.0
info:
  title: any
  version: 2024-03-15
tags:
  - name: my-tag
    description: any

components:
  schemas:

    MySchema:
      x-tags:
        - my-tag
      required:
        - id
      properties:
        id:
          type: string
      example:
        not-id: "any"
  1. Run this command with these arguments... redocly ...
redocly lint test.yaml
  1. Observe that no warning was raised regarding the absent id property in the example.
validating /data/docs/events/test.yaml...
/data/docs/events/test.yaml: validated in 8ms

Woohoo! Your API description is valid. 🎉 

Expected behavior

All examples should be linted.

Logs

OpenAPI description

Redocly Version(s): 1.9.0

Node.js Version(s) v21.6.1

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

Reproduce the issue with the supplied OpenAPI content in test.yaml and run redocly lint test.yaml. Trace the lint validation entry point for schema examples, then add coverage for an unreferenced x-tags schema; done means its invalid example raises a warning while referenced examples continue to be checked.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.