feat: add canonical data model pattern#307
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results764 tests 764 ✅ 30s ⏱️ Results for commit 5001de8. |
There was a problem hiding this comment.
Pull request overview
Introduces the Canonical Data Model enterprise integration pattern to PatternKit, including a fluent runtime API, a Roslyn source generator for factory creation, an importable DI example, and documentation/catalog entries to mark the pattern as production-ready.
Changes:
- Added
CanonicalDataModel<TCanonical>runtime andCanonicalDataModelResult<TCanonical>result type for normalizing multiple source contracts into a canonical model. - Added
GenerateCanonicalDataModel/CanonicalDataModelMapperattributes and an incremental generator that emits aCanonicalDataModel<TCanonical>factory method. - Added TinyBDD coverage (runtime, generator, example), wired the example into DI/catalogs, and updated docs + production-readiness catalogs.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/PatternKit.Tests/EnterpriseIntegration/CanonicalDataModel/CanonicalDataModelTests.cs | Adds runtime behavior tests for normalization, failure reporting, and configuration validation. |
| test/PatternKit.Generators.Tests/CanonicalDataModelGeneratorTests.cs | Adds generator tests for source emission and diagnostics (PKCDM001-003). |
| test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs | Extends attribute coverage suite to include canonical data model attributes. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates production-readiness catalog expectations to include the new pattern and count. |
| test/PatternKit.Examples.Tests/CanonicalDataModelDemo/OrderCanonicalDataModelDemoTests.cs | Adds example tests for fluent vs generated paths and DI importability. |
| src/PatternKit.Generators/CanonicalDataModel/CanonicalDataModelGenerator.cs | Implements incremental generator that emits a canonical data model factory from a mapper method. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Registers new generator diagnostics (PKCDM001-003). |
| src/PatternKit.Generators.Abstractions/EnterpriseIntegration/CanonicalDataModelAttributes.cs | Adds generator attribute APIs for canonical data model generation. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Adds canonical data model entry to the production-readiness pattern catalog. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Adds the “Order Canonical Data Model” example descriptor to the example catalog. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Wires the canonical data model demo into AddPatternKitExamples() and registers the aggregate example type. |
| src/PatternKit.Examples/CanonicalDataModelDemo/OrderCanonicalDataModelDemo.cs | Adds the canonical order demo (fluent + generated) and IServiceCollection import extension. |
| src/PatternKit.Core/EnterpriseIntegration/CanonicalDataModel/CanonicalDataModel.cs | Adds the canonical data model runtime and builder-based adapter registration. |
| docs/patterns/toc.yml | Adds the Canonical Data Model pattern to the patterns TOC. |
| docs/patterns/messaging/canonical-data-model.md | New pattern documentation page describing runtime + generated usage. |
| docs/guides/pattern-coverage.md | Adds the pattern to the documented coverage matrix. |
| docs/generators/toc.yml | Adds canonical data model to generator docs navigation. |
| docs/generators/index.md | Adds canonical data model to generator index table. |
| docs/generators/canonical-data-model.md | New generator documentation page describing usage and diagnostics. |
| docs/examples/toc.yml | Adds the order canonical data model example to examples TOC. |
| docs/examples/order-canonical-data-model.md | New example documentation page for DI import and usage. |
| docs/examples/index.md | Adds the new example to the examples landing page. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| => method.IsStatic && | ||
| SymbolEqualityComparer.Default.Equals(method.ReturnType, canonicalType) && | ||
| method.Parameters.Length == 1 && |
|
|
||
| if (!IsMapper(mappers[0], sourceType, canonicalType)) | ||
| { | ||
| context.ReportDiagnostic(Diagnostic.Create(InvalidMapper, mappers[0].Locations.FirstOrDefault(), mappers[0].Name)); |
| if (!_adapters.TryGetValue(typeof(TSource), out var adapter)) | ||
| return CanonicalDataModelResult<TCanonical>.Failure(Name, typeof(TSource).Name, new InvalidOperationException($"No canonical data model adapter is registered for '{typeof(TSource).FullName}'.")); | ||
|
|
| else if (type.IsAbstract && type.TypeKind == TypeKind.Class) | ||
| sb.Append("abstract "); | ||
| else if (type.IsSealed && type.TypeKind == TypeKind.Class) | ||
| sb.Append("sealed "); | ||
| sb.Append("partial ").Append(type.TypeKind == TypeKind.Struct ? "struct" : "class").Append(' ').Append(type.Name).AppendLine(); |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #307 +/- ##
==========================================
+ Coverage 90.27% 95.99% +5.71%
==========================================
Files 432 436 +4
Lines 36236 36446 +210
Branches 5137 5167 +30
==========================================
+ Hits 32713 34985 +2272
+ Misses 1557 1461 -96
+ Partials 1966 0 -1966
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
Code Coverage |
Closes #303.
Adds Canonical Data Model runtime, source generator, TinyBDD coverage, importable order example, docs, and production-readiness catalog entries.
Local focused validation passed for core/generator builds and runtime/generator tests across net8/net9/net10. Local full examples tests still hit the known analyzer/compiler mismatch; hosted CI validates the examples graph.