Skip to content

Commit 515107b

Browse files
fix: use reference to the json-schema draft-07 in monaco editor (#159)
1 parent 7605220 commit 515107b

File tree

2 files changed

+181
-1
lines changed

2 files changed

+181
-1
lines changed
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/* eslint-disable sonarjs/no-duplicate-string */
2+
export default {
3+
$schema: 'http://json-schema.org/draft-07/schema#',
4+
$id: 'http://json-schema.org/draft-07/schema#',
5+
title: 'Core schema meta-schema',
6+
definitions: {
7+
schemaArray: {
8+
type: 'array',
9+
minItems: 1,
10+
items: { $ref: '#' }
11+
},
12+
nonNegativeInteger: {
13+
type: 'integer',
14+
minimum: 0
15+
},
16+
nonNegativeIntegerDefault0: {
17+
allOf: [
18+
{ $ref: '#/definitions/nonNegativeInteger' },
19+
{ default: 0 }
20+
]
21+
},
22+
simpleTypes: {
23+
enum: [
24+
'array',
25+
'boolean',
26+
'integer',
27+
'null',
28+
'number',
29+
'object',
30+
'string'
31+
]
32+
},
33+
stringArray: {
34+
type: 'array',
35+
items: { type: 'string' },
36+
uniqueItems: true,
37+
default: []
38+
}
39+
},
40+
type: ['object', 'boolean'],
41+
properties: {
42+
$id: {
43+
type: 'string',
44+
format: 'uri-reference'
45+
},
46+
$schema: {
47+
type: 'string',
48+
format: 'uri'
49+
},
50+
$ref: {
51+
type: 'string',
52+
format: 'uri-reference'
53+
},
54+
$comment: {
55+
type: 'string'
56+
},
57+
title: {
58+
type: 'string'
59+
},
60+
description: {
61+
type: 'string'
62+
},
63+
default: true,
64+
readOnly: {
65+
type: 'boolean',
66+
default: false
67+
},
68+
writeOnly: {
69+
type: 'boolean',
70+
default: false
71+
},
72+
examples: {
73+
type: 'array',
74+
items: true
75+
},
76+
multipleOf: {
77+
type: 'number',
78+
exclusiveMinimum: 0
79+
},
80+
maximum: {
81+
type: 'number'
82+
},
83+
exclusiveMaximum: {
84+
type: 'number'
85+
},
86+
minimum: {
87+
type: 'number'
88+
},
89+
exclusiveMinimum: {
90+
type: 'number'
91+
},
92+
maxLength: { $ref: '#/definitions/nonNegativeInteger' },
93+
minLength: { $ref: '#/definitions/nonNegativeIntegerDefault0' },
94+
pattern: {
95+
type: 'string',
96+
format: 'regex'
97+
},
98+
additionalItems: { $ref: '#' },
99+
items: {
100+
anyOf: [
101+
{ $ref: '#' },
102+
{ $ref: '#/definitions/schemaArray' }
103+
],
104+
default: true
105+
},
106+
maxItems: { $ref: '#/definitions/nonNegativeInteger' },
107+
minItems: { $ref: '#/definitions/nonNegativeIntegerDefault0' },
108+
uniqueItems: {
109+
type: 'boolean',
110+
default: false
111+
},
112+
contains: { $ref: '#' },
113+
maxProperties: { $ref: '#/definitions/nonNegativeInteger' },
114+
minProperties: { $ref: '#/definitions/nonNegativeIntegerDefault0' },
115+
required: { $ref: '#/definitions/stringArray' },
116+
additionalProperties: { $ref: '#' },
117+
definitions: {
118+
type: 'object',
119+
additionalProperties: { $ref: '#' },
120+
default: {}
121+
},
122+
properties: {
123+
type: 'object',
124+
additionalProperties: { $ref: '#' },
125+
default: {}
126+
},
127+
patternProperties: {
128+
type: 'object',
129+
additionalProperties: { $ref: '#' },
130+
propertyNames: { format: 'regex' },
131+
default: {}
132+
},
133+
dependencies: {
134+
type: 'object',
135+
additionalProperties: {
136+
anyOf: [
137+
{ $ref: '#' },
138+
{ $ref: '#/definitions/stringArray' }
139+
]
140+
}
141+
},
142+
propertyNames: { $ref: '#' },
143+
const: true,
144+
enum: {
145+
type: 'array',
146+
items: true,
147+
minItems: 1,
148+
uniqueItems: true
149+
},
150+
type: {
151+
anyOf: [
152+
{ $ref: '#/definitions/simpleTypes' },
153+
{
154+
type: 'array',
155+
items: { $ref: '#/definitions/simpleTypes' },
156+
minItems: 1,
157+
uniqueItems: true
158+
}
159+
]
160+
},
161+
format: { type: 'string' },
162+
contentMediaType: { type: 'string' },
163+
contentEncoding: { type: 'string' },
164+
if: { $ref: '#' },
165+
then: { $ref: '#' },
166+
else: { $ref: '#' },
167+
allOf: { $ref: '#/definitions/schemaArray' },
168+
anyOf: { $ref: '#/definitions/schemaArray' },
169+
oneOf: { $ref: '#/definitions/schemaArray' },
170+
not: { $ref: '#' }
171+
},
172+
default: true
173+
};

src/services/monaco.service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import * as monacoAPI from 'monaco-editor/esm/vs/editor/editor.api';
77
import { SpecificationService } from './specification.service';
88
import state from '../state';
99

10+
import jsonSchemaDraft07 from './json-schema.draft-07';
11+
1012
export class MonacoService {
1113
private static actualVersion = 'X.X.X';
1214
private static Monaco: any = null;
@@ -45,10 +47,15 @@ export class MonacoService {
4547
completion: true,
4648
schemas: [
4749
{
48-
uri: 'https://www.asyncapi.com/', // id of the schema
50+
uri: 'https://www.asyncapi.com/', // id of the AsyncAPI spec schema
4951
fileMatch: ['*'], // associate with all models
5052
schema: specs[String(asyncAPIVersion)],
5153
},
54+
{
55+
uri: jsonSchemaDraft07.$id, // id of the draft-07 schema
56+
fileMatch: ['*'], // associate with all models
57+
schema: jsonSchemaDraft07,
58+
}
5259
],
5360
} as any;
5461
}

0 commit comments

Comments
 (0)