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

feat: add json schema #952

Merged
merged 4 commits into from
Jan 9, 2025
Merged

feat: add json schema #952

merged 4 commits into from
Jan 9, 2025

Conversation

luckasRanarison
Copy link
Contributor

@luckasRanarison luckasRanarison commented Jan 6, 2025

Migration notes


  • The change comes with new or modified tests
  • Hard-to-understand functions have explanatory comments
  • End-user documentation is updated to reflect the change

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.

Copy link

linear bot commented Jan 6, 2025

Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

📝 Walkthrough

Walkthrough

A new test file schema_test.ts has been introduced to validate configuration schemas using the Ajv JSON schema validator. The test focuses on verifying YAML configuration files against a predefined JSON schema (metatype.json). The validation process involves loading YAML files, parsing them, and checking their conformity to the specified schema structure. This ensures that configuration files meet the expected format and contain the required properties for the Metatype system.

Changes

File Change Summary
tests/tools/schema_test.ts New test file added to validate configuration schemas using Ajv JSON validator
tools/schema/metatype.json New JSON schema file defining configuration structure and validation rules for Metatype system

Sequence Diagram

sequenceDiagram
    participant Test as Schema Test
    participant Ajv as JSON Schema Validator
    participant YAML as YAML Parser
    participant Schema as Metatype Schema

    Test->>YAML: Read configuration files
    YAML-->>Test: Parse YAML to JavaScript objects
    Test->>Ajv: Create validator instance
    Test->>Schema: Load JSON schema
    Ajv->>Schema: Compile validation function
    Test->>Ajv: Validate each configuration
    Ajv-->>Test: Validation result
    alt Validation Fails
        Test->>Test: Throw assertion error
    else Validation Passes
        Test->>Test: Test complete
    end
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fe1151 and fb38905.

📒 Files selected for processing (1)
  • tools/schema/metatype.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/schema/metatype.json
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test-full
  • GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
  • GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
  • GitHub Check: pre-commit

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.72%. Comparing base (8c0022e) to head (fb38905).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #952   +/-   ##
=======================================
  Coverage   77.72%   77.72%           
=======================================
  Files         154      154           
  Lines       19154    19154           
  Branches     1930     1930           
=======================================
  Hits        14888    14888           
  Misses       4243     4243           
  Partials       23       23           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@luckasRanarison luckasRanarison marked this pull request as ready for review January 6, 2025 13:50
@luckasRanarison luckasRanarison requested a review from a team January 6, 2025 13:51
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
tests/tools/schema_test.ts (1)

25-29: Add custom loading or preprocessing if necessary.

While addFormats is sufficient for standard formats, you might need additional keywords or custom validations in the future. Keep an eye on the library's release notes for changes that affect specialized data types (URIs, UUIDs, etc.).

tools/schema/metatype.json (4)

21-35: Suggest adding descriptive examples.

