refactor(sql): #1076 one shared Sql DriverConfig JSON options (Sql.Contracts SqlDriverConfigJson) for driver factory and deploy gate; parity test

This commit is contained in:
Joseph Doherty
2026-12-03 16:28:04 -05:00
parent fe4bbbe256
commit 98dc4c24a1
4 changed files with 58 additions and 25 deletions
@@ -0,0 +1,31 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace ZB.MOM.WW.OtOpcUa.Driver.Sql.Contracts;
/// <summary>
/// The ONE definition of how a Sql <c>DriverConfig</c> blob is read (lmxopcua#1076). The driver factory deserialises
/// <see cref="SqlDriverConfigDto"/> with <see cref="Options"/>, and the deploy gate (<c>SqlTagDeployChecks</c>, which
/// cannot reference the driver assembly) uses the same instance, so the gate can never be looser or stricter than
/// the driver about what the JSON means.
/// <list type="bullet">
/// <item>Case-insensitive property names, camelCase naming policy (so a write round-trips to the authored shape).</item>
/// <item>Comments and trailing commas tolerated.</item>
/// <item>Unknown members skipped — a blob authored against another schema version must not brick the driver.</item>
/// <item>Enums read as names or ordinals, always written as names (the enum-serialization guard).</item>
/// </list>
/// Treat as read-only: do not mutate after first use.
/// </summary>
public static class SqlDriverConfigJson
{
/// <summary>Serializer options shared by the driver factory, the probe and the deploy gate.</summary>
public static readonly JsonSerializerOptions Options = new()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
ReadCommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true,
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
Converters = { new JsonStringEnumConverter() },
};
}
@@ -47,15 +47,7 @@ public static class SqlDriverFactoryExtensions
/// what makes a <em>write</em> round-trip to the authored shape.</item>
/// </list>
/// </summary>
internal static readonly JsonSerializerOptions JsonOptions = new()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
ReadCommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true,
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
Converters = { new JsonStringEnumConverter() },
};
internal static readonly JsonSerializerOptions JsonOptions = SqlDriverConfigJson.Options;
/// <summary>The serializer options, exposed so tests can assert the enum guard on a real round-trip.</summary>
internal static JsonSerializerOptions JsonOptionsForTest => JsonOptions;