Skip to content

chore: harden schema verification across all schema files#30

Open
brawlaphant wants to merge 1 commit intoregen-network:mainfrom
brawlaphant:codex/weekly-01-schema-verify
Open

chore: harden schema verification across all schema files#30
brawlaphant wants to merge 1 commit intoregen-network:mainfrom
brawlaphant:codex/weekly-01-schema-verify

Conversation

@brawlaphant
Copy link

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @brawlaphant, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness of schema verification within the repository. By extending validation to all schema definition files and implementing a more thorough validation logic, it aims to prevent common schema-related errors and ensure the integrity and consistency of data structures defined across the project. This change improves overall code quality and maintainability by catching schema definition issues early in the development cycle.

Highlights

  • Expanded Schema Verification Scope: The schema verification process has been significantly expanded from checking a single KPI schema to validating all .schema.json files found within the repository. This ensures consistent adherence to schema standards across all defined schemas.
  • Introduced Robust Schema Validation Logic: A new validateSchema function was added to perform comprehensive checks on each schema file. This function verifies that schemas are valid JSON objects, include a $schema declaration, define a top-level type as 'object', contain a properties object, and correctly handle required fields by ensuring they are strings, unique, and present in properties.
  • Added Utility Functions for File System Traversal and Assertions: New utility functions, listFilesRecursive and assert, were introduced. listFilesRecursive enables the script to dynamically discover all schema files, while assert provides a standardized way to enforce conditions and exit with informative error messages during the verification process.
Changelog
  • scripts/verify.mjs
    • Added listFilesRecursive function to recursively list files in a directory.
    • Introduced an assert utility function for conditional error handling and process termination.
    • Implemented validateSchema function to perform detailed structural validation on JSON schema objects.
    • Replaced the single KPI schema check with a loop that discovers and validates all .schema.json files in the repository using the new validateSchema function.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly improves the schema verification process by introducing a generalized validation function and applying it to all .schema.json files. The addition of listFilesRecursive and assert utility functions enhances the script's robustness and maintainability. No specific vulnerabilities or critical security issues were identified in these changes.

Comment on lines +50 to +65
function validateSchema(rel, schema) {
assert(schema && typeof schema === "object" && !Array.isArray(schema), `${rel}: schema must be a JSON object`, 5);
assert(typeof schema.$schema === "string" && schema.$schema.length > 0, `${rel}: missing $schema`, 5);
assert(schema.type === "object", `${rel}: top-level type must be object`, 5);
assert(schema.properties && typeof schema.properties === "object" && !Array.isArray(schema.properties), `${rel}: missing properties object`, 5);

if (schema.required !== undefined) {
assert(Array.isArray(schema.required), `${rel}: required must be an array`, 5);
const seen = new Set();
for (const key of schema.required) {
assert(typeof key === "string" && key.length > 0, `${rel}: required entries must be non-empty strings`, 5);
assert(!seen.has(key), `${rel}: duplicate required entry '${key}'`, 5);
seen.add(key);
assert(Object.prototype.hasOwnProperty.call(schema.properties, key), `${rel}: required key '${key}' missing from properties`, 5);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The validateSchema function provides a good set of initial structural checks for JSON schema files. However, for a more comprehensive hardening of schema verification, consider integrating a dedicated JSON Schema validation library (e.g., ajv). This would allow for full validation against the JSON Schema specification, catching more complex issues such as incorrect usage of keywords (e.g., items missing for an array type, or invalid format values) that are not covered by the current basic structural assertions.

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.

1 participant