Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for yaml flow mapping and sequence #94

Merged
merged 3 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading