Skip to content

Enhance JSON schema generation with $defs support and 'result' property#17

Merged
IvanMurzak merged 24 commits intomainfrom
fix/output-schema
Oct 22, 2025
Merged

Enhance JSON schema generation with $defs support and 'result' property#17
IvanMurzak merged 24 commits intomainfrom
fix/output-schema

Conversation

@IvanMurzak
Copy link
Copy Markdown
Owner

Introduce support for complex types in JSON schema generation by implementing $defs handling and adding a 'result' property for return types. Update version to 2.1.1.

@IvanMurzak IvanMurzak self-assigned this Oct 16, 2025
@IvanMurzak IvanMurzak requested a review from Copilot October 16, 2025 06:16
@IvanMurzak IvanMurzak added the bug Something isn't working label Oct 16, 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

Enhance JSON schema generation to support $defs for complex types and wrap method return schemas in an object with a "result" property. Also bumps package version to 2.1.1.

  • Add GenerateSchemaWithDefs to centralize $defs handling and deduplicate complex type schemas
  • Update GetArgumentsSchema and GetReturnSchema to use $defs and introduce the "result" property in return schemas
  • Introduce JsonSchema.Result constant and update tests to reflect the new return schema shape

Reviewed Changes

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

File Description
ReflectorNet/src/Utils/Json/JsonSchema.cs Adds $defs-aware schema generation and wraps return schemas with "result" property
ReflectorNet/src/Utils/Json/JsonSchema.Consts.cs Adds Result constant used in new return schema shape
ReflectorNet/ReflectorNet.csproj Version bump to 2.1.1
ReflectorNet.Tests/SchemaTests/ReturnSchemaTests.cs Updates tests to validate "result" wrapper and $defs behavior

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 Outdated
Comment thread ReflectorNet.Tests/SchemaTests/ReturnSchemaTests.cs Outdated
Comment thread ReflectorNet.Tests/SchemaTests/ReturnSchemaTests.cs Outdated
- Consolidated void return type tests into a single theory with inline data for void, Task, and ValueTask methods.
- Combined primitive return type tests into a single theory with inline data for string, int, bool, and double methods.
- Merged nullable primitive return type tests into a single theory with inline data for nullable types.
- Unified task primitive unwrapping tests into a single theory with inline data for task methods.
- Streamlined nullable task primitive unwrapping tests into a single theory with inline data.
- Refactored value task unwrapping tests into a single theory with inline data for value task methods.
- Added helper methods in SchemaTestBase for asserting return schema structures, including primitive, custom type, and array schemas.
- Updated method parameter type ID retrieval from GetTypeId to GetSchemaTypeId in SchemaTestBase.
- Enhanced AssertResultDefines to filter expected types, ensuring only non-primitive and non-enum types are included in $defs.
- Added comprehensive tests for GetSchemaTypeId covering various collection types, nullable types, and custom classes in TestSchemaTypeId.
- Introduced JsonObjectBuilder for building JSON schema objects with methods for adding properties, definitions, and handling required fields.
- Updated TypeUtils to include GetSchemaTypeId method for consistent schema type ID generation.
- Modified converters (MethodDataConverter, SerializedMemberConverter, SerializedMemberListConverter) to use GetSchemaTypeId for static ID retrieval.
- Adjusted JsonSchema to utilize GetSchemaTypeId for reference handling and type definitions.
- Commented out a test in TestType to avoid issues with current assembly type resolution.
@IvanMurzak IvanMurzak requested a review from Copilot October 17, 2025 08:06
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 27 out of 27 changed files in this pull request and generated 5 comments.


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

Comment thread ReflectorNet.Tests/SchemaTests/ReturnSchemaTests.cs
Comment thread ReflectorNet.Tests/SchemaTests/TestSchemaTypeId.cs
Comment thread ReflectorNet.Tests/SchemaTests/SchemaTestBase.cs
Comment thread ReflectorNet.Tests/SchemaTests/SchemaTestBase.cs
Comment thread ReflectorNet/src/Utils/Json/JsonSchema.cs Outdated
- Added IJsonSchemaConverter interface to define methods for schema generation.
- Implemented JsonSchemaConverter abstract class to provide base functionality for specific type converters.
- Refactored MethodDataConverter, SerializedMemberConverter, and SerializedMemberListConverter to inherit from JsonSchemaConverter.
- Updated methods to utilize new schema generation logic, including GetSchema and GetSchemaRef.
- Enhanced Reflector class to support schema generation for method parameters and return types with improved nullability handling.
- Introduced defines parameter in schema generation methods to manage recursive type definitions and prevent infinite loops.
- Improved error handling and documentation throughout the schema generation process.
@IvanMurzak IvanMurzak requested a review from Copilot October 22, 2025 09:10
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 38 out of 38 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

ReflectorNet/src/Utils/Json/JsonSchema.cs:1

  • The comment claims this prevents infinite recursion, but the actual check defines.ContainsKey(defTypeId) at line 154 already handles this. The placeholder approach appears redundant. Consider simplifying by relying solely on the ContainsKey check.
/*

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 Outdated
Comment thread ReflectorNet/src/Convertor/Json/JsonSchemaConverter.cs Outdated
Comment thread ReflectorNet/src/Utils/Json/JsonSchema.cs
Comment thread ReflectorNet.Tests/SchemaTests/TestType.cs Outdated
IvanMurzak and others added 3 commits October 22, 2025 02:15
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@IvanMurzak IvanMurzak requested a review from Copilot October 22, 2025 09:17
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 38 out of 38 changed files in this pull request and generated 4 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.cs Outdated
Comment thread ReflectorNet/src/Utils/Json/JsonSchema.cs
Comment thread ReflectorNet/src/Convertor/Json/MethodDataConverter.cs
Comment thread ReflectorNet.Tests/SchemaTests/SchemaTestBase.cs Outdated
@IvanMurzak IvanMurzak merged commit f6dde97 into main Oct 22, 2025
1 check passed
@IvanMurzak IvanMurzak deleted the fix/output-schema branch October 22, 2025 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants