docs: spec-follows-runtime naming decision + casing wart (#198)
- api-conventions.md §5a: runtime Newtonsoft casing vs generated spec, the schema transformer that mirrors it, and the contract test guarding it. - decisions.md: append the "wire format is source of truth; spec follows via the real contract resolver" decision. - spa-conventions.md §4: trust the generated key casing; note the removed troubleshooting escape hatch and runtime-cased test mocks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -121,6 +121,31 @@ gets this wrong. The SPA works around it with a manual override type; see `web/s
|
||||
`PlayoutAlternateSchedule`, `PlayoutTemplate`, and their request types). Copy this pattern for any
|
||||
new DTO with a `DayOfWeek` (or `DayOfWeek[]`) member — don't trust the generated numeric type.
|
||||
|
||||
### 5a. Runtime JSON casing vs the generated spec (the `ffmpegProfileId` wart)
|
||||
|
||||
Runtime `/api/*` JSON is serialized by **Newtonsoft** (`AddNewtonsoftJson` in `Startup.cs`), using
|
||||
`ErsatzTV/Serialization/CustomContractResolver.cs` → `CustomNamingStrategy` (camelCase **plus** a
|
||||
special case mapping any `FFmpegProfileId` member to `"ffmpegProfileId"`, and honoring any
|
||||
`[JsonProperty("...")]` attribute, e.g. `ChannelResponseModel.FFmpegProfile` →
|
||||
`[JsonProperty("ffmpegProfile")]`). The OpenAPI document, however, is generated from
|
||||
**System.Text.Json** metadata, whose camelCase can differ (it emitted `fFmpegProfileId` /
|
||||
`fFmpegProfile`). That drift silently gave the SPA the wrong key to read (issue #198).
|
||||
|
||||
Fix (do not remove): `ErsatzTV/Serialization/NewtonsoftSchemaNamingTransformer.cs` is an OpenAPI
|
||||
**schema transformer** registered on all three documents (`options.AddSchemaTransformer(...)` in
|
||||
`Startup.cs`). For each object schema it resolves the CLR type's Newtonsoft `JsonObjectContract`
|
||||
through the *same* `CustomContractResolver` the runtime uses and renames `schema.Properties` (and
|
||||
`schema.Required`) keys to the exact names Newtonsoft would emit. This mirrors the wire format **by
|
||||
construction**, so future naming-strategy special cases or `[JsonProperty]` renames can't drift.
|
||||
|
||||
Guard: `ErsatzTV.Tests/Controllers/OpenApiSerializerContractTests.cs` serializes fully-populated
|
||||
DTOs (ChannelViewModel, FFmpegSettingsResponseModel, WatermarkViewModel,
|
||||
MediaItemInfoResponseModel) through the runtime Newtonsoft settings and asserts the emitted top-level
|
||||
keys equal the corresponding `v1.json` schema's property set. It fails if spec generation ever drifts
|
||||
from the MVC serializer again. Note: only exact-match `FFmpegProfileId` gets the special case —
|
||||
`DefaultFFmpegProfileId` stays `defaultFFmpegProfileId` under both serializers, and non-acronym or
|
||||
single-leading-cap names (`fFmpegPath`, `fFprobePath`, `zIndex`, `rFrameRate`) already agree.
|
||||
|
||||
## 6. Tests
|
||||
|
||||
- **Controller tests**: `ErsatzTV.Tests/Controllers/<Domain>ControllerTests.cs`. NUnit + Shouldly +
|
||||
|
||||
Reference in New Issue
Block a user