diff --git a/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs b/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs index 2971ab2e9b6c..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; @@ -58,15 +59,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] = GetBinarySchemaId(type) }; } else if (type == typeof(IFormFileCollection)) @@ -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()