microsoft/vscode-json-languageservice

$ref is not resolved when referencing existing property

DaveChintan opened this issue · 1 comments

  • VS Code Version: 1.71.2
  • OS Version: Windows_NT x64 10.0.19044

Steps To Reproduce

  1. Json Schema tried
 {
	"$id": "company_name#",
	"$schema": "http://json-schema.org/draft-07/schema",
	"description": "A representation of a resource",
	"type": "object",
	"additionalProperties": true,
	"$defs": {
		"Resource1": {
			"$id": "/schemas/Resource1",
			"$schema": "http://json-schema.org/draft-07/schema#",
			"type": "object",
			"required": [
				"Property1",
				"Property2"
			],
			"properties": {
				"Property1": {
					"type": "string",
					"enum": [
						"true",
						"false"
					]
				},
				"Property2": {
					"type": "string",
					"enum": [
						"true",
						"false"
					]
				}
			}
		},
		"Resource2": {
			"$id": "/schemas/Resource2",
			"$schema": "http://json-schema.org/draft-07/schema#",
			"type": "object",
			"required": [
				"Property1",
				"Property2"
			],
			"properties": {
				"Property1": {
					"type": "string",
					"enum": [
						"1",
						"2"
					]
				},
				"Property2": {
					"type": "string",
					"enum": [
						"val1",
						"val2"
					]
				}
			}
		}
	},
	"required": [
		"Resources"
	],
	"properties": {
		"Resources": {
			"type": "object",
			"additionalProperties": true,
			"patternProperties": {
				"^[a-zA-Z0-9]+$": {
					"type": "object",
					"additionalProperties": true,
					"properties": {
						"Name": {
							"Type": "string",
							"description": "Name of resource"
						},
						"Type": {
							"Type": "string",
							"description": "Type of resource",
							"enum": [
								"Resource1",
								"Resource2"
							]
						},
						"Properties": {
							"$vars": {
								"resourcetype": {
									"$ref": "1/Type",
									"default": "Resource1"
								}
							},
							"type": "string",
							"$ref": "#/$defs/{+resourcetype}",
							"additionalProperties": true
						}
					}
				}
			}
		}
	}
}

$ref should be resolved based on referenced property value. (https://opis.io/json-schema/2.x/variables.html)

It should be noted that this is an implementation-specific behavior and not something defined by JSON Schema. "#/$defs/{+resourcetype}" is an invalid reference and should error.