Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect validation error "Example validation errored: schema with key or id ... already exists" #1245

Closed
ehuelsmann opened this issue Aug 24, 2023 · 5 comments · Fixed by #1377
Labels
p3 Type: Bug Something isn't working

Comments

@ehuelsmann
Copy link

ehuelsmann commented Aug 24, 2023

In the attached YAML schema API.yaml.gz, the following error is consistently reported:

Example validation errored: schema with key or id "/tmp/tmp.odmvjRGLjU/API.yaml#/components/schemas/commonId" already exists.

1406 | application/json:
1407 | schema:
1408 | $ref: '#/components/schemas/Warehouse'
1409 | examples:
1410 | validWarehouse:

referenced from API.yaml:1407:15 at #/paths/~1products~1warehouses~1{id}/get/responses/200/content/application~1json

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

API.yaml: validated in 242ms

However, the schema component id "commonId" appears exactly once in the specification. There is also no overlap between the "allOf" elements in the type being validated.

To Reproduce
Steps to reproduce the behavior:

  1. Unpack the attached API.yaml
  2. Run px @redocly/cli lint API.yaml

Will show the error above.

Expected behavior

I'm expecting the file to validate without errors. (There are no problems in the examples of this file as far as I can verify.)

Logs

None.

OpenAPI definition

Spec 3.0.3.

Redocly Version(s)

$ npx @redocly/cli --version
1.0.0-beta.125

Node.js Version(s)

$ node --version
v18.16.0

Additional context

None that I know of.

@Orest-Yastremskyy
Copy link

Hi @ehuelsmann

Thank you for reaching out.

We were able to replicate this issue and it appears to be a bug.

Please note that we will notify you as soon as the issue is resolved.

@tatomyr
Copy link
Contributor

tatomyr commented Dec 29, 2023

I've managed to simplify the case to the following sample:

openapi: 3.0.3
paths:
  /products/pricegroups/{id}:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    $ref: '#/components/schemas/pricegroup-id'
              examples:
                validPricegroup:
                  value:
                    id: 1
  /products/warehouses/{id}:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    $ref: '#/components/schemas/warehouse-id'
              examples:
                validWarehouse:
                  value:
                    id: 1
components:
  schemas:
    commonId:
      type: integer
    pricegroup-id:
      $ref: '#/components/schemas/commonId'
    warehouse-id:
      $ref: '#/components/schemas/commonId'

The issue goes away once $ref: '#/components/schemas/pricegroup-id' gets replaced with $ref: '#/components/schemas/warehouse-id' (since both are the same), or vice-versa, or, alternatively, both are replaced with $ref: '#/components/schemas/commonId'.

@ehuelsmann
Copy link
Author

Thank you! Hope that helps to find a solution!

@tatomyr
Copy link
Contributor

tatomyr commented Jan 23, 2024

Hi @ehuelsmann, the fix is already available in Redocly CLI 1.7. Could you confirm the issue has been resolved?

@ehuelsmann
Copy link
Author

@tatomyr, just verified with Redocly CLI 1.8: the problem is indeed gone!

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3 Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants