Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shethaadit
Copy link
Contributor

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

  • Added FileContentResult to the list of types that should be represented as binary data in the OpenAPI schema
  • Modified the TransformSchemaNode logic in OpenApiSchemaService to handle FileContentResult with the binary format

Fixes #63172

@Copilot Copilot AI review requested due to automatic review settings August 7, 2025 23:42
@shethaadit shethaadit requested review from captainsafia and a team as code owners August 7, 2025 23:42
@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Aug 7, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Aug 7, 2025
Copy link
Contributor

@Copilot 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 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 like IFormFile, Stream, and PipeReader
  • Updated the schema ID assignment to distinguish FileContentResult from other binary types

Copy link
Contributor

Thanks for your PR, @@shethaadit. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Copy link
Member

@captainsafia captainsafia left a 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.

@captainsafia captainsafia added the pr: pending author input For automation. Specifically separate from Needs: Author Feedback label Aug 8, 2025
@gfoidl gfoidl added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Aug 8, 2025
@@ -121,6 +122,28 @@ internal sealed class OpenApiSchemaService(
}
};

private static string GetBinarySchemaId(Type type)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates community-contribution Indicates that the PR has been added by a community member feature-openapi pr: pending author input For automation. Specifically separate from Needs: Author Feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File download endpoints incorrectly mapped as objects by built-in OpenAPI generator
4 participants