sample.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Configures two JSON schemas, with references.
  2. var jsonCode = [
  3. '{',
  4. ' "p1": "v3",',
  5. ' "p2": false',
  6. "}"
  7. ].join('\n');
  8. var modelUri = monaco.Uri.parse("a://b/foo.json"); // a made up unique URI for our model
  9. var model = monaco.editor.createModel(jsonCode, "json", modelUri);
  10. // configure the JSON language support with schemas and schema associations
  11. monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
  12. validate: true,
  13. schemas: [{
  14. uri: "http://myserver/foo-schema.json", // id of the first schema
  15. fileMatch: [modelUri.toString()], // associate with our model
  16. schema: {
  17. type: "object",
  18. properties: {
  19. p1: {
  20. enum: ["v1", "v2"]
  21. },
  22. p2: {
  23. $ref: "http://myserver/bar-schema.json" // reference the second schema
  24. }
  25. }
  26. }
  27. }, {
  28. uri: "http://myserver/bar-schema.json", // id of the second schema
  29. schema: {
  30. type: "object",
  31. properties: {
  32. q1: {
  33. enum: ["x1", "x2"]
  34. }
  35. }
  36. }
  37. }]
  38. });
  39. monaco.editor.create(document.getElementById("container"), {
  40. model: model
  41. });