Epic: Enum fields in API request bodies accept names only #316

Closed
opened 2026-11-05 14:53:04 -05:00 by claude · 2 comments
Owner
  • Priority: low
  • Agent: architect (policy), then coder
  • Depends on: #296
  • Decisions: Q-REL-5 ("names only" for every enum the API takes as text); needs a decision on wire codes, see below

Why

#296 made hand-parsed enum text accept member names only. Enum fields in typed request bodies are bound by JSON converters instead, and they still accept digit strings, and some accept JSON numbers and undefined values. Probed by the #296 verifier through the shared Web test host:

Endpoint and field Converter Digit string JSON number Undefined value
POST /api/dhcp-tag-rules vendorClassIdentifierMatchMode (and userClassMatchMode) BCL JsonStringEnumConverter<T> (default options) "1", "5" → 201 1, 5 → 201 5 stored
POST /api/zones type EnumDescriptionJsonConverter<T> "0" → 201 400 "99" stored
POST /api/zones dnssecAlgorithm EnumDescriptionJsonConverter<T> "13" → 201 400 "200" stored
POST /api/zones denialOfExistenceMode EnumDescriptionJsonConverter<T> "1" → 201 400 "99" stored
POST /api/zones/{id}/dnssec-keys role EnumDescriptionJsonConverter<T> "1" → 201 400 "9" stored
POST /api/zones/{id}/dnssec-keys algorithm EnumDescriptionJsonConverter<T> "13" → 201 400 "200" → 400 (controller check)

There is no AddJsonOptions in Program.cs; each enum carries a [JsonConverter] attribute. EnumDescriptionJsonConverter (src/dotnet/src/Ninlil.Common.Extension/Converter/EnumDescriptionJsonConverter.cs) resolves strings through ToEnumStringExtension.TryToEnum, which accepts any digit string on purpose, so wire codes without a named member (for example a record type or algorithm number Ninlil does not name) can be read back. That is why this needs a design decision rather than a blanket change.

Other text sites the #296 verifier found, outside the hand-parsed list #296 covered:

  • src/dotnet/src/Ninlil.Web/Services/Storage/StorageConnectionStringAssembler.cs:90,116: Enum.TryParse(..., ignoreCase: true) for SslMode / MySqlSslMode from the API's EncryptionMode (StorageModels.cs:190); digit strings pass.
  • src/dotnet/src/Ninlil.Dns.Data.EntityFrameworkCore/Topology/MySqlConnectionStringComposer.cs:144 and src/dotnet/src/Ninlil.Dns.Data.MongoDb/Topology/MongoClientSettingsComposer.cs:204: Enum.TryParse on topology text (MySqlLoadBalance, ReadPreferenceMode); check whether the text comes from the API.
  • src/dotnet/src/Ninlil.Web/Controllers/DnssecPolicySettingsController.cs:118: accepts a defined algorithm as a digit string ("13").

What to decide (architect)

  • Request bodies: names only (refuse digit strings, JSON numbers and undefined values), per Q-REL-5? Or allow digits for enums whose wire space is open (record type, record class, DNSSEC algorithm) where an operator may need an unnamed code? Responses keep writing names (and wire codes where no name exists).
  • Where to enforce: a names-only mode of the converters for request binding, or a validation step after binding, without breaking reading stored data and responses that carry unnamed codes.

What changes (after the decision)

  • Apply the rule to every body enum and the text sites above, with a 400 listing the valid names like #296.

Acceptance

  • Web.Tests: for each body field above, a digit string, a JSON number and an undefined value give 400 (or the decided exception), and every valid name is still accepted; red first.
  • The admin console's values still pass (it sends names, and wire names such as RSASHA256).
  • OpenApiSnapshotTests passes, or api-regen follows.

Source

Verifier report on #296 (feature/296-enum-names-only).

