如何在IntelliJ中验证project.json文件的JSON模式?

huangapple go评论48阅读模式
英文:

How to validate json schema of project.json files in IntelliJ?

问题

在nx的project.json文件中,我们有一个像这样的$schema规范。

{
  "$schema": "../../../../node_modules/nx/schemas/project-schema.json"
}

该模式文件存在,但IntelliJ不会验证该文件。

我们如何配置IntelliJ以使用指定的模式进行验证?

请注意,我们不能简单地使用映射,因为相对路径可能不同,取决于project.json文件的位置,例如也可能是"/../../node_modules/nx/schemas/project-schema.json"

英文:

in the nx project.json files, we have a $schema specification like this.

{
  "$schema": "../../../../node_modules/nx/schemas/project-schema.json"
}

That schema-file exists, but IntelliJ does not validate the file.

How can we configure IntelliJ to use the specified schema for validation?

Note, that we cannot simply use a mapping, because the relative path can be different, depending on the location of the project.json file: i.e. it may also be "/../../node_modules/nx/schemas/project-schema.json"

答案1

得分: 0

"$schema": "file://../../../../node_modules/nx/schemas/project-schema.json"

或者

"$schema": "file://node_modules/nx/schemas/project-schema.json"

这样它就成为一个合法的 URL,IDE 可以从中获取信息。

编辑:另一种方法是在 IDE 中手动配置映射,这样您就不必依赖 $schema 关键字。截图:

如何在IntelliJ中验证project.json文件的JSON模式?

英文:

I suggest trying

"$schema": "file://../../../../node_modules/nx/schemas/project-schema.json"

or "$schema": "file://node_modules/nx/schemas/project-schema.json"

so that it is a proper URL where the IDE can fetch from.

Edit: an other approach can be configuring the mapping manually in the IDE, so that you don't rely on the $schema keyword. Screenshot:

如何在IntelliJ中验证project.json文件的JSON模式?

huangapple
  • 本文由 发表于 2023年6月5日 20:22:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76406367.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定