Skip to content

Commit 0dc3749

Browse files
authored
Add support for yaml flow mapping and sequence (#94)
To test, copy package.json demo content to package.yaml editor Before: ![20240511-043150](https://github.com/acao/codemirror-json-schema/assets/11596445/95bac852-61cd-4323-900f-ae866e0fdb6e) It does not mark missing name and format errors in .contributors[0] After: ![20240511-043212](https://github.com/acao/codemirror-json-schema/assets/11596445/b452aac1-8a84-49a9-952d-809c17b62a12) Since yaml is a superset of json, I've also make all json validation test cases to be run under yaml mode.
1 parent f9308eb commit 0dc3749

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

.changeset/twelve-starfishes-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"codemirror-json-schema": patch
3+
---
4+
5+
Add support for YAML flow sequences and flow mappings

src/__tests__/json-validation.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const expectErrors = (
4141
};
4242

4343
describe("json-validation", () => {
44-
it.each([
44+
const jsonSuite = [
4545
{
4646
name: "provide range for a value error",
4747
mode: MODES.JSON,
@@ -137,6 +137,9 @@ describe("json-validation", () => {
137137
],
138138
schema: testSchema2,
139139
},
140+
];
141+
it.each([
142+
...jsonSuite,
140143
// JSON5
141144
{
142145
name: "provide range for a value error",
@@ -234,6 +237,7 @@ describe("json-validation", () => {
234237
schema: testSchema2,
235238
},
236239
// YAML
240+
...jsonSuite.map((t) => ({ ...t, mode: MODES.YAML })),
237241
{
238242
name: "provide range for a value error",
239243
mode: MODES.YAML,
@@ -286,8 +290,8 @@ object: {}
286290
`,
287291
errors: [
288292
{
289-
from: 13,
290-
to: 19,
293+
from: 21,
294+
to: 23,
291295
message: "The required property `foo` is missing at `object`",
292296
},
293297
],

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export const YAML_TOKENS_MAPPING: Record<
2525
Key: TOKENS.PROPERTY_NAME,
2626
BlockSequence: TOKENS.ARRAY,
2727
BlockMapping: TOKENS.OBJECT,
28+
FlowSequence: TOKENS.ARRAY,
29+
FlowMapping: TOKENS.OBJECT,
2830
QuotedLiteral: TOKENS.STRING,
2931
Literal: TOKENS.STRING, // best guess
3032
Stream: TOKENS.JSON_TEXT,

0 commit comments

Comments
 (0)