schema icon indicating copy to clipboard operation
schema copied to clipboard

feat: Add $schema property to schema

Open pke opened this issue 4 years ago • 5 comments

What this PR does / why we need it:

VS Code supports code completion for JSON files based on JSON Schema.

Code completion in VS Code picks up a schema for any JSON file if the schema is specified as "$schema": "<URL to schema>".

It automatically picks up certain JSON Schemas by file name (ie: package.json) and you can configure your own associations via (workspace) settings.json like this:

"json.schemas": [
  {
    "fileMatch": [
      "resume.json"
    ],
    "url": "http://json.schemastore.org/resumic-schema.json"
  }
]

Alternatively VS Code supports the $schema key in JSON files itself.

So in a resume.json we could add the JSON Resumic schema to get code completion without touching the VS Code settings:

{
  "$schema": "http://json.schemastore.org/resumic-schema.json",

}

XML had a similar feature where you could specify an XSD in the XML pre-processing tags to validate the syntax and data (to some extent) of the XML.

Release note:

Add `$schema` property to resumic JSON schema to allow editors like VS Code to offer validation and triggering suggestions.

pke avatar Oct 27 '19 20:10 pke

Great idea. Will look into how this would be possible with a redirect as well.

For the failing tests: We use go as the single source of truth and generate the schema.json as well as the examples from Go. Changing the schema.json itself won't work. If you can update this, would be awesome.

stp-ip avatar Oct 27 '19 22:10 stp-ip

This will take me some time, since I am not familiar with go.

pke avatar Oct 27 '19 23:10 pke

Everything schema specific is within https://github.com/resumic/schema/blob/master/schema/schema.go. It's mostly just around creating the specific struct within go that gets output to a json schema etc. Happy to help and take the time you need.

stp-ip avatar Oct 28 '19 00:10 stp-ip

@stp-ip Which call generates the JSON Schema so I can check it locally before updating this PR?

pke avatar Oct 28 '19 14:10 pke

We have a makefile that should test the integrity of the json schema as well as the overlap with the generated examples etc. make test should give some helpful output.

For the general CLI resumic -h should help navigation. To check a specific resume against the schema: resumic validate --resume=myresume.json

stp-ip avatar Oct 28 '19 18:10 stp-ip