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

Invalid json-schema objects are generated #42

Open
ershov-konst opened this issue Jul 6, 2022 · 0 comments
Open

Invalid json-schema objects are generated #42

ershov-konst opened this issue Jul 6, 2022 · 0 comments

Comments

@ershov-konst
Copy link

Description

If an object contains two or more properties with the same complex type, generated json-schema object is invalid.

Example

openapi.json

{
  "swagger": "2.0",
  "info": {
    "title": "Test API",
    "version": "{{version}}"
  },
  ...
  "paths": {
    "/foo/api": {
      "get": {
        "summary": "GET /foo/api",
        "description": "GET /foo/api",
        "operationId": "GET--foo-api",
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "$ref": "#/definitions/TestResponse"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "TestResponse": {
      "type": "object",
      "properties": {
        "a": {
          "$ref": "#/definitions/CommonDefinition"
        },
        "b": {
          "$ref": "#/definitions/CommonDefinition"
        }
      }
    },
    "CommonDefinition": {
      "type": "object",
      "properties": {
        "foo": {
          "type": "string"
        }
      }
    }
  }
}

After compilation we receive following json-scheme object

{
  type: "object",
  properties: { 
    a: {
      type: "object",
      properties: { 
        foo: { 
          type: "string" 
        } 
      },
      $id: "default_CommonDefinition"
    }, 
    b: {
      type: "object",
      properties: { 
        foo: { 
          type: "string" 
        } 
      },
      $id: "default_CommonDefinition"
    }
  },
  $id: "default_TestResponse"
}

The problem is using the $id keyword that identifies a schema resource.

If you try to validate the object described below using ajv package, you will receive the following exception

Error: reference "#default_CommonDefinition" resolves to more than one schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant