Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ 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(Mvc.FileContentResult))
{
schema = new JsonObject
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class Baz
[typeof(JsonPatchDocument<Todo>), "JsonPatchDocument"],
[typeof(Stream), "Stream"],
[typeof(PipeReader), "PipeReader"],
[typeof(FileContentResult), "FileContentResult"],
[typeof(Results<Ok<TodoWithDueDate>, Ok<Todo>>), "ResultsOfOkOfTodoWithDueDateAndOkOfTodo"],
[typeof(Ok<Todo>), "OkOfTodo"],
[typeof(NotFound<TodoWithDueDate>), "NotFoundOfTodoWithDueDate"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.ComponentModel;
using System.Net.Http;
using System.Net.Mime;
using System.Text.Json.Nodes;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -1031,6 +1032,29 @@ await VerifyOpenApiDocument(actionDescriptor, document =>
});
}

[Fact]
public async Task GetOpenApiResponse_HandlesFileContentResultTypeResponse()
{
// Arrange
var builder = CreateBuilder();

// Act
builder.MapPost("/filecontentresult", () => { return new FileContentResult([], MediaTypeNames.Application.Octet); })
.Produces<FileContentResult>(contentType: MediaTypeNames.Application.Octet);

// Assert
await VerifyOpenApiDocument(builder, document =>
{
var operation = document.Paths["/filecontentresult"].Operations[HttpMethod.Post];
var responses = Assert.Single(operation.Responses);
var response = responses.Value;
Assert.True(response.Content.TryGetValue("application/octet-stream", out var mediaType));
var schema = mediaType.Schema;
Assert.Equal(JsonSchemaType.String, schema.Type);
Assert.Equal("binary", schema.Format);
});
}

[ApiController]
[Produces("application/json")]
public class TestController
Expand Down
Loading