Is there any way to disable fetching based on the $schema field in Monaco editor?

Viewed 357

When setting the 'enableSchemaRequest' option to 'false', I get the warning:

Unable to load schema from '/do.not.load.me'. No schema request service available

Setting it to true gives the warning:

Unable to load schema from '/do.not.load.me': Failed to fetch.

How do I get Monaco to completely ignore the $schema field? I am supplying the schema manually so I don't want the editor to attempt to fetch over the internet.

Testing this behavior using: https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-configure-json-defaults

This question is not a duplicate of: Disable $schema JSON autocompletion with Monaco since I still want JSON schema functionality, just not based on the document's $schema field.

1 Answers

This seems to be a bug in Monaco v0.21.0+. The two ways around it I found were:

  1. Downgrade Monaco to v0.20.0
  2. Leave enableSchemaRequest as true, but create a fake schema URL using a blob:
const json = JSON.stringify(schema);
const blob = new Blob([json], {type: "application/json"});
const uri = URL.createObjectURL(blob);

Then set your $schema field to uri.

Related