Redocly / Redocly/redocly-cli

Example validates schema incorrectly

Open
#993 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug
Validating example gives unexpected warning regarding "exclusiveMaximum" being of invalid type which it is not according to specification.

To Reproduce
Steps to reproduce the behavior:

  1. Given the redocly.yaml file (see OpenAPI definition section)
  2. And the OpenAPI definition
  3. When linting it via redocly lint test@v1
  4. See Logs section for result

Expected behavior
No errors or warnings regarding "exclusiveMaximum" being of invalid type. According to OpenAPI specification 3.0.3 the "exclusiveMaximum" is taken from the JSON Schema and its description can be found here

Logs

validating apis/test.yaml...
[1] apis/test.yaml:28:17 at #/paths/~1examples/get/responses/default/content/application~1json/schema

Example validation errored: exclusiveMaximum value must be ["number"].

26 | "application/json":
27 |   schema:
28 |     type: object
29 |     properties:
 … |     < 5 more lines >
35 |         example: 403
36 |   examples:
37 |     example-response:

referenced from apis/test.yaml:27:15 at #/paths/~1examples/get/responses/default/content/application~1json 

Warning was generated by the no-invalid-media-type-examples rule.


apis/test.yaml: validated in 55ms

Woohoo! Your OpenAPI definition is valid. 🎉
You have 1 warning.

OpenAPI definition

# redocly.yaml
extends:
  - recommended

rules:
  operation-4xx-response: off

apis:
  test@v1:
    root:
      apis/test.yaml
# apis/test.yaml
openapi: 3.0.3
info:
  title: My service
  description: My service
  version: 1.0.0
  contact:
    name: Contact name
    email: info@example.com
    url: https://
  license:
    name: Licence
    url: https://
servers:
  - url: 'https://testing.com'
paths:
  /examples:
    get:
      summary: Example path
      security:
        - {}
      operationId: get-examples
      responses:
        default:
          description: Example response
          content:
            "application/json":
              schema:
                type: object
                properties:
                  rangedInteger:
                    type: integer
                    minimum: 100
                    maximum: 600
                    exclusiveMaximum: true
                    example: 403
              examples:
                example-response:
                  summary: Example response
                  value:
                    rangedInteger: 400

Redocly Version(s)
1.0.0-beta.120

Node.js Version(s)
v18.13.0

Additional context

If the specification is changed as per the warnings suggestion a different log (with error) is given.

# updated apis/test.yaml
openapi: 3.0.3
info:
  title: My service
  description: My service
  version: 1.0.0
  contact:
    name: Contact name
    email: info@example.com
    url: https://
  license:
    name: Licence
    url: https://
servers:
  - url: 'https://testing.com'
paths:
  /examples:
    get:
      summary: Example path
      security:
        - {}
      operationId: get-examples
      responses:
        default:
          $ref: '#/components/responses/ExampleResponse'
components:
  responses:
    ExampleResponse:
      description: Example response
      content:
        "application/json":
          schema:
            $ref: '#/components/schemas/ReferencedSchema'
          examples:
            example-response:
              summary: Example response
              value:
                rangedInteger: 400
  schemas:
    ReferencedSchema:
      type: object
      properties:
        rangedInteger:
          type: integer
          minimum: 100
          exclusiveMaximum: 600
          example: 403

The log with expected (correct) error:

validating apis/test.yaml...
[1] apis/test.yaml:33:39 at #/paths/~1examples/get/responses/default/content/application~1json/schema/properties/rangedInteger/exclusiveMaximum

Expected type `boolean` but got `integer`.

31 |       type: integer
32 |       minimum: 100
33 |       exclusiveMaximum: 600
34 |       example: 403
35 | examples:

Error was generated by the spec rule.


apis/test.yaml: validated in 57ms

❌ Validation failed with 1 error.
run `openapi lint --generate-ignore-file` to add all problems to the ignore file.

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 test@v1 with the provided redocly.yaml and apis/test.yaml, focusing on the no-invalid-media-type-examples warning for exclusiveMaximum. Compare the inline schema case with the referenced-schema case and confirm that valid OpenAPI 3.0.3 input no longer produces the warning while an invalid integer form still reports an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.