From a127105ea1a69112c3d9246fc40a2742d7c4698a Mon Sep 17 00:00:00 2001 From: Adit Sheth Date: Thu, 7 Aug 2025 16:41:04 -0700 Subject: [PATCH 1/3] Fix OpenAPI schema generation for FileContentResult to use binary format --- src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs b/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs index 2971ab2e9b6c..c05d60df80a9 100644 --- a/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs +++ b/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs @@ -58,15 +58,15 @@ internal sealed class OpenApiSchemaService( TransformSchemaNode = (context, schema) => { var type = context.TypeInfo.Type; - // Fix up schemas generated for IFormFile, IFormFileCollection, Stream, and PipeReader + // Fix up schemas generated for IFormFile, IFormFileCollection, Stream, PipeReader, and FileContentResult // that appear as properties within complex types. - if (type == typeof(IFormFile) || type == typeof(Stream) || type == typeof(PipeReader)) + if (type == typeof(IFormFile) || type == typeof(Stream) || type == typeof(PipeReader) || type == typeof(FileContentResult)) { schema = new JsonObject { [OpenApiSchemaKeywords.TypeKeyword] = "string", [OpenApiSchemaKeywords.FormatKeyword] = "binary", - [OpenApiConstants.SchemaId] = "IFormFile" + [OpenApiConstants.SchemaId] = type == typeof(FileContentResult) ? "FileContentResult" : "IFormFile" }; } else if (type == typeof(IFormFileCollection)) From c4b08d22c8d699304f4dd80e60c2425e19c3e0d8 Mon Sep 17 00:00:00 2001 From: Adit Sheth Date: Fri, 8 Aug 2025 09:48:00 -0700 Subject: [PATCH 2/3] Update src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs b/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs index c05d60df80a9..d95d1dbcee1e 100644 --- a/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs +++ b/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs @@ -66,7 +66,7 @@ internal sealed class OpenApiSchemaService( { [OpenApiSchemaKeywords.TypeKeyword] = "string", [OpenApiSchemaKeywords.FormatKeyword] = "binary", - [OpenApiConstants.SchemaId] = type == typeof(FileContentResult) ? "FileContentResult" : "IFormFile" + [OpenApiConstants.SchemaId] = GetBinarySchemaId(type) }; } else if (type == typeof(IFormFileCollection)) From aa4220f7e2b4edb4c629082497e2041d259eab52 Mon Sep 17 00:00:00 2001 From: Adit Sheth Date: Fri, 8 Aug 2025 10:33:23 -0700 Subject: [PATCH 3/3] More changes. --- .../Services/Schemas/OpenApiSchemaService.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs b/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs index d95d1dbcee1e..2e7c4a7030ad 100644 --- a/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs +++ b/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs @@ -13,6 +13,7 @@ using System.Text.Json.Serialization.Metadata; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Json; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.Extensions.DependencyInjection; @@ -121,6 +122,28 @@ internal sealed class OpenApiSchemaService( } }; + private static string GetBinarySchemaId(Type type) + { + if (type == typeof(IFormFile)) + { + return "IFormFile"; + } + else if (type == typeof(Stream)) + { + return "Stream"; + } + else if (type == typeof(PipeReader)) + { + return "PipeReader"; + } + else if (type == typeof(FileContentResult)) + { + return "FileContentResult"; + } + + return type.Name; + } + private static JsonObject CreateSchemaForJsonPatch() { var addReplaceTest = new JsonObject()