-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add logging for OpenAPI schema default value type mismatches #63027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo! |
Co-authored-by: captainsafia <[email protected]>
@copilot It's recommended that the type of the default value match the type defined in the schema so this option is not viable. Update the PR to:
|
Co-authored-by: captainsafia <[email protected]>
Updated the implementation to log warnings instead of using string fallback for default value type mismatches. The solution now:
Changes implemented in commit 4e363d3. |
Co-authored-by: captainsafia <[email protected]>
Problem
The current
ApplyDefaultValue
method in OpenAPI schema generation fails when there are type mismatches between default values and their target types, particularly in F# scenarios. For example:This causes
InvalidCastException
duringJsonSerializer.SerializeToNode()
calls, preventing OpenAPI schema generation from completing successfully.Solution
This PR implements a logging-based approach that:
ILogger
Implementation
The change adds logging infrastructure and modifies the
ApplyDefaultValue
method inJsonNodeSchemaExtensions.cs
:Testing
Added comprehensive tests that verify:
[DefaultValue(10)] ulong id
)Compatibility
[<DefaultParameterValue>]
type mismatches with proper loggingFixes scenarios where OpenAPI generation would previously fail with
InvalidCastException
, now producing valid schemas while alerting developers to type mismatches through logging.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.