Skip to content

Commit

Permalink
Add support for yaml flow mapping and sequence (#94)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xdavidwu committed May 11, 2024
1 parent f9308eb commit 0dc3749
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-starfishes-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"codemirror-json-schema": patch
---

Add support for YAML flow sequences and flow mappings
10 changes: 7 additions & 3 deletions src/__tests__/json-validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const expectErrors = (
};

describe("json-validation", () => {
it.each([
const jsonSuite = [
{
name: "provide range for a value error",
mode: MODES.JSON,
Expand Down Expand Up @@ -137,6 +137,9 @@ describe("json-validation", () => {
],
schema: testSchema2,
},
];
it.each([
...jsonSuite,
// JSON5
{
name: "provide range for a value error",
Expand Down Expand Up @@ -234,6 +237,7 @@ describe("json-validation", () => {
schema: testSchema2,
},
// YAML
...jsonSuite.map((t) => ({ ...t, mode: MODES.YAML })),
{
name: "provide range for a value error",
mode: MODES.YAML,
Expand Down Expand Up @@ -286,8 +290,8 @@ object: {}
`,
errors: [
{
from: 13,
to: 19,
from: 21,
to: 23,
message: "The required property `foo` is missing at `object`",
},
],
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const YAML_TOKENS_MAPPING: Record<
Key: TOKENS.PROPERTY_NAME,
BlockSequence: TOKENS.ARRAY,
BlockMapping: TOKENS.OBJECT,
FlowSequence: TOKENS.ARRAY,
FlowMapping: TOKENS.OBJECT,
QuotedLiteral: TOKENS.STRING,
Literal: TOKENS.STRING, // best guess
Stream: TOKENS.JSON_TEXT,
Expand Down

0 comments on commit 0dc3749

Please sign in to comment.