Skip to content

Commit 3d8dac2

Browse files
feat: add json schema (#952)
<!-- Pull requests are squashed and merged using: - their title as the commit message - their description as the commit body Having a good title and description is important for the users to get readable changelog. --> <!-- 1. Explain WHAT the change is about --> - Add a self-hosted json schema that will be referenced to [schemastore](https://www.schemastore.org/json/), part of [MET-798](https://linear.app/metatypedev/issue/MET-798/metatype-schema-for-ide-support). <!-- 3. Explain HOW users should update their code --> #### Migration notes --- - [x] The change comes with new or modified tests - [ ] Hard-to-understand functions have explanatory comments - [ ] End-user documentation is updated to reflect the change <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added comprehensive configuration schema validation for Metatype system configuration files. - Implemented JSON schema testing to ensure configuration integrity across multiple YAML files. - **Tests** - Introduced new test suite for validating configuration schema using Ajv JSON schema validator. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c60f4ee commit 3d8dac2

File tree

3 files changed

+384
-0
lines changed

3 files changed

+384
-0
lines changed

deno.lock

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tools/schema_test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
// NOTE: https://github.com/ajv-validator/ajv-formats/issues/85
5+
import Ajv from "https://esm.sh/[email protected]";
6+
import addFormats from "https://esm.sh/[email protected]";
7+
8+
import { parse } from "npm:yaml";
9+
import schema from "@local/tools/schema/metatype.json" with { type: "json" };
10+
import * as path from "@std/path";
11+
import { assert } from "@std/assert";
12+
import { Meta } from "test-utils/mod.ts";
13+
14+
const files = [
15+
"../metatype.yml",
16+
"../../examples/metatype.yaml",
17+
"../../examples/templates/deno/metatype.yaml",
18+
"../../examples/templates/node/metatype.yaml",
19+
"../../examples/templates/python/metatype.yaml",
20+
"../metagen/typegraphs/sample/metatype.yml",
21+
"../metagen/typegraphs/identities/metatype.yml",
22+
];
23+
24+
Meta.test("Configuration schema", () => {
25+
const ajv = new Ajv();
26+
27+
addFormats(ajv);
28+
29+
const validate = ajv.compile(schema);
30+
const scriptDir = import.meta.dirname!;
31+
32+
for (const file of files) {
33+
const relativePath = path.resolve(scriptDir, file);
34+
const yaml = Deno.readTextFileSync(relativePath);
35+
const parsed = parse(yaml);
36+
const result = validate(parsed);
37+
38+
assert(result, `validation failed for '${file}'`);
39+
}
40+
});

0 commit comments

Comments
 (0)