Skip to content

Convert all web API controllers to TypedResults and add Problem Details middleware#8

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/convert-api-to-typedresults
Draft

Convert all web API controllers to TypedResults and add Problem Details middleware#8
Copilot wants to merge 2 commits intomainfrom
copilot/convert-api-to-typedresults

Conversation

Copy link
Copy Markdown

Copilot AI commented May 4, 2026

Convert all controller actions from IActionResult to strongly-typed TypedResults return types per ASP.NET Core 10 guidance, and wire up RFC 7807 Problem Details for automatic error response formatting.

Problem Details middleware

  • AddProblemDetails() + UseExceptionHandler() + UseStatusCodePages() in Program.cs
  • Unhandled exceptions and bare error status codes now automatically return structured Problem Details JSON

TypedResults conversion (17 controllers)

  • All IActionResult returns replaced with concrete types: Ok<T>, NotFound, BadRequest<string>, Accepted<T>, Results<T1, T2>, FileContentHttpResult
  • Ok()TypedResults.Ok(), NotFound()TypedResults.NotFound(), etc.
  • Added global using Microsoft.AspNetCore.Http.HttpResults; to all API project GlobalUsings.cs files

Example

// Before
public async Task<IActionResult> GetHvacZone(string groupName, CancellationToken cancellationToken = default)
{
    var result = await knxQuerySvc.GetHvacZone(groupName, cancellationToken);
    return result is not null ? Ok(result) : NotFound();
}

// After
public async Task<Results<Ok<KnxHvacZone>, NotFound>> GetHvacZone(string groupName, CancellationToken cancellationToken = default)
{
    var result = await knxQuerySvc.GetHvacZone(groupName, cancellationToken);
    return result is not null ? TypedResults.Ok(result) : TypedResults.NotFound();
}

This gives compile-time guarantees on response types and enables better OpenAPI schema generation without relying on [ProducesResponseType] attributes alone.

Copilot AI and others added 2 commits May 4, 2026 15:31

/// <inheritdoc cref="BuderusQueryService.GetEvents"/>
[HttpGet("{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't TypedResults mean these attributes no longer need to be present?

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.

2 participants