Merge-patch enum fields and the storage encryption mode take names only #324

Closed
opened 2026-11-05 19:14:48 -05:00 by claude · 0 comments
Owner

Part of epic #316.

  • Kind: bug
  • Area: api
  • Priority: low
  • Milestone: Post-release fixes
  • Agent: coder
  • Depends on: #323
  • Decisions: Q-API-1 (#260)

Why

Merge-patch actions read enums with JsonSerializer.Deserialize<TEnum> and the attribute
converter, so PATCH /api/zones/{id} with "type":"1" passes. encryptionMode uses
Enum.TryParse, so "1" passes.

What changes

A new JsonElementMergePatchExtension.GetEnumName<TEnum> is used at the 12 raw-read sites and in
DnssecPolicySettingsController.ParseAllowedAlgorithms. StorageConnectionStringAssembler uses
EnumNameParser.

Acceptance

  • The WP-2 tests in EnumNamesOnlyRequestBodyTests, JsonElementMergePatchExtensionTests and StorageConnectionStringAssemblerTests pass, and fail before the change.
  • Every item in Before you finish that applies is done.

Source

Architect design for #316: §1.2 and WP-2. ZonesController.cs:270-293,444, RecordsController.cs:262,309,
FilterListsController.cs:265-272, WebhooksController.cs:346, DhcpScopesController.cs:452,
CloudProviderCredentialsController.cs:245, DnssecPolicySettingsController.cs:105-122,
StorageConnectionStringAssembler.cs:90,116.

Work package detail

  • Goal: the remaining hand-read body enums follow the same rule and message.
  • Files:
    • src/dotnet/src/Ninlil.Web/Extension/JsonElementMergePatchExtension.cs: add
      public static TEnum GetEnumName<TEnum>(this JsonElement element, string fieldPath) where TEnum : struct, Enum.
      It deserializes with one static JsonSerializerOptions(JsonSerializerDefaults.Web) that holds
      RequestEnumNameJsonConverterFactory, and turns JsonException into
      ValidationException("'<fieldPath>' must be one of: <ValidNames>."). Use the helper's name
      list, not Enum.GetNames, so wire names are shown.
    • Call sites:
      • ZonesController.cs:270,280,291,444
      • RecordsController.cs:262,309
      • FilterListsController.cs:265,268,272
      • WebhooksController.cs:346
      • DhcpScopesController.cs:452
      • CloudProviderCredentialsController.cs:245
    • DnssecPolicySettingsController.cs:105-122: parse each item with the same converter (a
      wrapper that reads a string), keep the signing-prohibited check, and drop the IsDefined
      workaround and its comment.
    • StorageConnectionStringAssembler.cs:90,116: use
      EnumNameParser.TryParseName(validated.EncryptionMode, ignoreCase: true, out …), and fix the
      summary at :30-38.
    • Tests:
      • src/dotnet/tests/Ninlil.Web.Tests/EnumNamesOnlyRequestBodyTests.cs (extend)
      • src/dotnet/tests/Ninlil.Web.Tests/StorageConnectionStringAssemblerTests.cs
      • src/dotnet/tests/Ninlil.Web.Tests/JsonElementMergePatchExtensionTests.cs
  • Acceptance: red first.
    • PatchZone_WithADigitStringForAnEnumField_ReturnsBadRequestListingTheValidNames
    • PatchRecord_WithADigitStringTypeOrClass_ReturnsBadRequest
    • PatchFilterList_WithADigitStringKindActionOrSource_ReturnsBadRequest
    • PatchWebhook_WithADigitStringAuthMode_ReturnsBadRequest
    • PatchDhcpScope_WithADigitStringKind_ReturnsBadRequest
    • PatchCloudProviderCredential_WithADigitStringProviderType_ReturnsBadRequest
    • PatchDnssecPolicy_WithADigitStringAllowedAlgorithm_ReturnsBadRequest ("13")
    • PatchZone_WithTheConsoleWireNames_Succeeds
    • GetEnumName_ForAJsonNumber_ThrowsValidationExceptionNamingTheField
    • Assemble_WithADigitStringEncryptionMode_ThrowsValidationException (PostgreSql and MySql,
      "1" and "99")
    • Assemble_WithAnEncryptionModeNameInAnyCase_BuildsTheConnectionString
  • Non-goals: TryGetMergePatchEnum callers, which are names-only already.
  • Depends on: #323
  • Changes: API behaviour, yes. Schema, options and OpenAPI, no.
  • Gate: the same as WP-1.
Part of epic #316. - **Kind:** bug - **Area:** api - **Priority:** low - **Milestone:** Post-release fixes - **Agent:** coder - **Depends on:** #323 - **Decisions:** Q-API-1 (#260) #### Why Merge-patch actions read enums with `JsonSerializer.Deserialize<TEnum>` and the attribute converter, so `PATCH /api/zones/{id}` with `"type":"1"` passes. `encryptionMode` uses `Enum.TryParse`, so `"1"` passes. #### What changes A new `JsonElementMergePatchExtension.GetEnumName<TEnum>` is used at the 12 raw-read sites and in `DnssecPolicySettingsController.ParseAllowedAlgorithms`. `StorageConnectionStringAssembler` uses `EnumNameParser`. #### Acceptance - [ ] The WP-2 tests in `EnumNamesOnlyRequestBodyTests`, `JsonElementMergePatchExtensionTests` and `StorageConnectionStringAssemblerTests` pass, and fail before the change. - [ ] Every item in [Before you finish](https://git.lantea.one/lantea-one/ninlil/src/branch/main/AGENTS.md#before-you-finish) that applies is done. #### Source Architect design for #316: §1.2 and WP-2. `ZonesController.cs:270-293,444`, `RecordsController.cs:262,309`, `FilterListsController.cs:265-272`, `WebhooksController.cs:346`, `DhcpScopesController.cs:452`, `CloudProviderCredentialsController.cs:245`, `DnssecPolicySettingsController.cs:105-122`, `StorageConnectionStringAssembler.cs:90,116`. ### Work package detail - **Goal:** the remaining hand-read body enums follow the same rule and message. - **Files:** - `src/dotnet/src/Ninlil.Web/Extension/JsonElementMergePatchExtension.cs`: add `public static TEnum GetEnumName<TEnum>(this JsonElement element, string fieldPath) where TEnum : struct, Enum`. It deserializes with one static `JsonSerializerOptions(JsonSerializerDefaults.Web)` that holds `RequestEnumNameJsonConverterFactory`, and turns `JsonException` into `ValidationException("'<fieldPath>' must be one of: <ValidNames>.")`. Use the helper's name list, not `Enum.GetNames`, so wire names are shown. - Call sites: - `ZonesController.cs:270,280,291,444` - `RecordsController.cs:262,309` - `FilterListsController.cs:265,268,272` - `WebhooksController.cs:346` - `DhcpScopesController.cs:452` - `CloudProviderCredentialsController.cs:245` - `DnssecPolicySettingsController.cs:105-122`: parse each item with the same converter (a wrapper that reads a string), keep the signing-prohibited check, and drop the `IsDefined` workaround and its comment. - `StorageConnectionStringAssembler.cs:90,116`: use `EnumNameParser.TryParseName(validated.EncryptionMode, ignoreCase: true, out …)`, and fix the summary at `:30-38`. - Tests: - `src/dotnet/tests/Ninlil.Web.Tests/EnumNamesOnlyRequestBodyTests.cs` (extend) - `src/dotnet/tests/Ninlil.Web.Tests/StorageConnectionStringAssemblerTests.cs` - `src/dotnet/tests/Ninlil.Web.Tests/JsonElementMergePatchExtensionTests.cs` - **Acceptance:** red first. - `PatchZone_WithADigitStringForAnEnumField_ReturnsBadRequestListingTheValidNames` - `PatchRecord_WithADigitStringTypeOrClass_ReturnsBadRequest` - `PatchFilterList_WithADigitStringKindActionOrSource_ReturnsBadRequest` - `PatchWebhook_WithADigitStringAuthMode_ReturnsBadRequest` - `PatchDhcpScope_WithADigitStringKind_ReturnsBadRequest` - `PatchCloudProviderCredential_WithADigitStringProviderType_ReturnsBadRequest` - `PatchDnssecPolicy_WithADigitStringAllowedAlgorithm_ReturnsBadRequest` (`"13"`) - `PatchZone_WithTheConsoleWireNames_Succeeds` - `GetEnumName_ForAJsonNumber_ThrowsValidationExceptionNamingTheField` - `Assemble_WithADigitStringEncryptionMode_ThrowsValidationException` (PostgreSql and MySql, `"1"` and `"99"`) - `Assemble_WithAnEncryptionModeNameInAnyCase_BuildsTheConnectionString` - **Non-goals:** `TryGetMergePatchEnum` callers, which are names-only already. - **Depends on:** #323 - **Changes:** API behaviour, yes. Schema, options and OpenAPI, no. - **Gate:** the same as WP-1.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#324
No description provided.