Skip to content

Fix runtime schema resolution and direct construction - #4426

Merged
marcschier merged 4 commits into
masterfrom
fix-runtime-schema-generation
Sep 6, 2026
Merged

Fix runtime schema resolution and direct construction#4426
marcschier merged 4 commits into
masterfrom
fix-runtime-schema-generation

Conversation

@marcschier

@marcschier marcschier commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Description

Fix runtime schema resolution and provide a supported DI-free construction path for generated data types.

  • Resolve registered data types by local/index-form and namespace-URI identifiers without using BrowseName as a namespace mapping.
  • Preserve identifier kind in URI registry keys, so numeric zero and empty GUID/string/ByteString identifiers remain distinct in nonzero namespaces, including during replacement.
  • Reconstruct typed identifiers during factory URI-to-index fallback while retaining exact lookup precedence and unknown-namespace/remote-server guards.
  • Make the built-in JSON, XSD, and BSD generators public, stabilize EncodeableFactoryDefinitionSource, and document generated activator/factory usage.
  • Keep the stable-API assertion effective across the netstandard2.1/net8.0 polyfill boundary by inspecting attribute metadata without referencing the ambiguous CLR type.
  • Merge the latest master without dropping upstream changes.

Related Issues

Validation

  • Opc.Ua.Core.Schema.Tests: 157/157 on net10.0
  • Opc.Ua.Core.Schema.Tests: 157/157 on net48
  • Opc.Ua.Core.Schema.Tests: 157/157 with CustomTestTarget=netstandard2.1 and its net8.0 consumer
  • Managed SchemaAotTests: 4/4
  • NativeAOT Release publish and filtered SchemaAotTests: 4/4
  • All three review reproductions pass against rebuilt assemblies.

Checklist

  • I have signed the CLA and read the CONTRIBUTING doc.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added all necessary documentation.
  • I have verified that my changes do not introduce (new) build or analyzer warnings.
  • I ran all tests locally using the UA.slnx solution against at least .net framework and .net 10, and all passed.
  • I fixed all failing and flaky tests in the CI pipelines and all CodeQL warnings.
  • I have addressed all PR feedback received.

Normalize namespace-index and namespace-URI data type lookup across schema resolvers. Expose the built-in schema generators and stabilize the generated factory definition path for direct construction.

Fixes #4423
Fixes #4424

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b17fd166-fdef-4660-a9d5-97c0e69f1bd5
Copilot AI lite review requested due to automatic review settings September 5, 2026 07:54

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.

🟡 Changes recommended

There is at least one build-blocking unused-using warning introduced in the updated tests (warnings are treated as errors).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes mismatches in runtime schema resolution between namespace-index and namespace-URI ExpandedNodeId forms, and makes the documented “direct construction” schema-generation path viable for non-friend assemblies by promoting the built-in generators and EncodeableFactoryDefinitionSource to stable public API.

Changes:

  • Normalize DataTypeDefinitionRegistry and EncodeableFactoryDefinitionSource resolution across index/URI ExpandedNodeId forms, including replacement/re-index cleanup.
  • Make JSON/XSD/BSD schema generators publicly constructible and remove [Experimental] from EncodeableFactoryDefinitionSource, enabling direct DefaultSchemaProvider construction.
  • Add/extend tests (DI path, direct construction, AOT, replacement scenarios) and update docs/NuGet readme to describe the supported usage patterns.
File summaries
File Description
tests/Opc.Ua.Core.Schema.Tests/SchemaServiceCollectionExtensionsTests.cs Adds DI-based regression test covering URI-form ExpandedNodeId resolution.
tests/Opc.Ua.Core.Schema.Tests/GeneratedTypeDefinitionTests.cs Updates tests to validate generated activator definitions and schema creation via factory definitions.
tests/Opc.Ua.Core.Schema.Tests/EncodeableFactoryDefinitionSourceTests.cs Adds stability/normalization coverage for factory-based resolution (and schema generation) across ID forms.
tests/Opc.Ua.Core.Schema.Tests/DataTypeNodeRegistrationTests.cs Expands registry tests for index/URI lookups and replacement/re-index cleanup.
tests/Opc.Ua.Core.Schema.Tests/ComplexTypeSystemCoverageTests.cs Adjusts experimental-warning comment to reflect current test surface.
tests/Opc.Ua.Aot.Tests/SchemaAotTests.cs Adds AOT smoke coverage for direct provider construction and factory-definition resolution.
src/Opc.Ua.Types/Encoders/IDataTypeDefinitionSource.cs Clarifies interface docs to explicitly include generated activators.
src/Opc.Ua.Server/ComplexTypes/ServerComplexTypeSystem.cs Removes experimental-warning suppressions now that the resolver is stable API.
src/Opc.Ua.Core.Schema/Xsd/XsdSchemaGenerator.cs Makes XSD generator publicly constructible for direct provider construction.
src/Opc.Ua.Core.Schema/Resolution/IDataTypeDefinitionResolver.cs Updates docs to state resolvers accept namespace-index and namespace-URI forms.
src/Opc.Ua.Core.Schema/Resolution/EncodeableFactoryDefinitionSource.cs Removes [Experimental] and adds namespace-table normalization between index/URI ID forms.
src/Opc.Ua.Core.Schema/Resolution/DataTypeDefinitionRegistryExtensions.cs Documents when to pass NamespaceTable to enable URI-form resolution.
src/Opc.Ua.Core.Schema/Resolution/DataTypeDefinitionRegistry.cs Adds namespace-URI lookup map, replacement cleanup, and URI-form ExpandedNodeId resolution.
src/Opc.Ua.Core.Schema/NugetREADME.md Documents direct construction and factory-definition-based resolution path.
src/Opc.Ua.Core.Schema/Json/JsonSchemaGenerator.cs Makes JSON generator publicly constructible for direct provider construction.
src/Opc.Ua.Core.Schema/IUaSchemaGenerator.cs Updates docs to reflect DI or direct provision of generators.
src/Opc.Ua.Core.Schema/DefaultSchemaProvider.cs Minor doc tweak aligning with direct-generator usage.
src/Opc.Ua.Core.Schema/Bsd/BsdSchemaGenerator.cs Makes BSD generator publicly constructible for direct provider construction.
docs/SchemaGeneration.md Updates guidance and examples for direct construction and factory-definition resolver usage, plus URI-form resolution notes.
Review details
  • Files reviewed: 19/19 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Code coverage