It's often helpful to provide small example values for keys like include or exclude to guide users.

 "typegraphLoaderConfig": {
   "type": "object",
   "additionalProperties": false,
   "properties": {
+    "includeExample": {
+      "description": "Example patterns for include",
+      "example": ["**/*.tg", "typegraphs/**/*.yaml"]
+    },
     "include": {
       "$ref": "#/definitions/path",
       "description": "A pattern or array of patterns to include."
     },
     ...

36-56: Expand or unify generator base properties.

All generator config bases share some common aspects, but some are more specialized (e.g., Rust). Review if there's a possibility to unify them further or keep them separate by design.


190-234: Include flexible property fallback or official doc references.

You restrict additional properties for typegates. That helps keep the config strict, but if new features appear frequently, consider a fallback approach or a reference to official docs for new properties.


272-288: Solid definitions for metagen, but consider versioning.

Metagen configurations evolve quickly. If older config structures need to be supported, you may want to specify versioning or backward compatibility approach.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c0022e and 5fe1151.

⛔ Files ignored due to path filters (1)
  • deno.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • tests/tools/schema_test.ts (1 hunks)
  • tools/schema/metatype.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
  • GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
  • GitHub Check: test-full
  • GitHub Check: pre-commit
🔇 Additional comments (5)
tests/tools/schema_test.ts (3)

1-2: Include a reference to the license information in the PR description.

You have established licensing details at the top. It's good practice to cross-reference them in the PR description to remind external contributors and maintainers about the licensing.


5-6: Validate version alignment and potential vulnerabilities.

You're using Ajv v8.12.0 and ajv-formats v3.0.1. Make sure the rest of your dependencies and environment are compatible with these versions.

✅ Verification successful

Version alignment verified - no issues found

The versions of Ajv (v8.12.0) and ajv-formats (v3.0.1) are compatible and properly pinned. The minor version differences in some imports (v8.17.1) maintain backward compatibility within the v8.x series. The version pinning and isolation of test environments demonstrate good dependency management practices.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# This script checks the package.json or import references for potential version mismatches.
rg 'ajv' -A 5
rg 'ajv-formats' -A 5

Length of output: 21138


14-22: Consider a stable reference for the example YAML files.

It might be beneficial to verify that these example YAML files exist and remain up-to-date. Ensure that the paths you reference (especially those in examples/templates) are accurate and under version control.

✅ Verification successful

All referenced YAML files exist and paths are correct

The relative paths in the code are accurate when resolved from tests/tools/schema_test.ts. All the referenced metatype YAML files exist in the repository and are under version control. No changes are needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# This script checks for the existence of each file reference 
for file in "../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"; do
    if [[ ! -f "$file" ]]; then
        echo "Missing file: $file"
    fi
done

Length of output: 3215


Script:

#!/bin/bash
# Search for all metatype yaml/yml files in the repository
echo "Searching for metatype.y(a)ml files:"
fd -t f "metatype\.(yaml|yml)$"

Length of output: 482

tools/schema/metatype.json (2)

1-5: Congratulations on adding a descriptive schema.

The $schema and $id references, along with title, are well-defined. This is a great start for discoverability on the SchemaStore.


156-187: Confirm that all generator configs match real usage.

Make sure the schema covers all possible future expansions of your generator configurations so that you don’t need frequent schema updates.

✅ Verification successful

All generator configurations in the schema match actual usage patterns

Found evidence of all generator types being actively used across the codebase:

  • Client generators (client_ts, client_py, client_rs) in test typegraphs
  • FDK generators (fdk_typescript, fdk_python, fdk_rust) in example configurations
  • Sub-generator configuration used with stubbed runtimes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for references to config generator usage
rg -A 10 'generatorConfig'

Length of output: 1699


Script:

#!/bin/bash
# Find config files that might contain generator configurations
fd -e json -e yaml -e yml | xargs rg -l 'generator|typegraph'

# Look for actual generator implementations
rg -l "class.*Generator" 

Length of output: 851


Script:

#!/bin/bash
# Check content of main metatype config files
echo "=== whiz.yaml ==="
cat whiz.yaml
echo -e "\n=== src/metagen/metatype.yaml ==="
cat src/metagen/metatype.yaml
echo -e "\n=== examples/metatype.yaml ==="
cat examples/metatype.yaml

Length of output: 9693


Script:

#!/bin/bash
# Check test files for generator configurations
echo "=== tests/metatype.yml ==="
cat tests/metatype.yml
echo -e "\n=== tests/metagen/typegraphs/sample/metatype.yml ==="
cat tests/metagen/typegraphs/sample/metatype.yml

Length of output: 2288

tests/tools/schema_test.ts Show resolved Hide resolved
michael-0acf4
michael-0acf4 previously approved these changes Jan 6, 2025
@luckasRanarison luckasRanarison merged commit 3d8dac2 into main Jan 9, 2025
13 checks passed
@luckasRanarison luckasRanarison deleted the feat/json-schema branch January 9, 2025 03:16
Yohe-Am pushed a commit that referenced this pull request Jan 9, 2025
<!--
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 -->

---

- [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
-->

- **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 -->
Yohe-Am pushed a commit that referenced this pull request Jan 15, 2025
<!--
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 -->

---

- [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
-->

- **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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants