Merge-patch enum fields and the storage encryption mode take names only #324
Labels
No labels
agent
api-regen
agent
architect
agent
coder
agent
console-coder
agent
docs-writer
agent
mechanic
agent
protocol-coder
agent
storage-coder
area/api
area/ci
area/console
area/dhcp
area/dns
area/docs
area/packaging
area/process
area/storage
area/windows
kind
bug
kind
chore
kind
docs
kind
epic
kind
feature
kind
performance
kind
security
kind
test
priority
high
priority
low
priority
medium
resolution
duplicate
resolution
not-a-bug
resolution
wontfix
status
blocked
status
in-progress
status
needs-decision
status
needs-design
status
ready
theme
ad-samba-dns
theme
alternatives-benchmark
theme
console-toolchain
theme
later
theme
parity-devices
theme
parity-query
theme
post-release-fixes
theme
tracker-setup
theme
valkey
theme
windows-installer
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
Depends on
#316 Epic: Enum fields in API request bodies accept names only
lantea-one/ninlil
#326 The changelog and README say API enum fields take names only
lantea-one/ninlil
#323 Typed request bodies refuse enum numbers and digit strings
lantea-one/ninlil
Reference
lantea-one/ninlil#324
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of epic #316.
Why
Merge-patch actions read enums with
JsonSerializer.Deserialize<TEnum>and the attributeconverter, so
PATCH /api/zones/{id}with"type":"1"passes.encryptionModeusesEnum.TryParse, so"1"passes.What changes
A new
JsonElementMergePatchExtension.GetEnumName<TEnum>is used at the 12 raw-read sites and inDnssecPolicySettingsController.ParseAllowedAlgorithms.StorageConnectionStringAssemblerusesEnumNameParser.Acceptance
EnumNamesOnlyRequestBodyTests,JsonElementMergePatchExtensionTestsandStorageConnectionStringAssemblerTestspass, and fail before the change.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
src/dotnet/src/Ninlil.Web/Extension/JsonElementMergePatchExtension.cs: addpublic static TEnum GetEnumName<TEnum>(this JsonElement element, string fieldPath) where TEnum : struct, Enum.It deserializes with one static
JsonSerializerOptions(JsonSerializerDefaults.Web)that holdsRequestEnumNameJsonConverterFactory, and turnsJsonExceptionintoValidationException("'<fieldPath>' must be one of: <ValidNames>."). Use the helper's namelist, not
Enum.GetNames, so wire names are shown.ZonesController.cs:270,280,291,444RecordsController.cs:262,309FilterListsController.cs:265,268,272WebhooksController.cs:346DhcpScopesController.cs:452CloudProviderCredentialsController.cs:245DnssecPolicySettingsController.cs:105-122: parse each item with the same converter (awrapper that reads a string), keep the signing-prohibited check, and drop the
IsDefinedworkaround and its comment.
StorageConnectionStringAssembler.cs:90,116: useEnumNameParser.TryParseName(validated.EncryptionMode, ignoreCase: true, out …), and fix thesummary at
:30-38.src/dotnet/tests/Ninlil.Web.Tests/EnumNamesOnlyRequestBodyTests.cs(extend)src/dotnet/tests/Ninlil.Web.Tests/StorageConnectionStringAssemblerTests.cssrc/dotnet/tests/Ninlil.Web.Tests/JsonElementMergePatchExtensionTests.csPatchZone_WithADigitStringForAnEnumField_ReturnsBadRequestListingTheValidNamesPatchRecord_WithADigitStringTypeOrClass_ReturnsBadRequestPatchFilterList_WithADigitStringKindActionOrSource_ReturnsBadRequestPatchWebhook_WithADigitStringAuthMode_ReturnsBadRequestPatchDhcpScope_WithADigitStringKind_ReturnsBadRequestPatchCloudProviderCredential_WithADigitStringProviderType_ReturnsBadRequestPatchDnssecPolicy_WithADigitStringAllowedAlgorithm_ReturnsBadRequest("13")PatchZone_WithTheConsoleWireNames_SucceedsGetEnumName_ForAJsonNumber_ThrowsValidationExceptionNamingTheFieldAssemble_WithADigitStringEncryptionMode_ThrowsValidationException(PostgreSql and MySql,"1"and"99")Assemble_WithAnEncryptionModeNameInAnyCase_BuildsTheConnectionStringTryGetMergePatchEnumcallers, which are names-only already.Ghost referenced this issue2026-11-05 19:14:49 -05:00
Ghost referenced this issue2026-11-05 20:00:31 -05:00
Ghost referenced this issue2026-11-05 20:01:25 -05:00