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

Support for $ref tags/JSON schema in extension's package.json #95270

Closed
bryceitoc9 opened this issue Apr 14, 2020 · 10 comments
Closed

Support for $ref tags/JSON schema in extension's package.json #95270

bryceitoc9 opened this issue Apr 14, 2020 · 10 comments
Assignees
Labels
debt Code quality issues debug Debug viewlet, configurations, breakpoints, adapter issues
Milestone

Comments

@bryceitoc9
Copy link

I work on a VS Code Extension, and I'm following up on #95033 . It looks like this issue was caused by the fact that we were using a $ref field within the package.json manifest. This appears to be an invalid use of package.json, given the unusual behavior shown in #95033. Could you please explain whether or not this is valid in package.json?

To offer some insight, we have embedded a JSON Schema into the debugger contribution point. The motivation was to use a code generator against the JSON schema to ensure the extension code remains in sync with the structure defined in the manifest. If this scenario is not valid, we'd be interested in hearing a recommended way to keep the manifest and code structures in sync.

Thanks in advance!

@weinand
Copy link
Contributor

weinand commented Apr 15, 2020

@isidorn @aeschli we are combining the json schemas from all debuggers into a single schema and then use this for the launch.json editor. Are there any limitations what this schema can use? Or are we merging the fragments in a problematic way?

@weinand weinand removed their assignment Apr 15, 2020
@weinand weinand added the debug Debug viewlet, configurations, breakpoints, adapter issues label Apr 15, 2020
@weinand weinand added this to the April 2020 milestone Apr 15, 2020
@weinand weinand added the bug Issue identified by VS Code Team member as probable bug label Apr 15, 2020
@isidorn
Copy link
Contributor

isidorn commented Apr 15, 2020

Well the issue is probably due to the $ref field as @bryceitoc9 suggests.
@aeschli do you treat this $ref special in the json schema land? Was it always like this?

@aeschli
Copy link
Contributor

aeschli commented Apr 15, 2020

$ref can not be used in such schema fragment as the path is resolved against the composed schema that users don't know how it looks like and should not know.
Maybe in the future when we support using $id in $ref (#92042) this can be allowed.

@aeschli
Copy link
Contributor

aeschli commented Apr 15, 2020

Not a bug but a feature request.

@aeschli aeschli removed their assignment Apr 15, 2020
@awschristou
Copy link

It sounds like there is a restriction to not have $ref fields (and maybe embedded json schemas?) within the package.json file. Is this documented somewhere?

@weinand weinand assigned aeschli and unassigned isidorn Apr 16, 2020
@aeschli
Copy link
Contributor

aeschli commented Apr 16, 2020

@weinand This needs to be documented with the debuggers contributions point.
We already do the same for the configuration contributions point: https://code.visualstudio.com/api/references/contribution-points#Configuration-property-schema
(implicitly, by describing what is supported)

@aeschli aeschli assigned weinand and unassigned aeschli Apr 16, 2020
@weinand weinand added debt Code quality issues and removed bug Issue identified by VS Code Team member as probable bug labels Apr 16, 2020
@matepek
Copy link

matepek commented Apr 20, 2020

(implicitly, by describing what is supported)

From the site: https://code.visualstudio.com/api/references/contribution-points#Configuration-property-schema

Configuration keys are defined using a superset of JSON Schema.

You can use any the properties defined by JSON Schema to describe other constraints on configuration values.

Without ref I cannot define a recursive schema.

Do I miss something?😏

@weinand weinand modified the milestones: April 2020, May 2020 Apr 27, 2020
@aeschli
Copy link
Contributor

aeschli commented May 13, 2020

You can only use other properties that define a constraint.

I made this more explicit: microsoft/vscode-docs@7108f81

@weinand weinand modified the milestones: May 2020, June 2020 Jun 1, 2020
@weinand weinand modified the milestones: June 2020, On Deck Jun 29, 2020
@bwateratmsft
Copy link
Contributor

The Docker extension has a substantial amount of repetition in its package.json; this would be a very nice feature to have.

@bwateratmsft
Copy link
Contributor

Update since some folks might be interested. I found a rather hacky way to accomplish this--I tried it for settings but it may also work for tasks/launch configs as well. Please note, it only helps with the settings JSON editor, not in the settings UI (which will simply send you to the JSON).

You can use "$ref" if you feed it an absolute URI to a schemas file, but the scheme for that URI can be anything. It seems internally VSCode uses vscode://, for example. By registering a FileSystemProvider with a custom scheme (let's say, myschemas://), I was able to reference schema files from package.json and get working validation / autocomplete / etc.

Basically what I did is:

  1. Add an activation event in package.json, "onFileSystem:myschemas"
  2. Register said filesystem provider: vscode.workspace.registerFileSystemProvider("myschemas", new MySchemasFilesystemProvider())
  3. Implement just stat and readFile on MySchemasFilesystemProvider, using the extension install directory as the root (so your schemas.json file can be adjacent to your package.json)
  4. Have settings that use "$ref": "myschemas:///schemas.json#/definitions/mycomplexobjectdefn"

If there is already some built-in FileSystemProvider for getting at extension files, steps 1-3 could be skipped, but I'm not aware of one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues debug Debug viewlet, configurations, breakpoints, adapter issues
Projects
None yet
Development

No branches or pull requests

7 participants