Skip to content

Conversation

@gunpal5
Copy link
Collaborator

@gunpal5 gunpal5 commented Mar 12, 2025

Summary by CodeRabbit

  • Chores
    • Upgraded project configurations to support the latest development environment and refined build setups.
    • Updated dependency packages.
  • New Features
    • Enhanced JSON serialization customization, offering more flexible options.
    • Improved integration for AI-driven tool interactions.
  • Refactor
    • Streamlined the codebase by removing redundant auto-generated serialization artifacts.
  • Tests
    • Expanded test coverage with a new tool-related test.
    • Enabled automatic verification for faster, more reliable test feedback.

Gunpal Jain and others added 25 commits March 9, 2025 09:47
…emaAttribute.cs and FunctionToolAttribute.cs
# Conflicts:
#	src/tests/CSharpToJsonSchema.AotTests/JsonSerializationTests.cs
Replaced direct dictionary access with TryGetValue to prevent potential KeyNotFound exceptions. This ensures safer and more robust handling of missing keys when fetching "mainFunction_Desc".
Removed unnecessary try-catch block around async call invocation and adjusted formatting for better code clarity. Minor whitespace and indentation improvements were also made to enhance consistency and maintainability.
Added detailed XML documentation for MeaiFunction class and its members, improving code readability and maintainability. Introduced support for strict mode and updated method implementations to enhance functionality. These changes provide better structure and guidance for future development.
Replaced GenericFunctionTool with GoogleFunctionTool to align with the updated namespace and class structure. This ensures compatibility with the latest library changes and maintains consistency in functionality.
# Conflicts:
#	CSharpToJsonSchema.sln
#	src/libs/CSharpToJsonSchema/MeaiFunction.cs
Generated snapshot files for ToolsJsonSerializerContext to support integration tests for various tool methods and their serialization. This includes handling for different types of arguments like string, void, and async inputs.
The `MethodFunction` test method is commented out, likely due to being unused or obsolete. This change improves code clarity by removing an inactive test without deleting it entirely, preserving it for potential future use.
# Conflicts:
#	CSharpToJsonSchema.sln
#	src/tests/AotConsole/Services/StudentRecordService.cs
refactor: Simplified JsonSchema generation codes
# Conflicts:
#	src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs
#	src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Tools.generated.verified.cs
#	src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Tools.generated.verified.cs
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ gunpal5
❌ Gunpal Jain


Gunpal Jain seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2025

Walkthrough

The changes update the solution’s Visual Studio version and project configurations, add a new conversion method in the model generator, and modify the instantiation of AI tool functions with an extra JSON serializer options parameter. The constructor of a key function class now accepts optional JSON options, with an added internal method to initialize default settings. Additionally, several auto-generated snapshot and serialization files in the tests have been removed, and the test helper now automatically verifies outputs.

Changes