Coverage gate passed.

Check Result Threshold
✅ Project line rate 86.79% (240447/277054 lines) >= 70.00%
✅ Project branch rate 76.71% >= 60.00%
✅ Patch coverage 98.97% (96/97 changed lines) >= 60.00% (<= 100 changed lines, advisory)
ℹ️ Baseline delta (advisory) +13.19 pp 73.60% recorded
Uncovered changed lines
  • src/Opc.Ua.Core.Schema/Resolution/EncodeableFactoryDefinitionSource.cs: 183

Coverage is above the recorded baseline - consider ratcheting coverage-thresholds.json.

Thresholds live in coverage-thresholds.json. Whole report before exclusions: line 85.87%, branch 75.84%.

@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.84536% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.87%. Comparing base (017856f) to head (01a5218).

Files with missing lines Patch % Lines
...re.Schema/Resolution/DataTypeDefinitionRegistry.cs 95.00% 0 Missing and 3 partials ⚠️
...ma/Resolution/EncodeableFactoryDefinitionSource.cs 94.59% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4426      +/-   ##
==========================================
- Coverage   80.89%   80.87%   -0.02%     
==========================================
  Files        1984     1984              
  Lines      276971   277054      +83     
  Branches    48061    48084      +23     
==========================================
+ Hits       224045   224066      +21     
- Misses      36411    36456      +45     
- Partials    16515    16532      +17     
Flag Coverage Δ
actions 80.87% <94.84%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/Opc.Ua.Core.Schema/Bsd/BsdSchemaGenerator.cs 80.62% <ø> (ø)
src/Opc.Ua.Core.Schema/DefaultSchemaProvider.cs 100.00% <ø> (ø)
src/Opc.Ua.Core.Schema/Json/JsonSchemaGenerator.cs 89.13% <ø> (-0.55%) ⬇️
...Resolution/DataTypeDefinitionRegistryExtensions.cs 93.33% <ø> (ø)
src/Opc.Ua.Core.Schema/Xsd/XsdSchemaGenerator.cs 80.85% <ø> (ø)
....Ua.Server/ComplexTypes/ServerComplexTypeSystem.cs 74.00% <ø> (ø)
...ma/Resolution/EncodeableFactoryDefinitionSource.cs 93.22% <94.59%> (+2.89%) ⬆️
...re.Schema/Resolution/DataTypeDefinitionRegistry.cs 93.42% <95.00%> (+17.23%) ⬆️

... and 30 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 and others added 3 commits September 5, 2026 15:28
Inspect attribute metadata by full name so the stable API guard works when net8.0 tests reference the netstandard2.1 attribute polyfill.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b17fd166-fdef-4660-a9d5-97c0e69f1bd5
Preserve upstream server, source-generation, and WoT changes alongside the schema fixes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b17fd166-fdef-4660-a9d5-97c0e69f1bd5
Remove BrowseName-derived namespace aliases, discriminate empty identifier kinds in URI keys, and reconstruct typed factory identifiers during URI-to-index fallback. Add regression coverage for public registry, factory, DI, and NativeAOT paths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b17fd166-fdef-4660-a9d5-97c0e69f1bd5
@marcschier
marcschier requested a review from romanett September 6, 2026 15:04
@marcschier
marcschier merged commit 62658d1 into master Sep 6, 2026
271 checks passed
@marcschier
marcschier deleted the fix-runtime-schema-generation branch September 6, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants