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] Override/disable json-schema for package.json #74943

Open
Forlini91 opened this issue Jun 6, 2019 · 7 comments
Open

[json] Override/disable json-schema for package.json #74943

Forlini91 opened this issue Jun 6, 2019 · 7 comments
Assignees
Labels
feature-request Request for new features or functionality json JSON support issues
Milestone

Comments

@Forlini91
Copy link

I would like to override the default json-schema used by VSCode on some files with my own json-schema (example: VSCode use a json-schema for the Node's "package.json", but I want to be able to override it), like when configuring any other json-schema in settings.json:

//settings.json - currently this doesn't work and VSCode keep applying the Node's package.json json-schema
"json.schemas": [{
	"fileMatch": ["*/package.json"],
	"url": "./schemas/package.json"
}]

Reason is: I'm working on a project where there's a file called "package.json" which is not related to Node: it's something completely different and internal to the project, and it's not even in the root directory, but I can't rename it and VSCode wrongly use the Node's json-schema and everything become an error.

@Forlini91 Forlini91 changed the title Override/disable intellisense for Package.json Override/disable json-schema for Package.json Jun 6, 2019
@vscodebot vscodebot bot added the json JSON support issues label Jun 6, 2019
@Forlini91 Forlini91 changed the title Override/disable json-schema for Package.json Override/disable json-schema for package.json Jun 6, 2019
@aeschli aeschli added this to the Backlog milestone Sep 5, 2019
@aeschli aeschli added the feature-request Request for new features or functionality label Sep 5, 2019
@aeschli aeschli changed the title Override/disable json-schema for package.json [json] Override/disable json-schema for package.json Sep 5, 2019
@snayam
Copy link

snayam commented Dec 4, 2019

+1

I want to override json schema for package.json to resolve an incorrect type for "bundleDependencies" property, issue /schemastore/issues/876.

To do that i try to use a local schema with custom definition for bundledDependency :

"json.schemas": [{
	"fileMatch": ["/package.json"],
	"url": "./schema/package.json"
}]

My local file is correctly mapped but it doesn't override the default schema, both are loaded, which causes a conflict. Indeed, i can see the package.json try to resolve the rules of my custom schema and those of the default schema.

Default schema in vscode is mapped in ./extensions/npm/package.json :

"jsonValidation": [{
      "fileMatch": "package.json",
      "url": "https://schemastore.azurewebsites.net/schemas/json/package.json"
    }, 

If i delete this (or replace it by my custom file path) and i refresh vscode cache, it works .... But i'm waiting a better solution.

Thanks.

@wayneashleyberry
Copy link

I just ran into this same situation, but when adding a custom schema for values.yaml which the Kubernetes extension seems to have already claimed. So my custom schema doesn't seem to be applying to files with that name at all, or they're being merged.

@feryardiant
Copy link

I am not sure is my situation related with this issue, but I can get any files under .github/workflows directory validated correctly if it have the same name with another tool's config file. E.g deploy.yml (deployer), build.yml (hammerkit), etc

DtSQfQ3DlB

I've tried to add this to my settings.json, but no luck

{
  "json.schemas": [
    {
      "fileMatch": [
        ".github/workflows/*.yml"
      ],
      "url": "https://json.schemastore.org/github-workflow.json"
    }
  ]
}

@man90es
Copy link

man90es commented Sep 17, 2021

I just ran into the same problem as @feryardiant and managed to solve it by editing the yaml.schemas option (not json.schemas). And the correct syntax for it is as follows:

{
    "yaml.schemas": {
        "https://json.schemastore.org/github-workflow.json": ".github/workflows/**.yml"
    }
}

@feryardiant
Copy link

Awesome! Thank you @octoman90, I didn't realize that we could use that such format. Anyway,

I can confirm that your suggestion is working perfectly for per-project settings, but I can't get its working as global (workspace) settings.

@laverdet
Copy link

I'm also running into this. It's lousy that an extension which is installed by default cannot be disabled or overridden.

@lobsterkatie
Copy link

lobsterkatie commented Mar 16, 2022

Bumping this - just ran into it today, same as @feryardiant, where my build.yml GitHub workflow file was convinced it had something to do with hammerkit, and therefore kept throwing errors. My experience with the workaround matches his, as well - I have to add it to the project settings for it to work.

(I am using version 1.65.1 on a Mac running Monterey 12.2.1)

lobsterkatie added a commit to getsentry/sentry-javascript that referenced this issue Mar 17, 2022
VSCode has a feature[1] wherein it auto-detects what schema to use to validate certain JSON and yml files. The problem is, sometimes it's wrong[2], and when it is, it will throw errors* because it's misconstrued what kind of file you're editing. The incorrect association can be overridden, though, with a correct association in settings.

This adds such an association, to prevent VSCode from complaining about our GHA `build` workflow.

*It correctly detects that it's a GHA config, but also checks it against the schema for a different build tool[3] called `hammerkit`, and throws errors because the two schemas are incompatible

[1] https://code.visualstudio.com/docs/languages/json#_json-schemas-and-settings
[2] microsoft/vscode#74943 (comment)
[3] https://no0dles.gitbook.io/hammerkit/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality json JSON support issues
Projects
None yet
Development

No branches or pull requests

8 participants