Skip to content

[SourceGeneration] Generate OPC UA models from WoT Thing Description files - #4134

Open
marcschier wants to merge 8 commits into
marcschier/wot-02-sourcegenfrom
marcschier/wot-04-generator-wot
Open

[SourceGeneration] Generate OPC UA models from WoT Thing Description files#4134
marcschier wants to merge 8 commits into
marcschier/wot-02-sourcegenfrom
marcschier/wot-04-generator-wot

Conversation

@marcschier

Copy link
Copy Markdown
Collaborator

Summary

  • Adds WoT Thing Description and Thing Model AdditionalFiles support to Opc.Ua.SourceGeneration for .tm.json, .td.json, .tm.jsonld, .td.jsonld, and explicitly opted-in .jsonld inputs.
  • Converts WoT inputs to an in-memory UANodeSet and reuses the existing NodeSet generation pipeline for constants, node states, and proxies.
  • Reports parsing, conversion, and virtual path collision failures as MODELGEN030 through MODELGEN034 diagnostics instead of generator exceptions.

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:m
  • dotnet build tests\Opc.Ua.SourceGeneration.Tests\Opc.Ua.SourceGeneration.Tests.csproj -c Release -p:CustomTestTarget=net10.0 -v:m
  • dotnet test tests\Opc.Ua.SourceGeneration.Tests\Opc.Ua.SourceGeneration.Tests.csproj -c Release -p:CustomTestTarget=net10.0 --no-build
  • dotnet build tests\Opc.Ua.SourceGeneration.Tests\Opc.Ua.SourceGeneration.Tests.csproj -c Release -p:CustomTestTarget=net48 -v:m
  • dotnet test tests\Opc.Ua.SourceGeneration.Tests\Opc.Ua.SourceGeneration.Tests.csproj -c Release -p:CustomTestTarget=net48 --no-build

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
Copilot AI review requested due to automatic review settings July 31, 2026 15:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tools/Opc.Ua.SourceGeneration/WotNodeSetAdditionalText.cs
Comment thread tools/Opc.Ua.SourceGeneration/WotNodeSetAdditionalText.cs
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

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.53755% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.09%. Comparing base (fc38861) to head (bdbdd9a).

Files with missing lines Patch % Lines
...pc.Ua.SourceGeneration/WotNodeSetAdditionalText.cs 78.67% 21 Missing and 8 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                       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     
Files with missing lines Coverage Δ
tools/Opc.Ua.SourceGeneration/Extensions.cs 94.84% <100.00%> (+0.94%) ⬆️
...ls/Opc.Ua.SourceGeneration/ModelSourceGenerator.cs 100.00% <100.00%> (ø)
tools/Opc.Ua.SourceGeneration/SourceGenerator.cs 93.85% <100.00%> (+1.59%) ⬆️
...ools/Opc.Ua.SourceGeneration/WotInputResolution.cs 100.00% <100.00%> (ø)
...pc.Ua.SourceGeneration/WotNodeSetAdditionalText.cs 78.67% <78.67%> (ø)

... and 276 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcschier
marcschier changed the base branch from marcschier/wot-03-converter to marcschier/wot-02-sourcegen August 1, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants