Skip to content

Commit

Permalink
feat: add json schema (#952)
Browse files Browse the repository at this point in the history
<!--
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 -->
  • Loading branch information
luckasRanarison authored Jan 9, 2025
1 parent c60f4ee commit 3d8dac2
Show file tree
Hide file tree
Showing 3 changed files with 384 additions and 0 deletions.
48 changes: 48 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions tests/tools/schema_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0

// NOTE: https://github.com/ajv-validator/ajv-formats/issues/85
import Ajv from "https://esm.sh/[email protected]";
import addFormats from "https://esm.sh/[email protected]";

import { parse } from "npm:yaml";
import schema from "@local/tools/schema/metatype.json" with { type: "json" };
import * as path from "@std/path";
import { assert } from "@std/assert";
import { Meta } from "test-utils/mod.ts";

const files = [
"../metatype.yml",
"../../examples/metatype.yaml",
"../../examples/templates/deno/metatype.yaml",
"../../examples/templates/node/metatype.yaml",
"../../examples/templates/python/metatype.yaml",
"../metagen/typegraphs/sample/metatype.yml",
"../metagen/typegraphs/identities/metatype.yml",
];

Meta.test("Configuration schema", () => {
const ajv = new Ajv();

addFormats(ajv);

const validate = ajv.compile(schema);
const scriptDir = import.meta.dirname!;

for (const file of files) {
const relativePath = path.resolve(scriptDir, file);
const yaml = Deno.readTextFileSync(relativePath);
const parsed = parse(yaml);
const result = validate(parsed);

assert(result, `validation failed for '${file}'`);
}
});
Loading

0 comments on commit 3d8dac2

Please sign in to comment.