Skip to content

Reading request body: retarget net10.0 and move to the built-in OpenAPI generator - #2198

Merged
vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/101143-aspnetcore-webapi-read-request-body
Sep 16, 2026
Merged

vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/101143-aspnetcore-webapi-read-request-body

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Retargets aspnetcore-webapi/ReadingRequestBody to net10.0 and moves the sample off Swashbuckle onto the built-in OpenAPI generator.

  • Both projects: net8.0 to net10.0, Nullable enabled.
  • Swashbuckle.AspNetCore 6.5.0 removed, Microsoft.AspNetCore.OpenApi 10.0.12 added. SwaggerUtils/RawTextRequestOperationFilter.cs and SwaggerUtils/SwaggerEnableRawTextAttribute.cs are replaced by OpenApiUtils/RawTextRequestOperationTransformer.cs (IOpenApiOperationTransformer) and OpenApiUtils/RawTextRequestAttribute.cs. GET /openapi/v1.json returns an OpenAPI 3.1.1 document whose six raw-text actions carry "text/plain": {"schema": {"type": "string"}}, and read-from-body keeps its PersonItemDto JSON schema. No UI package is added.
  • RequestBodyMiddleware now takes ILogger, which removes the builder.Services.AddSingleton(typeof(ILogger), typeof(Logger)) line that existed only to satisfy the non-generic ILogger.
  • The size guard reads Request.ContentLength before the body is read instead of measuring the string afterwards, and EnableBuffering is called with a bufferThreshold and a bufferLimit. A 2,000 byte POST to /Home/read-from-middleware returns 413, a 500 byte POST returns 200.
  • Path checks use a null-safe Path.Value with Contains(..., StringComparison.OrdinalIgnoreCase); PersonItemDto becomes a record; the 413 literal becomes StatusCodes.Status413PayloadTooLarge; primary constructor on the middleware.
  • Test packages: MSTest 4.4.0, Microsoft.NET.Test.Sdk 18.10.0, coverlet.collector 10.0.1, Moq 4.20.72, AutoFixture 4.18.1, Microsoft.AspNetCore.Mvc.Testing 10.0.12, plus nullable annotations and two Assert.AreEqual argument-order fixes.

dotnet build -c Release: 0 warnings, 0 errors. dotnet test -c Release: 7 passed, 0 failed, 0 skipped, on .NET SDK 10.0.302 / runtime 10.0.10.

…generator

- ReadingRequestBody and Tests move from net8.0 to net10.0 with nullable enabled
- Swashbuckle 6.5.0 removed; Microsoft.AspNetCore.OpenApi 10.0.12 with AddOpenApi()
  and MapOpenApi(), and the raw-text operation filter ported to
  IOpenApiOperationTransformer; no UI package
- RequestBodyMiddleware takes ILogger<RequestBodyMiddleware>, so the
  AddSingleton(typeof(ILogger), ...) workaround in Program.cs is gone
- The size guard checks Request.ContentLength before the body is read, and
  EnableBuffering gets a bufferThreshold and a bufferLimit
- Path checks use Contains with StringComparison.OrdinalIgnoreCase on a
  null-safe Path.Value; PersonItemDto is a record; test packages bumped
@vladimir-pecanac-main
vladimir-pecanac-main merged commit 894233a into CodeMazeBlog:main Sep 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant