Web API return types: retarget net10.0, built-in OpenAPI, HttpResults controller - #2213
Merged
vladimir-pecanac-main merged 2 commits intoSep 19, 2026
Conversation
… controller Retargets aspnetcore-webapi/ReturnTypes from net6.0 to net10.0 and modernises it. - Swashbuckle.AspNetCore 6.2.3 removed; Microsoft.AspNetCore.OpenApi 10.0.12 added, with AddOpenApi() and MapOpenApi() replacing AddEndpointsApiExplorer/AddSwaggerGen and UseSwagger/UseSwaggerUI. - Test packages: Mvc.Testing 10.0.12, Test.Sdk 18.10.1, xunit 2.9.3, xunit.runner.visualstudio 4.0.0, coverlet.collector 10.0.1. - Fixes CS8602 in EmployeeIActionResultController.CreateAsync by replacing the employee.Name.Length guard with a pattern, and applies the same pattern in EmployeeActionResultController in place of the int? workaround. - EmployeeActionResultController.GetById returns ActionResult<Employee> instead of ActionResult<Employee?>, and TryGetEmployee gains [NotNullWhen(true)] on the interface and the implementation so the implicit conversion stays warning free. - The 200 attribute uses the generic [ProducesResponseType<Employee>] form. - New EmployeeHttpResultsController shows the fourth return type, Results<T1, T2> through TypedResults. Build: 0 warnings, 0 errors. Tests: 7 passed, 0 failed, 0 skipped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Retargets
aspnetcore-webapi/ReturnTypesfrom net6.0 to net10.0 and modernises it, for the republish of "IActionResult and Web API Return Types in ASP.NET Core".Microsoft.AspNetCore.OpenApi10.0.12 added, withAddOpenApi()andMapOpenApi()replacingAddEndpointsApiExplorer()/AddSwaggerGen()andUseSwagger()/UseSwaggerUI(). 10.0.12 rather than the template's 10.0.10, which still restores with NU1903 on Microsoft.OpenApi 2.0.0.Microsoft.AspNetCore.Mvc.Testing10.0.12,Microsoft.NET.Test.Sdk18.10.1,xunit2.9.3,xunit.runner.visualstudio4.0.0,coverlet.collector10.0.1.EmployeeIActionResultController.CreateAsyncraised CS8602 after the retarget (employee.Name.Lengthdereferences astring?). The guard is nowemployee.Name is not { Length: >= 3 and <= 30 }, and the same expression replaces theint?workaround inEmployeeActionResultController.EmployeeActionResultController.GetByIdreturnsActionResult<Employee>instead ofActionResult<Employee?>, andTryGetEmployeegains[NotNullWhen(true)]on the interface and the implementation so the implicit conversion stays warning free.[ProducesResponseType<Employee>]form.EmployeeHttpResultsControllercovers the fourth return type,Results<T1, T2>throughTypedResults, which the article did not have a sample for.Build on SDK 10.0.302: 0 warnings, 0 errors.
dotnet test: 7 passed, 0 failed, 0 skipped.