[SourceGeneration] Generate OPC UA models from WoT Thing Description files - #4134
[SourceGeneration] Generate OPC UA models from WoT Thing Description files#4134marcschier wants to merge 8 commits into
Conversation
The generator now accepts Thing Description and Thing Model documents as AdditionalFiles, alongside the ModelDesign and NodeSet2 inputs it already supported. A .tm.json, .td.json, .tm.jsonld or .td.jsonld file, or a .jsonld file that opts in explicitly, is converted to an in-memory UANodeSet and then runs through the existing NodeSet code generation pipeline, so a WoT model produces the same generated constants, node states and proxies as an equivalent NodeSet2 input. Parsing, conversion and virtual path collision problems are reported as MODELGEN030 through MODELGEN034 rather than as exceptions, so a malformed document fails the build with a diagnostic that points at the input. Roslyn generators must run synchronously, so the conversion is driven through the converter's synchronous entry point; the asynchronous resolver contracts are not used here. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9e6a5abf-3299-4cd1-9855-010fedbf0ad8
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds WoT Thing Model / Thing Description (.tm.json, .td.json, .tm.jsonld, .td.jsonld, plus opted-in .jsonld) support to the OPC UA source generator by converting WoT inputs into in-memory NodeSet2 XML and feeding them through the existing generation pipeline, while projecting conversion failures as structured diagnostics instead of exceptions.
Changes:
- Introduces in-memory WoT→NodeSet2 conversion (
WotNodeSetAdditionalText) and collision-aware WoT input resolution (ResolveWotInputs) with MODELGEN030–034 diagnostics. - Extends the generator pipeline to recognize WoT additional files (including opt-in metadata) and forward conversion diagnostics without crashing.
- Updates documentation and adds/extends tests to cover WoT recognition, diagnostics, collisions, and incremental behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/Opc.Ua.SourceGeneration/readme.md | Documents WoT AdditionalFiles support, opt-in behavior for .jsonld, and MODELGEN030–034 diagnostics. |
| tools/Opc.Ua.SourceGeneration/WotNodeSetAdditionalText.cs | Implements resilient WoT parsing/conversion to in-memory NodeSet2 and projects failures into diagnostics. |
| tools/Opc.Ua.SourceGeneration/WotInputResolution.cs | Adds deterministic resolution of WoT outcomes, including synthesized-path collision detection/diagnostics. |
| tools/Opc.Ua.SourceGeneration/SourceGenerator.cs | Defines MODELGEN030–034 diagnostic descriptors for WoT parsing/conversion/collision scenarios. |
| tools/Opc.Ua.SourceGeneration/OPCFoundation.Opc.Ua.SourceGeneration.props | Exposes per-file ModelSourceGeneratorWot metadata to the generator. |
| tools/Opc.Ua.SourceGeneration/NugetREADME.md | Notes WoT inputs are accepted and links to detailed documentation. |
| tools/Opc.Ua.SourceGeneration/ModelSourceGenerator.cs | Integrates WoT recognition/conversion + diagnostics into the incremental generator pipeline. |
| tools/Opc.Ua.SourceGeneration/Extensions.cs | Adds WoT extension recognition and the .jsonld opt-in switch (ModelSourceGeneratorWot). |
| tools/Opc.Ua.SourceGeneration/AnalyzerReleases.Unshipped.md | Registers new MODELGEN030–034 diagnostics. |
| tests/Opc.Ua.SourceGeneration.Tests/WotNodeSetConversionFailureTests.cs | Adds unit tests for WoT wrapper failure modes and diagnostic projection behavior. |
| tests/Opc.Ua.SourceGeneration.Tests/ModelGeneratorTests.cs | Adds end-to-end generator tests for WoT recognition, opt-in/ignore behavior, collisions, and incremental reruns. |
Map System.Text.Json byte offsets back to SourceText UTF-16 columns so parse diagnostics stay accurate for non-ASCII WoT inputs. Also stream SourceText to UTF-8 to avoid the extra whole-file string allocation before parsing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9e6a5abf-3299-4cd1-9855-010fedbf0ad8
…erator-wot # Conflicts: # tools/Opc.Ua.SourceGeneration/ModelSourceGenerator.cs
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## marcschier/wot-03-converter #4134 +/- ##
===============================================================
+ Coverage 75.01% 80.09% +5.07%
===============================================================
Files 1519 1539 +20
Lines 212830 214557 +1727
Branches 36726 37070 +344
===============================================================
+ Hits 159651 171841 +12190
+ Misses 40534 29859 -10675
- Partials 12645 12857 +212
🚀 New features to boost your workflow:
|
Summary
Stack context
This is PR 4 of the stacked split of integration PR #4093. It is stacked on #4131 (
marcschier/wot-03-converter) and should be reviewed and merged after that PR.The source-generation entry-point project is included whole in this PR because its final state is irreducibly WoT-coupled. The genuinely generic generator work lives in the separate PR 2 branch.
Notes
Roslyn source generators must run synchronously. This PR drives WoT conversion through the converter's synchronous entry point and does not use the asynchronous resolver contracts from generator code.
Validation
dotnet build tools\Opc.Ua.SourceGeneration\Opc.Ua.SourceGeneration.csproj -c Release -v:mdotnet build tests\Opc.Ua.SourceGeneration.Tests\Opc.Ua.SourceGeneration.Tests.csproj -c Release -p:CustomTestTarget=net10.0 -v:mdotnet test tests\Opc.Ua.SourceGeneration.Tests\Opc.Ua.SourceGeneration.Tests.csproj -c Release -p:CustomTestTarget=net10.0 --no-builddotnet build tests\Opc.Ua.SourceGeneration.Tests\Opc.Ua.SourceGeneration.Tests.csproj -c Release -p:CustomTestTarget=net48 -v:mdotnet test tests\Opc.Ua.SourceGeneration.Tests\Opc.Ua.SourceGeneration.Tests.csproj -c Release -p:CustomTestTarget=net48 --no-build