File(s) Change Summary
CSharpToJsonSchema.sln Updated Visual Studio version; modified project configurations including workflows and added Debug/Release configurations for specific projects.
src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs Added new private static method ToParameterData that converts type symbols to OpenAPI schema representations.
src/libs/CSharpToJsonSchema.Generators/Sources.Method.MeaiTools.cs Updated MeaiFunction instantiation by adding a new parameter for serializer options in two method overloads.
src/libs/CSharpToJsonSchema/MeaiFunction.cs Introduced an optional JsonSerializerOptions? options parameter in the constructor; added a private _options field; made GetArgsString protected virtual and enhanced its logic; introduced InitializeReflectionOptions for default JSON options.
src/tests/CSharpToJsonSchema.MeaiTests/CSharpToJsonSchema.MeaiTests.csproj Added package reference to Google_GenerativeAI.Microsoft v2.4.1.
src/tests/CSharpToJsonSchema.MeaiTests/Meai_Tests.cs Updated AI client behavior by replacing the commented out instantiation of OpenAIChatClient with GenerativeAIChatClient that sources the API key from an environment variable.
src/tests/CSharpToJsonSchema.SnapshotTests/SnapshotTests.cs Added new test method MethodFunction to enhance test coverage.
src/tests/CSharpToJsonSchema.SnapshotTests/TestHelper.cs Uncommented .AutoVerify() method calls to enable automatic verification of diagnostics and driver outputs.
src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/* Removed numerous auto-generated snapshot files and JSON serialization context files from Tools and Weather functionality, eliminating redundant or obsolete metadata definitions.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant MeaiFunction
    participant SerializerOptions
    Note over Caller,MeaiFunction: Instance Creation
    Caller->>MeaiFunction: new MeaiFunction(tool, call, [options])
    alt Options Provided
        MeaiFunction->>MeaiFunction: Store provided options in _options
    else Options Null
        MeaiFunction->>MeaiFunction: Call InitializeReflectionOptions()
        MeaiFunction-->>SerializerOptions: Create default JSON options
        MeaiFunction->>MeaiFunction: Assign default options to _options
    end
    Caller->>MeaiFunction: Invoke GetArgsString(arguments)
    MeaiFunction->>SerializerOptions: Serialize arguments with _options
Loading
sequenceDiagram
    participant Test as UnitTest
    participant TestHelper
    participant Verifier
    Note over Test,TestHelper: Automatic Verification Process
    Test->>TestHelper: CheckSourceAsync(resource)
    TestHelper->>Verifier: verifier.Verify(diagnostics)
    TestHelper->>Verifier: verifier.Verify(driver)
    Verifier-->>TestHelper: Verification results
    TestHelper-->>Test: Return verification outcome
Loading

Poem

Oh, I hop through lines of code so bright,
Mapping types to schemas with all my might.
With JSON options dancing in the air,
Tests now verify with flair,
Removing old snapshots, setting the record right.
Hopping on in code with joy, day and night!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/tests/CSharpToJsonSchema.MeaiTests/Meai_Tests.cs (1)

50-53: AI client implementation switched from OpenAI to Google

The code now uses Google's GenerativeAIChatClient instead of OpenAI, which aligns with the package addition in the project file. The environment variable access pattern remains consistent with the rest of the code.

Consider removing commented code once the new implementation is confirmed to be working correctly.

-//Microsoft.Extensions.AI.OpenAIChatClient openAiClient = new OpenAIChatClient(client.GetChatClient("gpt-4o-mini"));
-
var chatClient = new GenerativeAIChatClient(Environment.GetEnvironmentVariable("GOOGLE_API_KEY",EnvironmentVariableTarget.User));
-//var chatClient = new Microsoft.Extensions.AI.FunctionInvokingChatClient(openAiClient);
src/libs/CSharpToJsonSchema/MeaiFunction.cs (1)

123-156: Enhanced type handling for JSON serialization

The implementation now handles various JSON types (JsonValue, JsonObject, JsonArray) and has a more robust fallback for complex types. This significantly improves the flexibility of the function.

However, there's a potential issue with null handling in the type check.

Consider improving the null handling in the type check. The current code might throw a NullReferenceException if args.Value is null when checking if the type is primitive.

-                var type = args.Value?.GetType();
-                if(type.IsPrimitive)
+                var type = args.Value?.GetType();
+                if(type?.IsPrimitive == true)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ffaa1e and 45eaf37.

📒 Files selected for processing (70)
  • CSharpToJsonSchema.sln (3 hunks)
  • src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs (1 hunks)
  • src/libs/CSharpToJsonSchema.Generators/Sources.Method.MeaiTools.cs (2 hunks)
  • src/libs/CSharpToJsonSchema/MeaiFunction.cs (6 hunks)
  • src/tests/CSharpToJsonSchema.MeaiTests/CSharpToJsonSchema.MeaiTests.csproj (1 hunks)
  • src/tests/CSharpToJsonSchema.MeaiTests/Meai_Tests.cs (2 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/SnapshotTests.cs (1 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.PropertyNames.g.received.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.PropertyNames.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_NoReturnAsyncArgs.g.received.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_NoReturnAsyncArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_NoReturnAsyncArgs.g.received.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_NoReturnAsyncArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_StringArgs.g.received.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_StringArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_StringAsyncArgs.g.received.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_StringAsyncArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_VoidArgs.g.received.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_VoidArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_StringArgs.g.received.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_StringArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_StringAsyncArgs.g.received.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_StringAsyncArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_VoidArgs.g.received.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_VoidArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.String.g.received.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.String.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Boolean.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Calls.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateOnly.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateTime.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Double.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetCurrentWeather3Args.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetJsonTypeInfo.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueAsyncArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int32.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int64.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.PropertyNames.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueAsyncArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Single.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes_Diagnostics.verified.txt (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Calls.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Double.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherAsyncArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetJsonTypeInfo.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.PropertyNames.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.String.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Tools.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Unit.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Weather.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Calls.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Double.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeather2Args.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeatherAsync2Args.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetJsonTypeInfo.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.PropertyNames.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.String.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Tools.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Unit2.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Weather2.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict_Diagnostics.verified.txt (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather_Diagnostics.verified.txt (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/TestHelper.cs (1 hunks)
💤 Files with no reviewable changes (62)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_NoReturnAsyncArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.String.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.PropertyNames.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_VoidArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.PropertyNames.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_VoidArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_StringAsyncArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_StringArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_StringArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_NoReturnAsyncArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather_Diagnostics.verified.txt
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes_Diagnostics.verified.txt
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.PropertyNames.g.received.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetJsonTypeInfo.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.PropertyNames.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict_Diagnostics.verified.txt
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_StringAsyncArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.String.g.received.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueAsyncArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Tools.generated.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Double.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_StringAsyncArgs.g.received.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Double.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Double.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Boolean.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_VoidArgs.g.received.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueAsyncArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_StringAsyncArgs.g.received.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Tools.generated.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_NoReturnAsyncArgs.g.received.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Unit2.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetJsonTypeInfo.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Weather2.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_StringArgs.g.received.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateOnly.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetCurrentWeather3Args.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_NoReturnAsyncArgs.g.received.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.String.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetJsonTypeInfo.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.PropertyNames.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Weather.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Unit.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Single.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeatherAsync2Args.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherAsyncArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeather2Args.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Calls.generated.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateTime.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Calls.generated.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int32.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Calls.generated.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_Static_StringArgs.g.received.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.String.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.MethodFunction#ToolsJsonSerializerContext.SampleFunctionTool_VoidArgs.g.received.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int64.g.verified.cs
🔇 Additional comments (16)
src/tests/CSharpToJsonSchema.SnapshotTests/TestHelper.cs (2)

35-36: Excellent enhancement to test automation!

Enabling automatic verification with .AutoVerify() streamlines the testing workflow by automating the verification step for diagnostic outputs.


41-42: Good consistency in automation approach!

Applying the same .AutoVerify() pattern to the driver verification maintains consistency and ensures both verification processes follow the same automated approach.

src/tests/CSharpToJsonSchema.SnapshotTests/SnapshotTests.cs (1)

6-10: Great addition to test coverage!

The new MethodFunction() test method follows the established pattern of other tests in this class and properly tests the method function capabilities mentioned in the PR objectives. This improves test coverage for the "MeaiFunction type handling" feature.

src/tests/CSharpToJsonSchema.MeaiTests/CSharpToJsonSchema.MeaiTests.csproj (1)

12-12: Package addition looks good for Google Generative AI support

The added Google_GenerativeAI.Microsoft package aligns with the code changes in the test file where OpenAI has been replaced with Google's Generative AI implementation.

src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs (1)

139-269: Well-structured implementation for type conversion

The new ToParameterData method is a comprehensive implementation for converting C# type symbols to OpenAPI schema representations. It handles various TypeKind cases (Enum, Structure, Class, Interface, Array) appropriately, determining the correct schema type and format for each.

The method effectively:

  • Processes primitive types with appropriate formats
  • Handles complex object types by recursively processing their properties
  • Manages array types and their item schemas
  • Preserves enum values
  • Correctly determines nullability
src/tests/CSharpToJsonSchema.MeaiTests/Meai_Tests.cs (1)

3-3: Added namespace for Google's Generative AI

The import is consistent with the transition from OpenAI to Google's Generative AI implementation.

CSharpToJsonSchema.sln (3)

2-3: Updated Visual Studio version

The solution has been updated to Visual Studio 17.12, which is appropriate for using the latest IDE features.


27-27: Added Dependabot configuration

Adding Dependabot configuration is a good practice for automated dependency management.


84-89: Added configuration settings for projects

Release configurations have been added for the CSharpToJsonSchema.MeaiTests project, and both Debug and Release configurations for the AotConsole project. This ensures build configurations are complete for all projects.

src/libs/CSharpToJsonSchema.Generators/Sources.Method.MeaiTools.cs (2)

33-33: Updated MeaiFunction constructor to include serialization options

The constructor call now includes the serialization options from the generated JsonSerializerContext. This aligns with the updated MeaiFunction constructor signature and ensures consistent JSON serialization behavior across the application.


62-62: Updated MeaiFunction constructor in interface extension method

Similar to the previous change, this properly updates the MeaiFunction constructor call to include serialization options from the generated context, ensuring consistent JSON handling across different extension methods.

src/libs/CSharpToJsonSchema/MeaiFunction.cs (5)

4-5: Added necessary JSON serialization namespaces

Added imports for JSON serialization features that are required for the enhanced type handling functionality.


35-35: Added private field for JSON serialization options

This field will store the JSON serialization options passed to the constructor, enabling consistent serialization behavior throughout the class.


47-62: Updated constructor to accept optional serialization options

The constructor now accepts a JsonSerializerOptions parameter, allowing for customization of JSON serialization behavior. This is a valuable enhancement that improves flexibility.


104-104: Changed GetArgsString to protected virtual

Making this method protected and virtual is a good design decision as it allows derived classes to customize the JSON serialization behavior for arguments.


65-81:

Details

❓ Verification inconclusive

Added fallback initialization method for JSON serialization options

This method provides a fallback for creating serialization options when not explicitly provided, which is good for backward compatibility. However, the comment about breaking AOT compatibility is concerning.

The code includes a warning about AOT compatibility issues when using reflection. Verify that this won't cause problems in environments that rely on AOT compilation, such as mobile or serverless platforms.


🏁 Script executed:

#!/bin/bash
# Check for AOT compilation directives or mentions in the project
echo "Checking for AOT compilation directives in the project..."
rg -i "aot|nativeaot|trimming|PublishAot" --type csproj --type cs

Length of output: 223


Let's re-run the search using glob patterns so that both C# and csproj files are examined. This should avoid the "unrecognized file type" error.


🏁 Script executed:

#!/bin/bash
echo "Re-checking for AOT-related keywords in *.cs and *.csproj files..."
rg -i "aot|nativeaot|trimming|PublishAot" -g "*.csproj" -g "*.cs"

Length of output: 1879


AOT Compatibility Verification Required: Update Fallback Initialization for JSON Options

The fallback method for initializing JSON serialization options maintains backward compatibility but relies on reflection (e.g., using JsonStringEnumConverter), which is known to break in AOT environments. Notably, there’s an inline comment in src/libs/CSharpToJsonSchema/MeaiFunction.cs and diagnostics in other parts of the repository (e.g., in the source generator diagnostic descriptors and AOT-specific project configurations) that confirm these concerns.

  • Verify that this fallback mechanism won’t cause runtime issues on AOT-based platforms (mobile/serverless).
  • Consider enforcing the provision of an explicit JsonSerializerOptions instance in AOT scenarios or add runtime checks to fail fast in incompatible environments.

Comment on lines 144 to 150
if (_options == null)
{
//Fallback to Reflection
//This will break the AOT, Hoping for the best, IChatClient implementation only send JSON classes
//Or Developer is using the code generator
_options = InitializeReflectionOptions();
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Added reflection fallback with explicit warning

The code includes a fallback to reflection-based serialization with explicit warning comments about AOT compatibility issues. While this provides good backward compatibility, it may lead to runtime errors in AOT environments.

Verify whether this reflection fallback is actually needed or if all scenarios can be covered by passing proper JsonSerializerOptions with type information. If reflection is truly needed, consider adding a feature flag to disable it in AOT environments.


🌐 Web query:

What are best practices for handling System.Text.Json serialization in AOT compilation environments?

💡 Result:

To handle System.Text.Json serialization effectively in AOT compilation environments, follow these best practices:


1. Use Source Generators

Leverage System.Text.Json source generators to avoid reflection, which isn't AOT-compatible. Source generators precompute serialization logic at compile time, ensuring type metadata isn't trimmed.
Example setup:

[JsonSerializable(typeof(MyModel))]
public partial class MyContext : JsonSerializerContext { }

var options = new JsonSerializerOptions {
    TypeInfoResolver = MyContext.Default
};
var json = JsonSerializer.Serialize(model, options);

This eliminates runtime reflection and supports trimming/Native AOT[1][3][7][10].


2. Define a JsonSerializerContext

Create a context class annotated with [JsonSerializable] for all serializable types:

[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Book))]
[JsonSerializable(typeof(Bookcase))]
public partial class AppJsonContext : JsonSerializerContext { }

Register it globally in ASP.NET Core:

builder.Services.ConfigureHttpJsonOptions(options => {
    options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonContext.Default);
});

This ensures type information is preserved during trimming[2][13][14].


3. Avoid Reflection-Based APIs

Disable reflection defaults to enforce AOT safety:

<PropertyGroup>
    <JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>

This throws InvalidOperationException if reflection is accidentally used[10].


4. Handle Polymorphism with Attributes

Use [JsonPolymorphic] and [JsonDerivedType] for AOT-safe inheritance:

[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[JsonDerivedType(typeof(TextItem), "text")]
[JsonDerivedType(typeof(ImageItem), "image")]
public abstract class ItemModel { }

// Context must include all derived types
[JsonSerializable(typeof(ItemModel))]
[JsonSerializable(typeof(TextItem))]
public partial class ItemContext : JsonSerializerContext { }

This replaces reflection-based type resolution[12][7].


5. Configure Serialization Options via Attributes

Set options at compile time using JsonSourceGenerationOptions:

[JsonSourceGenerationOptions(
    PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
    DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
)]
[JsonSerializable(typeof(WeatherForecast))]
public partial class WeatherContext : JsonSerializerContext { }

This avoids runtime configuration overhead[10][13].


6. Handle Enums as Strings

Use JsonStringEnumConverter<TEnum> for AOT-compatible enum serialization:

[JsonConverter(typeof(JsonStringEnumConverter<MyEnum>))]
public enum MyEnum { Value1, Value2 }

[JsonSerializable(typeof(MyEnum))]
public partial class EnumContext : JsonSerializerContext { }

Avoid the non-generic JsonStringEnumConverter[7][10].


7. Follow Model Constraints

  • Use partial classes: Required for source-generated types[1][9].
  • Parameterless constructors: Mandatory for deserialization[1][9].
  • Limit collections: Stick to List<T>, HashSet<T>, and Dictionary<TKey, TValue>[1].
  • Avoid generics: Not supported by some AOT-focused libraries like Chickensoft Serialization[1].

8. Performance and Size Optimization

  • Metadata mode: Reduces generated code size by omitting serialization logic[8].
  • Trimming: Ensure all runtime-accessed types are explicitly included in contexts[4][9].
  • Migrate from Newtonsoft.Json: Replace reflection-heavy serializers with System.Text.Json[5][9].

Example: AOT-Compatible Serialization

// Model
[JsonSerializable(typeof(Book))]
public partial class BookContext : JsonSerializerContext { }

public record Book(
    [property: JsonPropertyName("title")] string Title,
    [property: JsonPropertyName("author")] string Author
);

// Serialization
var options = new JsonSerializerOptions {
    TypeInfoResolver = BookContext.Default
};
string json = JsonSerializer.Serialize(book, options);

Output includes AOT-safe type discriminators:

{
    "$type": "book",
    "title": "The Book",
    "author": "The Author"
}

By adopting these practices, you ensure compatibility with AOT/trimmed environments while maintaining performance and type safety[1][7][10][13].

Citations:


Action Required: Address Reflection Fallback for AOT Compatibility

The reflection-based fallback in use at src/libs/CSharpToJsonSchema/MeaiFunction.cs (lines 144–150) poses a risk in AOT environments where runtime reflection is unsupported. Given best practices for System.Text.Json in AOT scenarios—such as leveraging source generators and predefining a JsonSerializerContext—relying on reflection can lead to runtime errors. If you must retain this fallback for backward compatibility, please consider one of the following actions:

  • Remove the reflection fallback entirely: Ensure all serialization scenarios use properly configured JsonSerializerOptions (e.g., with source-generated type metadata) to eliminate the risk in AOT environments.
  • Gate the fallback with a feature flag: If reflection-based serialization is necessary in some contexts, add a feature flag (or conditional compilation) to disable it when the application is running in AOT scenarios.

@gunpal5 gunpal5 merged commit e3ab034 into tryAGI:main Mar 12, 2025
2 of 4 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/libs/CSharpToJsonSchema/MeaiFunction.cs (1)

147-154: 💡 Verification agent

🧩 Analysis chain

Consider adding feature flag for AOT environments.

The reflection fallback mechanism with explicit warnings provides good backward compatibility, but it may lead to runtime errors in AOT environments.

Consider adding a feature flag or conditional compilation to completely disable reflection in AOT-targeted builds:

 if (_options == null)
 {  
+    #if !ENABLE_AOT
     #pragma warning disable IL2026, IL3050 // Reflection is used only when enabled
     //Fallback to Reflection
     //This will break the AOT, Hoping for the best, IChatClient implementation only send JSON classes
     //Or Developer is using the code generator
     _options = InitializeReflectionOptions();
-    #pragma warning disable IL2026, IL3050 // Reflection is used only when enabled
+    #pragma warning restore IL2026, IL3050 // Reflection is used only when enabled
+    #else
+    throw new InvalidOperationException("Reflection-based serialization is disabled in AOT environments. Please provide JsonSerializerOptions with proper TypeInfoResolver.");
+    #endif
 }

Let's see if there are similar patterns elsewhere in the codebase:


🏁 Script executed:

#!/bin/bash
# Check for AOT-related conditionals or feature flags in the codebase
rg -A 2 -B 2 'AOT|Native AOT|NativeAOT|ENABLE_AOT|#if.*AOT|#if.*REFLECTION|JsonSerializer\.IsReflectionEnabledByDefault'

Length of output: 19449


AOT Feature Flag for Reflection Fallback Required

The reflection fallback block in src/libs/CSharpToJsonSchema/MeaiFunction.cs (lines 147–154) currently relies on runtime behavior while always attempting to use reflection. Since runtime reflection can cause failures in AOT environments, it’s safer to gate this fallback using a compile-time feature flag. Doing so will disable the reflection path outright for AOT builds and ensure a clear exception is thrown instead.

Please update the code as follows:

 if (_options == null)
 {  
-    #pragma warning disable IL2026, IL3050 // Reflection is used only when enabled
-    //Fallback to Reflection
-    //This will break the AOT, Hoping for the best, IChatClient implementation only send JSON classes
-    //Or Developer is using the code generator
-    _options = InitializeReflectionOptions();
-    #pragma warning disable IL2026, IL3050 // Reflection is used only when enabled
+    #if !ENABLE_AOT
+        #pragma warning disable IL2026, IL3050 // Reflection is used only when enabled
+        // Fallback to Reflection
+        // This approach may break AOT; consider using the code generator or providing JsonSerializerOptions
+        _options = InitializeReflectionOptions();
+        #pragma warning restore IL2026, IL3050 // Reflection is used only when enabled
+    #else
+        throw new InvalidOperationException("Reflection-based serialization is disabled in AOT environments. Please provide JsonSerializerOptions with a proper TypeInfoResolver.");
+    #endif
 }

This adjustment aligns with similar runtime checks in the repository (e.g., the if(!JsonSerializer.IsReflectionEnabledByDefault) block) while providing a safer, compile-time safeguard against reflection in AOT contexts.

🧹 Nitpick comments (1)
src/libs/CSharpToJsonSchema/MeaiFunction.cs (1)

123-159: Improved JSON type handling with comprehensive type support.

The enhanced handling of various JSON types (JsonNode, JsonValue, JsonObject, JsonArray) provides better support for different argument formats. The fallback mechanism using reflection is properly implemented with warning suppressions.

However, there are a few areas for improvement:

  1. Consider removing the commented-out code (lines 140-143 and 159) as it adds noise without providing value:
- // if(type.IsPrimitive)
- // {
- //     jsonObject[args.Key] = JsonValue.Create(args.Value);
- // }
- // else
- // {
     if (_options == null)
     {  
         #pragma warning disable IL2026, IL3050 // Reflection is used only when enabled
         //Fallback to Reflection
         //This will break the AOT, Hoping for the best, IChatClient implementation only send JSON classes
         //Or Developer is using the code generator
         _options = InitializeReflectionOptions();
         #pragma warning disable IL2026, IL3050 // Reflection is used only when enabled
     }
     var typeInfo = _options.GetTypeInfo(type);

     var str = JsonSerializer.Serialize(args.Value, typeInfo);
     jsonObject[args.Key] = JsonNode.Parse(str);
- //}
  1. The warning directive on line 153 should be #pragma warning restore instead of #pragma warning disable to properly close the warning suppression block.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 45eaf37 and 9ba450e.

📒 Files selected for processing (2)
  • src/libs/CSharpToJsonSchema/MeaiFunction.cs (6 hunks)
  • src/libs/CSharpToJsonSchema/TypeToSchemaHelpers.cs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/libs/CSharpToJsonSchema/TypeToSchemaHelpers.cs
🔇 Additional comments (5)
src/libs/CSharpToJsonSchema/MeaiFunction.cs (5)

4-5: Good addition of required imports.

The added imports for JSON serialization and metadata support the enhanced type handling capabilities being introduced.


35-35: LGTM: Field for JSON serialization options.

Adding this field allows for storing and using custom serialization options throughout the class.


47-47: Well-implemented parameter addition with backward compatibility.

The optional JSON serialization options parameter preserves backward compatibility while adding flexibility. The assignment on line 61 properly stores the provided options for later use.

Also applies to: 61-61


66-82: Properly handles reflection-based serialization with explicit warnings.

The method correctly initializes default serialization options with appropriate configurations and includes pragma directives to suppress AOT-related warnings. The explicit check for reflection availability on line 69 is a good safeguard.


106-106: Good enhancement to method accessibility and extensibility.

Changing the method from private to protected virtual allows derived classes to access and override this functionality, which improves the extensibility of the class.

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.

2 participants