From 260f0da919a272081582d66f3d0f21956c099a3d Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 9 Aug 2021 21:32:40 +0200 Subject: [PATCH 1/3] Add a more advanced example value --- examples/webpack/src/index.js | 107 +++++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 21 deletions(-) diff --git a/examples/webpack/src/index.js b/examples/webpack/src/index.js index f37a163..1f55316 100644 --- a/examples/webpack/src/index.js +++ b/examples/webpack/src/index.js @@ -29,39 +29,55 @@ window.MonacoEnvironment = { setDiagnosticsOptions({ validate: true, enableSchemaRequest: true, + format: true, hover: true, completion: true, schemas: [ { // Id of the first schema - uri: 'http://myserver/foo-schema.json', + uri: 'https://example.com/example-schema.json', // Associate with our model fileMatch: ['*'], schema: { // Id of the first schema - id: 'http://myserver/foo-schema.json', + id: 'https://example.com/example-schema.json', type: 'object', properties: { - p1: { - enum: ['v1', 'v2'], + property: { + description: 'I have a description', }, - p2: { - // Reference the second schema - $ref: 'http://myserver/bar-schema.json', + titledProperty: { + title: 'I have a title', + description: 'I also have a description', }, - }, - }, - }, - { - // Id of the first schema - uri: 'http://myserver/bar-schema.json', - schema: { - // Id of the first schema - id: 'http://myserver/bar-schema.json', - type: 'object', - properties: { - q1: { - enum: ['x1', 'x2'], + markdown: { + markdownDescription: 'Even **markdown** _descriptions_ `are` ~~not~~ supported!', + }, + enum: { + description: 'Pick your started', + enum: ['Bulbasaur', 'Squirtle', 'Charmander', 'Pickachu'], + }, + number: { + description: 'Numbers work!', + minimum: 42, + maximum: 1337, + }, + boolean: { + description: 'Are boolean supported?', + type: 'boolean', + }, + string: { + type: 'string', + }, + reference: { + description: 'JSON schemas can be referenced, even recursively', + $ref: 'https://example.com/example-schema.json', + }, + array: { + description: 'It also works in arrays', + items: { + $ref: 'https://example.com/example-schema.json', + }, }, }, }, @@ -69,9 +85,58 @@ setDiagnosticsOptions({ ], }); +const value = ` +# Property descriptions are displayed when hovering over properties using your cursor +property: This property has a JSON schema description + + +# Titles work too! +titledProperty: Titles work too! + + +# Even markdown descriptions work +markdown: hover me to get a markdown based description 😮 + + +# Enums can be autocompleted by placing the cursor after the colon and pressing Ctrl+Space +enum: + + +# Of course numbers are supported! +number: 12 + + +# As well as booleans! +boolean: true + + +# And strings +string: I am a string + + +# This property is using the JSON schema recursively +reference: + boolean: Not a boolean + + +# Also works in arrays +array: + - string: 12 + enum: Mewtwo + + +formatting: Formatting is supported too! Under the hood this is powered by Prettier. Just press Ctrl+Shift+I or right click and press Format to format this document. + + + + + + +`.replace(/:$/m, ': '); + editor.create(document.getElementById('editor'), { automaticLayout: true, - value: 'p1: ', + value, language: 'yaml', theme: window.matchMedia('(prefers-color-scheme: dark)').matches ? 'vs-dark' : 'vs-light', }); From b42b0b6af48cbd1c481c3eb34b5c20c0e9be1e92 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 9 Aug 2021 22:30:08 +0200 Subject: [PATCH 2/3] Update examples/webpack/src/index.js Co-authored-by: fleonus --- examples/webpack/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/webpack/src/index.js b/examples/webpack/src/index.js index 1f55316..0584010 100644 --- a/examples/webpack/src/index.js +++ b/examples/webpack/src/index.js @@ -54,7 +54,7 @@ setDiagnosticsOptions({ markdownDescription: 'Even **markdown** _descriptions_ `are` ~~not~~ supported!', }, enum: { - description: 'Pick your started', + description: 'Pick your starter', enum: ['Bulbasaur', 'Squirtle', 'Charmander', 'Pickachu'], }, number: { From 41d2b2e0c98c33ab638d48c0086d01fd2b3f2996 Mon Sep 17 00:00:00 2001 From: fleonus Date: Mon, 9 Aug 2021 22:31:30 +0200 Subject: [PATCH 3/3] Update examples/webpack/src/index.js --- examples/webpack/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/webpack/src/index.js b/examples/webpack/src/index.js index 0584010..a0fe3bc 100644 --- a/examples/webpack/src/index.js +++ b/examples/webpack/src/index.js @@ -55,7 +55,7 @@ setDiagnosticsOptions({ }, enum: { description: 'Pick your starter', - enum: ['Bulbasaur', 'Squirtle', 'Charmander', 'Pickachu'], + enum: ['Bulbasaur', 'Squirtle', 'Charmander', 'Pikachu'], }, number: { description: 'Numbers work!',