vue-monaco icon indicating copy to clipboard operation
vue-monaco copied to clipboard

How to setup json schema?

Open ppasieka opened this issue 4 years ago • 4 comments

I'm trying to use my custom JSON schema in editor content but it doesn't work.

editorWillMount(monaco) {
        monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
          schemas: [
            {
              schema: schema  ///  from import
            }
          ]
        });
      },

What am I missing?

ppasieka avatar Apr 13 '20 18:04 ppasieka

I believe you need to set the fileMatch property of your schema, which will link it to your editor. I was able to do this using editorDidMount instead of editorWillMount. It is a little tricky since this method uses the editor. You can get the monaco module and the model from these lines, using a ref to your editor:

editorDidMount(editor) {
    const monaco = this.$refs.editor.monaco;
    const model = editor.getModel();
    
    monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
          validate: true,
          schemas: [{
              uri: "http://example.com/schema.json",
              fileMatch: [model.uri.toString()],
              schema: schema
          }]
      });
  }

I think the uri is also required for the schema to work.

lrduncan avatar Jun 10 '20 22:06 lrduncan

I am also trying to setup the schema. I did what @lrduncan suggested, but I don't get what is the uri for. What am I suposed to write there?

ODck avatar Nov 02 '20 11:11 ODck

This snippet doesn't work for me, I don't get any message error or anything, when I inspect monaco it is correctly registered in the diagnostic options but nothing happens after that

It's like nothing happened

noook avatar Nov 23 '21 16:11 noook

I get the same problem, and this snippet doesn't work for me too

shangliuyan avatar Feb 28 '22 04:02 shangliuyan