Skip to content

Feature/dictionary json schema ignore#18

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

Feature/dictionary json schema ignore#18
IvanMurzak merged 5 commits intomainfrom
feature/dictionary-json-schema-ignore

Conversation

@IvanMurzak
Copy link
Copy Markdown
Owner

This pull request introduces improvements to JSON schema generation and validation logic, especially around handling dictionary types and restricted types, as well as some updates to type definitions in converters. The changes ensure that dictionary types are correctly identified and processed, restricted types are not referenced in schema definitions, and schema properties are set more reliably.

Dictionary Type Handling and Schema Generation

  • Added TypeUtils.IsDictionary and TypeUtils.GetDictionaryGenericArguments methods to reliably detect dictionary types and extract their generic arguments. (ReflectorNet/src/Utils/TypeUtils.cs)
  • Updated schema generation logic to handle dictionary types: when a dictionary is detected, its generic arguments are processed for schema definitions, and the schema is set with AdditionalProperties. (ReflectorNet/src/Utils/Json/JsonSchema.cs)
  • Modified test assertions to differentiate between array and dictionary types, ensuring the correct schema type and properties are checked. (ReflectorNet.Tests/SchemaTests/CollectionsTests.cs)

Restricted Type Reference Validation

  • Introduced a list of restricted types (string, object, DateTime, etc.) that should not appear as $ref references in schemas. (ReflectorNet.Tests/SchemaTests/SchemaTestBase.cs)
  • Enhanced schema reference validation to assert that restricted types are not included in $ref references or $defs definitions. (ReflectorNet.Tests/SchemaTests/SchemaTestBase.cs) [1] [2]

Schema Property Initialization and Converter Definitions

  • Improved schema property assignment to ensure properties are only added when present, both in object and parameter schemas. (ReflectorNet/src/Utils/Json/JsonSchema.Internal.cs, ReflectorNet/src/Utils/Json/JsonSchema.cs) [1] [2] [3]
  • Added SerializedMember and SerializedMemberList to the list of defined types in their respective converters for completeness. (ReflectorNet/src/Convertor/Json/SerializedMemberConverter.cs, ReflectorNet/src/Convertor/Json/SerializedMemberListConverter.cs) [1] [2]

@IvanMurzak IvanMurzak requested a review from Copilot October 23, 2025 06:43
@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 by adding proper dictionary type detection and handling, while also improving schema validation and ensuring restricted types are not referenced incorrectly.

  • Introduces new utility methods (IsDictionary and GetDictionaryGenericArguments) for reliable dictionary type detection
  • Updates schema generation to properly handle dictionaries with additionalProperties instead of treating them as arrays
  • Adds validation to prevent restricted types (string, DateTime, etc.) from appearing as $ref references

Reviewed Changes

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

Show a summary per file
File Description
ReflectorNet/src/Utils/TypeUtils.cs Adds dictionary detection and generic argument extraction methods
ReflectorNet/src/Utils/Json/JsonSchema.cs Implements dictionary-specific schema generation with additionalProperties and conditional property assignment
ReflectorNet/src/Utils/Json/JsonSchema.Internal.cs Adjusts property assignment order to only add when properties exist
ReflectorNet/src/Convertor/Json/SerializedMemberListConverter.cs Adds SerializedMemberList to defined types list
ReflectorNet/src/Convertor/Json/SerializedMemberConverter.cs Adds SerializedMember to defined types list
ReflectorNet.Tests/SchemaTests/SchemaTestBase.cs Introduces restricted type validation for schema references
ReflectorNet.Tests/SchemaTests/CollectionsTests.cs Updates test assertions to differentiate between array and dictionary schemas

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.cs
Comment thread ReflectorNet.Tests/SchemaTests/SchemaTestBase.cs Outdated
@IvanMurzak IvanMurzak merged commit f9e601f into main Oct 23, 2025
1 check passed
@IvanMurzak IvanMurzak deleted the feature/dictionary-json-schema-ignore branch October 23, 2025 07:34
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