sample.js 1.0 KB

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