- **Priority:** low - **Agent:** architect (policy), then coder - **Depends on:** #296 - **Decisions:** Q-REL-5 ("names only" for every enum the API takes as text); needs a decision on wire codes, see below ### Why #296 made hand-parsed enum text accept member names only. Enum fields in typed request bodies are bound by JSON converters instead, and they still accept digit strings, and some accept JSON numbers and undefined values. Probed by the #296 verifier through the shared Web test host: | Endpoint and field | Converter | Digit string | JSON number | Undefined value | |---|---|---|---|---| | `POST /api/dhcp-tag-rules` `vendorClassIdentifierMatchMode` (and `userClassMatchMode`) | BCL `JsonStringEnumConverter<T>` (default options) | `"1"`, `"5"` → 201 | `1`, `5` → 201 | `5` stored | | `POST /api/zones` `type` | `EnumDescriptionJsonConverter<T>` | `"0"` → 201 | 400 | `"99"` stored | | `POST /api/zones` `dnssecAlgorithm` | `EnumDescriptionJsonConverter<T>` | `"13"` → 201 | 400 | `"200"` stored | | `POST /api/zones` `denialOfExistenceMode` | `EnumDescriptionJsonConverter<T>` | `"1"` → 201 | 400 | `"99"` stored | | `POST /api/zones/{id}/dnssec-keys` `role` | `EnumDescriptionJsonConverter<T>` | `"1"` → 201 | 400 | `"9"` stored | | `POST /api/zones/{id}/dnssec-keys` `algorithm` | `EnumDescriptionJsonConverter<T>` | `"13"` → 201 | 400 | `"200"` → 400 (controller check) | There is no `AddJsonOptions` in `Program.cs`; each enum carries a `[JsonConverter]` attribute. `EnumDescriptionJsonConverter` (`src/dotnet/src/Ninlil.Common.Extension/Converter/EnumDescriptionJsonConverter.cs`) resolves strings through `ToEnumStringExtension.TryToEnum`, which accepts any digit string on purpose, so wire codes without a named member (for example a record type or algorithm number Ninlil does not name) can be read back. That is why this needs a design decision rather than a blanket change. Other text sites the #296 verifier found, outside the hand-parsed list #296 covered: - `src/dotnet/src/Ninlil.Web/Services/Storage/StorageConnectionStringAssembler.cs:90,116`: `Enum.TryParse(..., ignoreCase: true)` for `SslMode` / `MySqlSslMode` from the API's `EncryptionMode` (`StorageModels.cs:190`); digit strings pass. - `src/dotnet/src/Ninlil.Dns.Data.EntityFrameworkCore/Topology/MySqlConnectionStringComposer.cs:144` and `src/dotnet/src/Ninlil.Dns.Data.MongoDb/Topology/MongoClientSettingsComposer.cs:204`: `Enum.TryParse` on topology text (`MySqlLoadBalance`, `ReadPreferenceMode`); check whether the text comes from the API. - `src/dotnet/src/Ninlil.Web/Controllers/DnssecPolicySettingsController.cs:118`: accepts a defined algorithm as a digit string (`"13"`). ### What to decide (architect) - Request bodies: names only (refuse digit strings, JSON numbers and undefined values), per Q-REL-5? Or allow digits for enums whose wire space is open (record type, record class, DNSSEC algorithm) where an operator may need an unnamed code? Responses keep writing names (and wire codes where no name exists). - Where to enforce: a names-only mode of the converters for request binding, or a validation step after binding, without breaking reading stored data and responses that carry unnamed codes. ### What changes (after the decision) - Apply the rule to every body enum and the text sites above, with a 400 listing the valid names like #296. ### Acceptance - [ ] Web.Tests: for each body field above, a digit string, a JSON number and an undefined value give 400 (or the decided exception), and every valid name is still accepted; red first. - [ ] The admin console's values still pass (it sends names, and wire names such as `RSASHA256`). - [ ] `OpenApiSnapshotTests` passes, or api-regen follows. ### Source Verifier report on #296 (`feature/296-enum-names-only`).
Author
Owner

Designed (architect), decisions Q-API-1..4 recorded on #260 (names only everywhere; record data out of scope; query strings in #327; no repair of stored rows). Now an epic. Children: #323 (typed bodies, coder) → #324 (merge patches + storage encryption mode, coder) → #326 (CHANGELOG/README, docs-writer); #325 (replica mode settings, mechanic, independent). An OpenAPI snapshot regen follows #323/#324 only if the document changes.

Designed (architect), decisions Q-API-1..4 recorded on #260 (names only everywhere; record data out of scope; query strings in #327; no repair of stored rows). Now an epic. Children: #323 (typed bodies, coder) → #324 (merge patches + storage encryption mode, coder) → #326 (CHANGELOG/README, docs-writer); #325 (replica mode settings, mechanic, independent). An OpenAPI snapshot regen follows #323/#324 only if the document changes.
claude changed title from Enum fields in API request bodies accept member names only to Epic: Enum fields in API request bodies accept names only 2026-11-05 19:14:50 -05:00
Author
Owner

All children (#323, #324, #325, #326) merged into develop through PR #328 and closed. No OpenAPI change, so no api-regen child was needed. Query-string enums continue in #327. Closing the epic.

All children (#323, #324, #325, #326) merged into develop through PR #328 and closed. No OpenAPI change, so no api-regen child was needed. Query-string enums continue in #327. Closing the epic.
claude 2026-11-05 20:01:23 -05:00
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#316
No description provided.