Skip to content

feat: enhance schema generation to support value types for additional…#19

Merged
IvanMurzak merged 2 commits intomainfrom
feature/dictionary-json-schema-ignore
Oct 23, 2025
Merged

feat: enhance schema generation to support value types for additional…#19
IvanMurzak merged 2 commits intomainfrom
feature/dictionary-json-schema-ignore

Conversation

@IvanMurzak
Copy link
Copy Markdown
Owner

This pull request updates the logic for generating JSON schema definitions for generic types in the GetSchema method. The main improvement is that the schema now uses the value type's schema for additionalProperties when the generic type has at least two type arguments, making the schema more accurate and descriptive.

Enhancement to JSON schema generation:

  • In JsonSchema.cs, the GetSchema method now checks if the generic type has two or more arguments and, if so, sets additionalProperties in the schema to the value type's schema instead of just true. This provides a more precise schema for dictionaries and similar types.…Properties

@IvanMurzak IvanMurzak requested a review from Copilot October 23, 2025 07:55
@IvanMurzak IvanMurzak self-assigned this Oct 23, 2025
@IvanMurzak IvanMurzak added the enhancement New feature or request label Oct 23, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances JSON schema generation for generic types by using the value type's schema for additionalProperties instead of just true when the generic type has two or more type arguments (e.g., dictionaries).

Key changes:

  • Modified GetSchema method to check generic argument count and generate more descriptive schemas for dictionary-like types
  • Moved schema creation logic before the defines assignment to ensure proper schema structure

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 185 to 197
if (genericArgs.Length >= 2)
{
// Use the value type's schema for additionalProperties
var valueTypeSchema = GetSchema(reflector, genericArgs[1], defines);
schema = new JsonObject { [Type] = Object, [AdditionalProperties] = valueTypeSchema };
}
else
{
schema = new JsonObject { [Type] = Object, [AdditionalProperties] = true };
}

if (definesNeeded && !defineContainsType)
defines[typeId] = schema;
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

The schema assignment should occur before adding to defines to ensure the correct schema is stored. However, the current logic assigns the schema to defines[typeId] after creating it, but the original code at line 198 (now removed) was creating the schema after the defines assignment. This means defines[typeId] may now contain the wrong schema reference. The conditional check at line 196 should come after the schema is fully constructed but the code doesn't handle the case where definesNeeded might need the final schema that includes proper additionalProperties. Consider whether line 196-197 should remain in its current position or be moved after the schema construction is complete.

Copilot uses AI. Check for mistakes.
@IvanMurzak IvanMurzak requested a review from Copilot October 23, 2025 08:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread ReflectorNet/src/Utils/Json/JsonSchema.Internal.cs
Comment thread ReflectorNet/src/Utils/Json/JsonSchema.cs
@IvanMurzak IvanMurzak merged commit 89fb3b2 into main Oct 23, 2025
1 check passed
@IvanMurzak IvanMurzak deleted the feature/dictionary-json-schema-ignore branch October 23, 2025 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants