-
Notifications
You must be signed in to change notification settings - Fork 60
Add a test controller which consumes text/plain content #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Copilot
AI
Dec 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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