Skip to content

Conversation

@hugoaguirre
Copy link
Contributor

@hugoaguirre hugoaguirre commented Jan 21, 2026

Checklist (if applicable):

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hugoaguirre, 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 addresses an issue in the JSON schema inference logic where previously encountered struct types were not explicitly marked as "object" in the generated schema. By adding the type: "object" property, the generated schemas become more accurate and compliant, especially for recursive or shared struct definitions, improving the robustness of the schema generation process.

Highlights

  • JSON Schema Generation for Seen Structs: Ensures that when a struct type is encountered multiple times during JSON schema inference (to prevent infinite recursion), the generated schema correctly includes "type": "object" along with "additionalProperties": true.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

@hugoaguirre hugoaguirre changed the title fix(go): include type property in seen struct types fix(go): include Type property in seen struct types Jan 21, 2026
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 aims to fix an issue where the JSON schema for a seen struct type was missing the type: "object" property. The change correctly adds this property in go/internal/base/json.go and updates/adds tests in go/internal/base/json_test.go to verify this behavior.

While the change is an improvement for standard structs, I've identified a significant edge case where it can produce an incorrect schema for structs that implement json.Marshaler. My review includes a comment with a suggested fix to handle this case correctly. Otherwise, the changes are logical and the tests are well-written.

Comment on lines 105 to 108
return &jsonschema.Schema{
Type: "object",
AdditionalProperties: jsonschema.TrueSchema,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This change correctly adds Type: "object" for seen structs, making the schema more specific. However, this introduces an issue for struct types that implement json.Marshaler to produce a non-object JSON representation (e.g., a string or number).

For such types, this logic will incorrectly claim the type is object. For example:

type MyStringer struct { Value string }
func (s MyStringer) MarshalJSON() ([]byte, error) { return json.Marshal(s.Value) }

type Container struct {
    A MyStringer
    B MyStringer
}

When inferring the schema for Container, the schema for the second occurrence of MyStringer (field B) will be incorrectly marked as type: "object".

To fix this, we should check if the struct implements json.Marshaler and, if so, fall back to a more generic schema that doesn't specify the type, which is consistent with how jsonschema handles marshalers.

          var marshalerType = reflect.TypeOf((*json.Marshaler)(nil)).Elem()
          if baseType.Implements(marshalerType) || reflect.PtrTo(baseType).Implements(marshalerType) {
            return &jsonschema.Schema{
              AdditionalProperties: jsonschema.TrueSchema,
            }
          }
          return &jsonschema.Schema{
            Type:                 "object",
            AdditionalProperties: jsonschema.TrueSchema,
          }

@hugoaguirre hugoaguirre requested a review from apascal07 January 21, 2026 21:08
@hugoaguirre hugoaguirre marked this pull request as ready for review January 21, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Go] InferJSONSchema produces invalid schema for repeated struct types

1 participant