-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Fix OpenAPI schema generation for FileContentResult to use binary format #63180
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
There was a problem hiding this 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 fixes OpenAPI schema generation for FileContentResult
to properly represent it as binary data instead of a JSON object reference. The change ensures that when FileContentResult
appears in API responses, the generated OpenAPI schema correctly indicates it's a binary file format.
- Modified schema transformation logic to include
FileContentResult
alongside other binary types likeIFormFile
,Stream
, andPipeReader
- Updated the schema ID assignment to distinguish
FileContentResult
from other binary types
Thanks for your PR, @@shethaadit. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has build failures (missing usings) that need to be addressed.
Co-authored-by: Copilot <[email protected]>
@@ -121,6 +122,28 @@ internal sealed class OpenApiSchemaService( | |||
} | |||
}; | |||
|
|||
private static string GetBinarySchemaId(Type type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has changed the meaning of the code. It was returning the same value for all types before, now they're all different. I doubt this is correct, but even if it is it will cause tests to fail so will need further changes.
I suggest you follow the [guide to build and test the code](https://github.com/dotnet/aspnetcore/blob/main/docs/BuildFromSource.md aspnetcore/docs/BuildFromSource.md) and change the code using an IDE and run the relevant tests so you can check none get broken, and also so you can add a test for this change.
Fix OpenAPI schema generation for FileContentResult to use binary format
Summary of the changes (Less than 80 chars)
Description
This PR fixes #63172 by ensuring that
FileContentResult
is correctly represented as a binary file response in the generated OpenAPI schema instead of being treated as a JSON object reference.Changes
FileContentResult
to the list of types that should be represented as binary data in the OpenAPI schemaTransformSchemaNode
logic inOpenApiSchemaService
to handleFileContentResult
with the binary formatFixes #63172