Skip to content

Comments

add Go struct and JSON schema sync test#173

Open
pradhyum6144 wants to merge 1 commit intomodelpack:mainfrom
pradhyum6144:feat-schema-struct-sync-checker
Open

add Go struct and JSON schema sync test#173
pradhyum6144 wants to merge 1 commit intomodelpack:mainfrom
pradhyum6144:feat-schema-struct-sync-checker

Conversation

@pradhyum6144
Copy link

@pradhyum6144 pradhyum6144 commented Feb 24, 2026

Adds a test that uses Go reflection to automatically detect drift between Go struct fields and JSON schema properties. The test compares all five struct types (Model, ModelDescriptor, ModelConfig, ModelCapabilities, ModelFS) against their schema definitions and reports missing fields, extra properties, or type mismatches. This also fixes the missing reward and languages fields in the ModelCapabilities schema that the test caught. The test runs automatically with go test in CI, so any future struct changes without matching schema updates will be caught immediately.

Closes #91

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @pradhyum6144, 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 introduces an automated mechanism to maintain consistency between Go struct definitions and their JSON schema representations. By adding a new Go test that uses reflection, it ensures that any changes to core Go structs are reflected in the JSON schema, preventing schema drift. The PR also includes a fix for existing discrepancies in the ModelCapabilities schema, demonstrating the immediate value of this new validation.

Highlights

  • Automated Schema Validation Test Added: A new Go test (schema/sync_test.go) was introduced to automatically detect and prevent drift between Go struct definitions and their corresponding JSON schema properties.
  • Go Reflection for Schema Comparison: The test leverages Go reflection to compare five key struct types (Model, ModelDescriptor, ModelConfig, ModelCapabilities, ModelFS) against their schema definitions, checking for missing fields, extra properties, or type mismatches.
  • Schema Discrepancies Fixed: The schema/config-schema.json file was updated to include the previously missing reward (boolean) and languages (array of strings) fields within the ModelCapabilities schema, which were identified by this new test.
  • CI Integration: This new schema synchronization test is integrated into the CI pipeline, ensuring that any future inconsistencies between Go structs and their JSON schema definitions are caught automatically.
Changelog
  • schema/config-schema.json
    • Added reward property of type boolean to ModelCapabilities.
    • Added languages property of type array of strings to ModelCapabilities.
  • schema/sync_test.go
    • Added a new Go test file sync_test.go containing TestStructSchemaSync.
    • Implemented functions to parse JSON schema, map Go types to expected schema types, and compare them.
    • The test iterates through v1.Model, v1.ModelDescriptor, v1.ModelConfig, v1.ModelCapabilities, and v1.ModelFS to verify their schema synchronization.
Activity
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 introduces a valuable test to ensure synchronization between Go structs and their corresponding JSON schema definitions, which is a great step for maintainability. The new test has already proven its worth by identifying and helping fix missing reward and languages fields in the ModelCapabilities schema. However, I've found a logical issue in the test's type-matching function that could cause it to miss certain kinds of schema drift. I've provided a suggestion to correct this, ensuring the test is more robust.

Comment on lines 140 to 149
if p.Type != e.typ {
return false
}
if e.format != "" && p.Format != e.format {
return false
}
if e.typ == "array" && e.items != nil && p.Items != nil {
return matchesExpected(*p.Items, *e.items)
}
return true
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The type matching logic in matchesExpected has a couple of issues that could cause it to incorrectly report a match, undermining the purpose of this test:

  1. Format Check: The check for format is one-sided. It will fail if the Go type expects a format and the schema doesn't have one, but it will incorrectly pass if the schema has a format that the Go type doesn't expect.
  2. Array Items Check: The check for array items is incomplete. If the Go type is an array of a specific type (e.g., []string), but the schema just defines "type": "array" without an items block, the function will incorrectly report a match.

This could lead to a false sense of security, as some schema drifts might not be detected. The suggested change corrects both of these issues by ensuring the format matches exactly and by properly validating the presence and type of array items.

	if p.Type != e.typ || p.Format != e.format {
		return false
	}
	if e.typ == "array" {
		if (p.Items == nil) != (e.items == nil) {
			return false // Mismatch: one defines items, the other doesn't.
		}
		if p.Items != nil { // implies e.items is also not nil
			return matchesExpected(*p.Items, *e.items)
		}
	}
	return true

@pradhyum6144 pradhyum6144 force-pushed the feat-schema-struct-sync-checker branch from 869d216 to 6759430 Compare February 24, 2026 17:54
…schema

Signed-off-by: pradhyum6144 <pradhyum314@gmail.com>
@pradhyum6144 pradhyum6144 force-pushed the feat-schema-struct-sync-checker branch from 6759430 to e726a11 Compare February 24, 2026 18:11
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.

ci should not pass when new fields are added in GO structs but json schema is not corresponding changed

1 participant