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] support setting schema associations at runtime #96120

Open
ayqy opened this issue Apr 25, 2020 · 7 comments
Open

[json] support setting schema associations at runtime #96120

ayqy opened this issue Apr 25, 2020 · 7 comments
Assignees
Labels
feature-request Request for new features or functionality json JSON support issues
Milestone

Comments

@ayqy
Copy link

ayqy commented Apr 25, 2020

Related PR: #73424
Related FR: #69868

Feature Request: Configure jsonValidation contribution point dynamically.
Use Case: Twin json files like myFile.json and myFile.js, which file name is the same as another file under the same directory, but file extension name is normal .json. So, glob matching or content detection does not work well, dynamic configuration is required.

@aeschli
Copy link
Contributor

aeschli commented Apr 27, 2020

How would the dynamic configurator know what schemes applies to which file?

@ayqy
Copy link
Author

ayqy commented Apr 27, 2020

In my case, there are some twin files like this:

.
├── project.json
└── src
    ├── foo.js
    ├── foo.json
    ├── bar.js
    ├── bar.json
    └── non-match.js

I wanna to configure a specified JSON Schema to validate foo.js and bar.js under my project (detected from project.json at project root folder).

As you see, static glob is not working. Any workarounds or a more graceful solution will be great as well.

@aeschli
Copy link
Contributor

aeschli commented Apr 27, 2020

One possible solution is to specify the schema in the JSON file
"$schema": "..."

@ayqy
Copy link
Author

ayqy commented Apr 27, 2020

Not really bad, but it's a little bit dirty for someone who reads and parses JSON key-values from the original file. And all consumers (such as our source code analysis service, native application...) have to take care of $schema from now on.

But anyway I think it's accepted for this case, so you can close this or take it into consideration for other clean approaches in the future. Thanks a lot.

@aeschli aeschli changed the title Configure JSON Schema dynamically [json] support setting schema associations at runtime May 6, 2020
@aeschli aeschli added feature-request Request for new features or functionality json JSON support issues labels May 6, 2020
@aeschli aeschli added this to the Backlog milestone May 6, 2020
@dsherret
Copy link

dsherret commented Aug 29, 2021

I have a use case for this. In my scenario, the schema of the JSON file changes based on the plugins specified, for example:

{
  "incremental": true,
  "lineWidth": 160,
  "json": {
    "indentWidth": 2,
  },
  "typescript": {
    "useTabs": true
  },
  "includes": [
    "**/*.{ts,tsx,js,jsx,json}"
  ],
  "plugins": [
    "https://plugins.dprint.dev/typescript-0.48.0.wasm",
    "https://plugins.dprint.dev/json-0.12.1.wasm"
  ]
}

Given the plugins specified, the schema of the plugin specific properties change (ex. in this case the "typescript" and "json" properties are added to the schema). I previously thought #98443 would solve my use case, but it has the problem of the "plugins" needing to be kept in sync with the "$schema" and it's annoying for the user to have to specify this.

Instead, it would be neat if the dprint vscode extension could programatically generate a schema based on the plugins in the plugins array and use that to help set the schema of the file (so this would be ideally programatically specified rather than a uri, but as a workaround I could create a web server route with some query parameters to make this work).

@aeschli
Copy link
Contributor

aeschli commented Aug 31, 2021

@dsherret What you want can be done with a programmatic schema. See #127812

@dsherret
Copy link

@aeschli oh great! That looks like it will work. Thanks so much!

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

3 participants