Repository navigation
Conversation
WalkthroughIntroduces an optional JsonTypeInfo modifier across adapter registration and JSON configuration. Adds a jsonTypeModifier parameter to CustomAdapterProvider.Add, extends AdapterRegistration to carry it, and updates CrdtConfig to invoke per-type modifiers via a cached RegistrationsByType map, which is frozen and reused after configuration. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Dev as Developer
participant CAP as CustomAdapterProvider
participant OR as AdapterRegistration
participant OTB as ObjectTypeListBuilder
participant CC as CrdtConfig
participant STJ as System.Text.Json
Dev->>CAP: Add<T>(configureEntry?, jsonTypeModifier?)
CAP->>OR: Create AdapterRegistration(T, EntityBuilder, JsonTypeModifier)
CAP-->>Dev: Registration stored via provider(s)
Note over CC,OTB: During configuration freeze
CC->>OTB: Freeze()
OTB->>OTB: Compute RegistrationsByType (or use cached)
OTB-->>CC: Cached map ready
Note over STJ,CC: At runtime JSON metadata creation
STJ->>CC: Apply global JsonTypeModifier(typeInfo)
CC->>OTB: Find registration by type
alt Registration found with JsonTypeModifier
CC->>OR: Invoke registration.JsonTypeModifier(typeInfo)
else No per-type modifier
CC-->>STJ: No-op
end
STJ-->>Dev: Finalized JsonTypeInfo
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Warning Tools execution failed with the following error: Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error) Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/SIL.Harmony/Adapters/CustomAdapterProvider.cs (1)
22-28: Expose jsonTypeModifier on AddWithCustomPolymorphicMapping as wellRight now, callers using AddWithCustomPolymorphicMapping can’t pass a JsonTypeInfo modifier without switching to Add. Consider adding an overload to keep the ergonomic flow consistent.
Example (new overload):
public CustomAdapterProvider<TCommonInterface, TCustomAdapter> AddWithCustomPolymorphicMapping<T>( string typeName, Action<EntityTypeBuilder<T>>? configureEntry = null, Action<JsonTypeInfo>? jsonTypeModifier = null ) where T : class, TCommonInterface { JsonTypes.AddDerivedType(typeof(TCommonInterface), typeof(T), typeName); return Add(configureEntry, jsonTypeModifier); }src/SIL.Harmony/CrdtConfig.cs (2)
73-77: Prefer TryGetValue over GetValueOrDefault and remove redundant equality checkAvoid relying on extension availability and simplify the condition.
- var registration = ObjectTypeListBuilder.RegistrationsByType.GetValueOrDefault(typeInfo.Type); - if (registration?.JsonTypeModifier is not null && registration.ObjectDbType == typeInfo.Type) - { - registration.JsonTypeModifier(typeInfo); - } + if (ObjectTypeListBuilder.RegistrationsByType.TryGetValue(typeInfo.Type, out var registration) + && registration.JsonTypeModifier is not null) + { + registration.JsonTypeModifier(typeInfo); + }
166-169: Duplicate registration guard (optional)ToDictionary will throw a generic exception on duplicate ObjectDbType. Consider emitting a clearer error by pre‑validating duplicates.
Sketch:
private IReadOnlyDictionary<Type, AdapterRegistration> BuildRegistrationsByType() { var regs = AdapterProviders.SelectMany(p => p.GetRegistrations()); var dups = regs.GroupBy(r => r.ObjectDbType).Where(g => g.Skip(1).Any()).Select(g => g.Key).ToArray(); if (dups.Length > 0) throw new InvalidOperationException($"Multiple adapter registrations for: {string.Join(", ", dups.Select(t => t.FullName))}"); return regs.ToDictionary(r => r.ObjectDbType); }Then have RegistrationsByType delegate to BuildRegistrationsByType() when not frozen.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/SIL.Harmony/Adapters/CustomAdapterProvider.cs(4 hunks)src/SIL.Harmony/Adapters/IObjectAdapterProvider.cs(1 hunks)src/SIL.Harmony/CrdtConfig.cs(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/SIL.Harmony/Adapters/IObjectAdapterProvider.cs (1)
src/SIL.Harmony/CrdtConfig.cs (2)
Action(39-42)JsonTypeModifier(52-78)
src/SIL.Harmony/Adapters/CustomAdapterProvider.cs (1)
src/SIL.Harmony/CrdtConfig.cs (1)
Action(39-42)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: Analyze (csharp)
🔇 Additional comments (4)
src/SIL.Harmony/Adapters/CustomAdapterProvider.cs (2)
30-33: Add JSON type modifier: API extension looks goodNew optional parameter is well-placed and backward‑compatible.
37-44: Correctly forwarding jsonTypeModifier to AdapterRegistrationForwarding the delegate into the registration ensures per‑type customization is reachable from the resolver.
src/SIL.Harmony/Adapters/IObjectAdapterProvider.cs (1)
7-7: AdapterRegistration gains optional JsonTypeModifierChange is internal, backward‑compatible (default = null), and aligns with usage.
src/SIL.Harmony/CrdtConfig.cs (1)
140-141: Freezing and caching registrations mapCapturing a frozen snapshot before wiring model configurations is a good move for stability.
|
Not actually necessary. |
Summary by CodeRabbit