Skip to content

REST polish: return 200 on empty collection, explicit AutoMapper Id ignore #425

@nanotaboada

Description

@nanotaboada

Problem

Two low-severity REST compliance gaps identified during a full RESTful audit:

  1. GET /players returns 404 Not Found when the collection is empty instead of 200 OK []
  2. The Player → PlayerResponseModel AutoMapper mapping does not explicitly ignore the Id (UUID) field — it works correctly today only because PlayerResponseModel has no Id property, not by design intent

Proposed Solution

  1. Return 200 OK with an empty list when no players exist — a 404 implies the resource itself is absent, not that the list is empty
  2. Add an explicit .ForMember(dest => dest.Id, opt => opt.Ignore()) (or equivalent) to the output mapping to make the exclusion intentional and future-proof

Suggested Approach

Empty collection (GET /players):

  • Controllers/PlayerController.cs lines 99–113 — replace the players.Count == 0 branch from TypedResults.Problem(404) to TypedResults.Ok(Array.Empty<PlayerResponseModel>()) (or TypedResults.Ok(players) directly, since an empty list is a valid 200 response)

AutoMapper explicit ignore:

  • Mappings/PlayerMappingProfile.cs — in the Player → PlayerResponseModel map, add explicit ignore for Id (if PlayerResponseModel gains an Id property in the future AutoMapper would silently populate it and leak the surrogate key; an explicit ignore fails fast instead)
  • Consider enabling ValidateMemberList on the mapping profile to enforce that all destination members are intentionally mapped or ignored

Acceptance Criteria

  • GET /players returns 200 OK with [] when no players exist (not 404)
  • AutoMapper profile explicitly ignores Id on the Player → PlayerResponseModel mapping
  • Tests updated to cover the empty-collection case
  • All pre-commit checks pass (dotnet build Release, dotnet test, CSharpier)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnetPull requests that update .NET codeenhancementNew feature or requestgood first issueGood for newcomerspriority:highImportant for production readiness. Schedule for current milestone.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions