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

How to setup json schema? #97

Open
ppasieka opened this issue Apr 13, 2020 · 4 comments
Open

How to setup json schema? #97

ppasieka opened this issue Apr 13, 2020 · 4 comments

Comments

@ppasieka
Copy link

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?

@lrduncan
Copy link

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.

@ODck
Copy link

ODck commented Nov 2, 2020

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?

@noook
Copy link

noook commented Nov 23, 2021

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

@shangliuyan
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants