chore: harden schema verification across all schema files#30
chore: harden schema verification across all schema files#30brawlaphant wants to merge 1 commit intoregen-network:mainfrom
Conversation
Summary of ChangesHello @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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
No description provided.