jsonnext / codemirror-json-schema

A JSONSchema enabled mode for codemirror 6, for json4 and json5, inspired by monaco-json
https://codemirror-json-schema.netlify.app
MIT License
56 stars 9 forks source link

jsonschema rules for array type does not get all applied during validation #89

Closed rafaellichen closed 1 month ago

rafaellichen commented 3 months ago

the json schema definition:

{
    "type": "object",
    "definitions": {
        "type": {
            "type": "string",
            "enum": [
                "object",
                "boolean",
                "integer",
                "number",
                "string"
            ]
        },
        "enum": {
            type: "array",
            uniqueItems: true,
            items: { type: "string" },
            minItems: 1,
        }
    },
    "properties": {
        "type": {
            "$ref": "#/definitions/type"
        },
        "enum": {
            "$ref": "#/definitions/enum"
        }
    },
    "patternProperties": {
        "^.*$": {
            "properties": {
                "type": {
                    "$ref": "#/definitions/type"
                },
                "enum": {
                    "$ref": "#/definitions/enum"
                }
            },
            "additionalProperties": {
                "$ref": "#"
            }
        }
    }
}

and how i initialized the editor

const state = EditorState.create({
    doc: doc,
    extensions: [
        minimalSetup,
        lineNumbers(),
        bracketMatching(),
        closeBrackets(),
        linter(jsonParseLinter(), { delay: 0 }),
        lintGutter(),
        keymap.of([indentWithTab]),
        indentUnit.of("    "),
        json(),
        onUpdate,
        jsonSchema(...);
    ]
})

the enum array is not being fully validated, enum: type: array and enum: minItems: 1 work, but enum: uniqueItems: true and enum: items: type: string are not being enforced.

image
acao commented 1 month ago

ah, we don't have any tests covering patternProperties yet, let me add some and see what I get

rafaellichen commented 1 month ago

thanks. confirm fixed.