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

no-invalid-media-type-examples fails with "schema with key or id ... already exists" on windows #329

Open
aviskase opened this issue Jul 23, 2021 · 9 comments
Labels
governance Issues relating to problems with or requests for API governance/linting/decorating p2 Type: Bug Something isn't working

Comments

@aviskase
Copy link
Contributor

aviskase commented Jul 23, 2021

Describe the bug
Reproducable only on windows.
In WSL and linux there is no warnings or errors.

Requires schemas in different directory than the main description doc.

To Reproduce
Steps to reproduce the behavior:

  1. Given attached OpenAPI description doc and schemas
  2. Run lint
➜  npm run lint

> scripts@1.0.0 lint C:\Users\ybagriy\sources\scripts
> openapi lint openapi.yaml

No configurations were defined in extends -- using built in recommended configuration by default.

validating openapi.yaml...
[1] openapi.yaml:40:17 at #/paths/~1client/get/responses/200/content/application~1json/schema

Example validation errored: schema with key or id "C:\Users\ybagriy\sources\scripts\Clients\Client.yaml" already exists.

38 | application/json:
39 |   schema:
40 |     type: object
41 |     properties:
42 |       data:
43 |         $ref: ./Clients/Client.yaml
44 |   example:
45 |     data:

referenced from openapi.yaml:39:15

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


openapi.yaml: validated in 60ms

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

Expected behavior
No errors should be generated.

OpenAPI definition

Directory structure:

.
├── Clients
│   ├── Client.yaml
│   └── ClientCollection.yaml
├── openapi.yaml

openapi.yaml file:

openapi: 3.0.3
info:
  title: test
  version: 1.0.0
  description: test
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: https
paths:
  /clients:
    get:
      summary: Retrieve clients
      description: Retrieve clients.
      operationId: getClients
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                $ref: ./Clients/ClientCollection.yaml
              example:
                data:
                  items:
                    - id: 89d6c100-8322-4a45-97ab-bb55c31ea1b2
                      name: test
  /client:
    get:
      summary: Retrieve a client
      description: Retrieve a client.
      operationId: getClient
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: ./Clients/Client.yaml
              example:
                data:
                  id: 89d6c100-8322-4a45-97ab-bb55c31ea1b2
                  name: test

Clients/Client.yaml file

type: object
required:
  - id
  - name
properties:
  id:
    type: string
  name:
    type: string

Clients/ClientCollection.yaml file

type: object
properties:
  data:
    type: object
    properties:
      items:
        type: array
        items:
          $ref: ./Client.yaml

openapi-cli Version(s)
1.0.0-beta.54

Node.js Version(s)
v14.17.0

@aviskase aviskase changed the title no-invalid-media-type-examples fails with no-invalid-media-type-examples fails with "schema with key or id ... already exists" on windows Jul 23, 2021
@aviskase
Copy link
Contributor Author

Exception schema with key or id "C:\Users\ybagriy\sources\scripts\Clients\Client.yaml" already exists is thrown by ajv. I'm not familiar with it enough to understand why it's happening only on windows.

So far this exception occurs only with this validation rule, any other seems to be passing fine on our project repo.

@RomanHotsiy RomanHotsiy added Type: Bug Something isn't working GR p2 labels Nov 1, 2021
@slavikbez
Copy link
Contributor

On Windows it won't throw if I comment this line. Will investigate deeper.

@tatomyr tatomyr self-assigned this Jan 27, 2022
@tatomyr
Copy link
Contributor

tatomyr commented Jan 27, 2022

For some reason Ajv visits Clients\Client.yaml twice on Win. It happens when validating the /clients path. The data we provide for validation is identical for both Win & Mac. The bundles are equal too.

@tatomyr tatomyr removed their assignment Mar 18, 2022
@jeremyfiel
Copy link
Contributor

@tatomyr any news on this one?

@tatomyr
Copy link
Contributor

tatomyr commented Oct 31, 2022

@jeremyfiel unfortunately I cannot share any ETAs on this at the moment.

@laellyo
Copy link

laellyo commented Jan 13, 2023

Hello,
I have the same issue on Windows.
Any idea at least of a workaround? (Except disabling the rule 🙃)

@tatomyr
Copy link
Contributor

tatomyr commented Jan 23, 2023

Hi @laellyo,
Maybe ignoring these exact errors could help in your case? Please see the docs: https://redocly.com/docs/cli/commands/lint/#generate-ignore-file
This won't help with validating the content of a ref though.

@morozovcookie
Copy link

Hello, everyone! Are you sure that this is only on windows? I run redocly in docker with image redocly/cli:v1.0.0-beta.123 and I just got the same error.

@jeremyfiel
Copy link
Contributor

@tatomyr @lornajane any update on this one? It's still occurring for all examples with shared schemas. I'm on win 10.

@lornajane lornajane added the governance Issues relating to problems with or requests for API governance/linting/decorating label Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
governance Issues relating to problems with or requests for API governance/linting/decorating p2 Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants