Add a test controller which consumes text/plain content#276
Add a test controller which consumes text/plain content#276sergey-tihon merged 7 commits intofsprojects:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive support for consuming and producing text/plain content type, serving as a minimal reproduction test for issue #275. The changes implement a complete end-to-end text/plain media type handling pipeline.
Key changes:
- Added text/plain input formatter for reading plain text request bodies
- Extended the SwaggerProvider runtime and design-time compilers to handle text/plain payload types
- Added a test controller and corresponding test to verify the functionality
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Swashbuckle.WebApi.Server/Startup.fs | Registers the new TextPlainInputFormatter in the MVC pipeline |
| tests/Swashbuckle.WebApi.Server/Controllers/ReturnTextControllers.fs | Adds ConsumesTextController for handling text/plain POST requests and TextPlainInputFormatter implementation |
| tests/SwaggerProvider.ProviderTests/v3/Swashbuckle.ReturnTextControllers.Tests.fs | Adds test case for sending and receiving text/plain content |
| src/SwaggerProvider.Runtime/RuntimeHelpers.fs | Adds TextPlain media type constant and toTextContent helper function |
| src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs | Extends PayloadType enum and operation compiler to handle TextPlain payload type |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| override _.ReadRequestBodyAsync(context, encoding) = | ||
| task { | ||
| use reader = new StreamReader(context.HttpContext.Request.Body, encoding) |
There was a problem hiding this comment.
The StreamReader should be constructed with leaveOpen: true to prevent it from disposing the underlying Request.Body stream. When the StreamReader is disposed by the use binding, it will by default also dispose the Request.Body stream, which is owned by ASP.NET Core and should not be disposed by the formatter.
| use reader = new StreamReader(context.HttpContext.Request.Body, encoding) | |
| use reader = new StreamReader(context.HttpContext.Request.Body, encoding, true, 1024, true) |
Just seeing if this acts as a minimal repro/text for #275