redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

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

Open aviskase opened this issue 3 years ago • 9 comments

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

> [email protected] 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 avatar Jul 23 '21 19:07 aviskase

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.

aviskase avatar Jul 23 '21 19:07 aviskase

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

slavikbez avatar Nov 08 '21 06:11 slavikbez

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 avatar Jan 27 '22 14:01 tatomyr

@tatomyr any news on this one?

jeremyfiel avatar Oct 26 '22 18:10 jeremyfiel

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

tatomyr avatar Oct 31 '22 10:10 tatomyr

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

laellyo avatar Jan 13 '23 15:01 laellyo

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.

tatomyr avatar Jan 23 '23 10:01 tatomyr

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.

morozovcookie avatar Feb 03 '23 18:02 morozovcookie

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

jeremyfiel avatar Oct 23 '23 14:10 jeremyfiel