Skip to content

Commit b345333

Browse files
Copilotwadepickett
andauthored
Add OpenAPI binary file response documentation for ASP.NET Core 11.0 (#36754)
* Initial plan * Add OpenAPI binary file response documentation for ASP.NET Core 11.0 - Added File() to TypedResults helper methods table - Added "Describe binary file responses" section for Minimal APIs - Added "Describe binary file responses" section for Controllers - All new content uses moniker range >= aspnetcore-11.0 - Updated ms.date to 02/06/2026 and added ai-usage metadata Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> * Enhance description for binary file responses Clarify the usage of [ProducesResponseType<FileContentResult>] for binary file responses, specifying that it generates an OpenAPI description similar to the Minimal API example. * Apply suggestions from code review * Preserve .NET 10.0 version and update main file for .NET 11.0 - Created include-metadata10.md with original content for .NET 10.0 - Changed moniker range to "= aspnetcore-10.0" in include file - Updated main file moniker range to ">= aspnetcore-11.0" - Updated content moniker range to ">= aspnetcore-11.0" Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> * Update include-metadata10.md Set include for version 10.0 to be preserved as 10.0 * Apply suggestion from @wadepickett Fixed article metadata monikerRange to start at 9.0 * Update include-metadata.md to remove version checks Removed moniker directives for ASP.NET Core version 11.0 and updated binary file response descriptions. * Update include-metadata.md * Add OpenAPI metadata inclusion details Added section on including OpenAPI metadata for endpoints. * Update include-metadata10.md to remove old reference Removed reference to include-metadata9.md. * Add H2 heading to include-metadata9.md after moniker range Added "## Include OpenAPI metadata for endpoints" heading after the moniker range line with blank lines before and after as requested. Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> Co-authored-by: Wade Pickett <wpickett@microsoft.com>
1 parent 6c84d4d commit b345333

3 files changed

Lines changed: 759 additions & 4 deletions

File tree

aspnetcore/fundamentals/openapi/include-metadata.md

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
---
22
title: Include OpenAPI metadata in an ASP.NET Core app
3+
ai-usage: ai-assisted
34
author: wadepickett
45
description: Learn how to add OpenAPI metadata in an ASP.NET Core app.
5-
ms.author: wpickett
66
monikerRange: '>= aspnetcore-9.0'
7+
ms.author: wpickett
78
ms.custom: mvc
8-
ms.date: 06/12/2025
9+
ms.date: 02/06/2026
910
uid: fundamentals/openapi/include-metadata
1011
---
1112
# Include OpenAPI metadata in an ASP.NET Core app
1213

1314
This article explains how to add OpenAPI metadata in an ASP.NET Core app.
1415

15-
## Include OpenAPI metadata for endpoints
16+
:::moniker range=">= aspnetcore-11.0"
1617

17-
:::moniker range=">= aspnetcore-10.0"
18+
## Include OpenAPI metadata for endpoints
1819

1920
ASP.NET collects metadata from the web app's endpoints and uses it to generate an OpenAPI document.
2021

@@ -360,11 +361,49 @@ Only return types that implement <xref:Microsoft.AspNetCore.Http.Metadata.IEndpo
360361
| NotFound() | 404 |
361362
| Conflict() | 409 |
362363
| UnprocessableEntity() | 422 |
364+
| File() | 200 |
363365

364366
All of these methods except `NoContent` have a generic overload that specifies the type of the response body.
365367

366368
A class can be implemented to set the endpoint metadata and return it from the route handler.
367369

370+
##### Describe binary file responses
371+
372+
To describe endpoints that return binary file responses in the OpenAPI document, use the <xref:Microsoft.AspNetCore.Http.OpenApiRouteHandlerBuilderExtensions.Produces%2A> extension method with `FileContentResult` as the type parameter to specify the response type and content type:
373+
374+
```csharp
375+
app.MapPost("/filecontentresult", () =>
376+
{
377+
var content = "This endpoint returns a FileContentResult!"u8.ToArray();
378+
return TypedResults.File(content);
379+
})
380+
.Produces<FileContentResult>(contentType: MediaTypeNames.Application.Octet);
381+
```
382+
383+
This generates an OpenAPI schema with `type: string` and `format: binary` for the `FileContentResult` type.
384+
385+
The generated OpenAPI document describes the endpoint response as:
386+
387+
```yaml
388+
responses:
389+
'200':
390+
description: OK
391+
content:
392+
application/octet-stream:
393+
schema:
394+
$ref: '#/components/schemas/FileContentResult'
395+
```
396+
397+
With `FileContentResult` defined in `components/schemas` as:
398+
399+
```yaml
400+
components:
401+
schemas:
402+
FileContentResult:
403+
type: string
404+
format: binary
405+
```
406+
368407
##### Set responses for `ProblemDetails`
369408

370409
When setting the response type for endpoints that may return a ProblemDetails response, the following can be used to add the appropriate response metadata for the endpoint:
@@ -441,6 +480,22 @@ public async Task<ActionResult<Todo>> CreateOrReplaceTodo(string id, Todo todo)
441480

442481
This example also illustrates how to define multiple response types for an action method, including the content type of the response body.
443482

483+
##### Describe binary file responses
484+
485+
To describe endpoints that return binary file responses, use the [`[ProducesResponseType<FileContentResult>]`](xref:Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute) attribute to specify the response type and content type:
486+
487+
```csharp
488+
[HttpPost("filecontentresult")]
489+
[ProducesResponseType<FileContentResult>(StatusCodes.Status200OK, MediaTypeNames.Application.Octet)]
490+
public IActionResult PostFileContentResult()
491+
{
492+
var content = "This endpoint returns a FileContentResult!"u8.ToArray();
493+
return new FileContentResult(content, MediaTypeNames.Application.Octet);
494+
}
495+
```
496+
497+
This operation generates the same OpenAPI description as the [Minimal API binary file response example](xref:fundamentals/openapi/include-metadata#describe-binary-file-responses), with `FileContentResult` defined as `type: string` and `format: binary`.
498+
444499
---
445500

446501
### Exclude endpoints from the generated document
@@ -710,4 +765,5 @@ The following table shows the key differences beween the MVC JSON options and gl
710765

711766
:::moniker-end
712767

768+
[!INCLUDE[](~/fundamentals/openapi/includes/include-metadata10.md)]
713769
[!INCLUDE[](~/fundamentals/openapi/includes/include-metadata9.md)]

0 commit comments

Comments
 (0)