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

When the schema has required fields, unexpanded {} will not trigger validation, expanded {} can trigger validation #105

Open rookie-luochao opened 1 month ago

rookie-luochao commented 1 month ago
image image

my use schema:

{
    "type": "object",
    "properties": {
        "opsProjectID": {
            "type": "string",
            "description": "项目id",
            "x-go-field-name": "OpsProjectID",
            "x-tag-json": "opsProjectID"
        },
        "packageVersionID": {
            "type": "string",
            "description": "部署包版本id",
            "x-go-field-name": "PackageVersionID",
            "x-tag-json": "packageVersionID"
        },
        "remark": {
            "type": "string",
            "description": "发布描述",
            "x-go-field-name": "Remark",
            "x-tag-json": "remark"
        },
        "envs": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "agentID": {
                        "type": "string",
                        "description": "集群",
                        "x-go-field-name": "AgentID",
                        "x-tag-json": "agentID"
                    },
                    "copyAgentIDs": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        },
                        "description": "需要copy的集群集合\n\nApplicationTemplateInstanceSet []*ApplicationRelateTemplateAndInstance `json:\"applicationTemplateInstance,omitempty\"` // 服务模版实例关联",
                        "x-go-field-name": "CopyAgentIDs",
                        "x-tag-json": "copyAgentIDs,omitempty"
                    },
                    "namespace": {
                        "type": "string",
                        "description": "命名空间",
                        "x-go-field-name": "Namespace",
                        "x-tag-json": "namespace"
                    }
                },
                "required": [
                    "agentID",
                    "namespace"
                ],
                "x-id": "ApplyEnvRequest"
            },
            "description": "环境集合",
            "x-go-field-name": "Envs",
            "x-tag-json": "envs"
        }
    },
    "required": [
        "opsProjectID",
        "packageVersionID",
        "remark",
        "envs"
    ],
    "x-id": "CreateApplyParams",
    "x-go-field-name": "Body"
}

associate #99, this bug has not been resolved, unable to reopen bug

when the schema has required fields, expect that both unexpanded or expanded {} can trigger verification

rookie-luochao commented 1 month ago

@imolorhe please confirm this bug, thank you

imolorhe commented 1 month ago

Yes I can confirm it is still there. Looks like this isn't a bug but is intended? 🤔 cc @acao why do we not want to validate when the doc length is short? https://github.com/acao/codemirror-json-schema/blob/imolorhe/improve-completion/src/json-validation.ts#L131

imo an empty editor is also invalid but that should also be length of 0 after trimming 🤔

rookie-luochao commented 1 month ago

I think validation should be done when the document length is short, because it is easy for users to misunderstand that there is no difference between expanding and not expanding null map

rookie-luochao commented 1 month ago

monaco-editor will also prompt and verify when the map is not expanded,you can try it on monaco-editor. @imolorhe @acao

acao commented 1 month ago

agreed on all of this, short documents should be validated, i think we should only check to avoid validating for an an empty string.

rookie-luochao commented 1 month ago

Maybe you need to verify it with the test schema data I gave you. It seems that this bug has not been solved. When you enter {}, the verification still cannot be triggered @acao @imolorhe

acao commented 1 month ago

@rookie-luochao the issue i fixed was with the text document validation length, did that not solve your issue?

rookie-luochao commented 1 month ago

@rookie-luochao the issue i fixed was with the text document validation length, did that not solve your issue?

I saw your modification, but using the schema I provided, the same problem still occurs. {} still cannot trigger validation, but { } can trigger validation, and line breaks {} can also trigger validation

Seems to have removed < 3 Fixes some issues, But not completely