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

[json] $ref breaks validation of additionalItems #69071

Closed
openreply-dleinhaeuser opened this issue Feb 20, 2019 · 1 comment · Fixed by microsoft/vscode-json-languageservice#69
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug json JSON support issues verified Verification succeeded
Milestone

Comments

@openreply-dleinhaeuser
Copy link

openreply-dleinhaeuser commented Feb 20, 2019

  • VSCode Version: 1.31.1
  • OS Version: macOS 10.14.2

Steps to Reproduce:

  1. Create a JSON-Schema where a $ref is used inside additionalItems
{
  "type": "array",
  "items": [
    {
      "type": "string"
    }
  ],
  "additionalItems": {
    "$ref": "#/definitions/Number"
  },
  "definitions": {
    "Number": {
      "type": "integer"
    }
  }
}
  1. Create a JSON file where the additional items in the array do not conform to the schema
[
  "A string",
  "Definitely not an integer"
]
  1. Set VSCode up to validate the JSON file against the schema

Expected result:

Squiggly lines below the second item in the array.

Actual result:

JSON file passes validation

Does this issue occur when all extensions are disabled?: Yes

@vscodebot vscodebot bot added the json JSON support issues label Feb 20, 2019
@aeschli aeschli changed the title $ref breaks validation of additionalItems [json] $ref breaks validation of additionalItems Feb 21, 2019
@aeschli aeschli added the bug Issue identified by VS Code Team member as probable bug label Feb 21, 2019
@aeschli aeschli modified the milestones: Backlog, On Deck Feb 21, 2019
@paillave
Copy link

paillave commented Nov 1, 2019

Any news about this bug?

actually anything that is in additionalItems that is not "true" or a simple type ("number", "string", etc...) is ignored. Type "object" with its properties, or a reference is just ignored.

At my side

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Container",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "Stream": {
      "$ref": "#/definitions/Stream"
    }
  },
  "definitions": {
    "Stream": {
      "type": [
        "array"
      ],
      "items": [
        {
          "$ref": "#/definitions/Input"
        }
      ],
      "additionalItems": {
        "$ref": "#/definitions/Pipe"
      }
    },
    "Input": {
      "type": "object",
      "oneOf": [
        {
          "$ref": "#/definitions/Input1"
        },
        {
          "$ref": "#/definitions/Input2"
        }
      ]
    },
    "Input1": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Type": {
          "type": "string",
          "enum": [
            "Input1"
          ]
        },
        "Prop1": {
          "type": "integer",
          "format": "int32"
        },
        "Name": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "Input2": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Type": {
          "type": "string",
          "enum": [
            "Input2"
          ]
        },
        "Prop2": {
          "type": "integer",
          "format": "int32"
        },
        "Name": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "Pipe": {
      "type": "object",
      "oneOf": [
        {
          "$ref": "#/definitions/Pipe1"
        },
        {
          "$ref": "#/definitions/Pipe2"
        }
      ]
    },
    "Pipe1": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Type": {
          "type": "string",
          "enum": [
            "Pipe1"
          ]
        },
        "NumberOfLegs": {
          "type": "integer",
          "format": "int32"
        },
        "Name": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "Pipe2": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Type": {
          "type": "string",
          "enum": [
            "Pipe2"
          ]
        },
        "NumberOfWings": {
          "type": "integer",
          "format": "int32"
        },
        "Name": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}

validated json that should not be accepted:

{
    "Stream": [
        {
            "Type": "Input1",
            "Name": "qsdfgf",
            "Prop1": 45
        },
        "not only these is no intellisense",
        "but it also validates!",
        {
            "prop1": "anything",
            "prop2": "is validated"
        },
        54
    ]
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug json JSON support issues verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants