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

Items in array are not properly generated #6

Open
georgebancila opened this issue Jun 12, 2019 · 0 comments
Open

Items in array are not properly generated #6

georgebancila opened this issue Jun 12, 2019 · 0 comments

Comments

@georgebancila
Copy link

If I have an array with 2 objects that have different properties it generates a item that resembles only the first object. The test json is this:

{
  "data": [
    {
      "id": "1",
      "type": "type1",
      "attributes": {
        "message": "Message",
        "status": "pending"
      }
    },
    {
      "id": "2",
      "something": "typ2",
      "attributes": {
        "name": "Name1",
        "activity": "None"
      }
    }
  ]
}

If I generate the schema with version draft3 I get this:

{
  "$schema": "http://json-schema.org/draft-03/schema#",
  "description": "Generated from /web/app/shared/notifications/responses/get_notifications.json with shasum db9e033f3530d2420c527de7bf2c611551a61c23",
  "type": "object",
  "required": true,
  "properties": {
    "data": {
      "type": "array",
      "required": true,
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "required": true,
        "properties": {
          "id": {
            "type": "string",
            "required": true
          },
          "type": {
            "type": "string",
            "required": false
          },
          "attributes": {
            "type": "object",
            "required": true,
            "properties": {
              "message": {
                "type": "string",
                "required": true
              },
              "status": {
                "type": "string",
                "required": true
              }
            }
          }
        }
      }
    }
  }
}

As you can see it completely ignores the second object in the array.
If I generate it with schema4 I get this:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "Generated from /web/app/shared/notifications/responses/get_notifications.json with shasum db9e033f3530d2420c527de7bf2c611551a61c23",
  "type": "object",
  "required": [
    "data"
  ],
  "properties": {
    "data": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "required": [
          "id",
          "attributes"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "attributes": {
            "type": "object",
            "required": [
              "message",
              "status",
              "name",
              "activity"
            ],
            "properties": {
              "message": {
                "type": "string"
              },
              "status": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}

The generated schema sees the attributes of the second object and has them as required but does not specify them in the properties. And it completely ignores the 'type' and 'something' attributes in both objects.

Am I missing something here?

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