Runtime schema generation for types (XSD, BSD, JSON Schema) + PubSub message schemas#3916
Closed
marcschier wants to merge 2 commits into
Closed
Runtime schema generation for types (XSD, BSD, JSON Schema) + PubSub message schemas#3916marcschier wants to merge 2 commits into
marcschier wants to merge 2 commits into
Conversation
…ubSub messages New Opc.Ua.Core.Schema and Opc.Ua.PubSub.Schema libraries that generate XSD, OPC Binary (BSD) and JSON Schema (Part 6 Annex C, compact + verbose) for generated encodeable types and dynamically added complex types, plus PubSub JSON message-format schemas. Schemas are built as object models in code (trimmable, NativeAOT compatible). Includes ISchemaProvider/IPubSubSchemaProvider DI surface, resolver registry, docs and tests.
…n, packaging Cross-namespace correctness (qualified JSON \ keys; per-namespace XSD/BSD imports) and ValueRanks.Any array modeling. Auto-wiring so types expose their schemas: IDataTypeDefinitionSource on the encodeable activators with a factory-backed resolver, the source generator emitting the definition accessor on generated types, ComplexTypeSystem and server address-space registration helpers. XSD/BSD output validation tests, PubSub coverage and real-message validation, and both new packages added to the pack solution.
marcschier
added a commit
that referenced
this pull request
Jun 29, 2026
Apply whitespace + style + safe analyzer fixes to the files introduced by the #3915 (Ethernet L2 transport) and #3916 (runtime schema generation) squash merges. Removed low-value empty <exception> auto-tags (RCS1140) and restored the two platform-#if Ethernet channel files (AfPacket/Bpf) that dotnet format cannot process across TFMs without emitting "Unmerged change" markers. No behavioural changes; UA.slnx builds 0-warning on net10.0 and the new project test suites pass.
Collaborator
Author
marcschier
added a commit
that referenced
this pull request
Jun 29, 2026
#3916 added a ProjectReference from Opc.Ua.Server to the new Stack/Opc.Ua.Core.Schema project, but the ConsoleReferenceServer Dockerfile's per-project restore layer did not copy that csproj, so `dotnet restore` skipped it and `dotnet publish` failed with NETSDK1004 (assets file not found). Add the missing COPY line for Opc.Ua.Core.Schema.csproj.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds runtime schema generation for OPC UA data types so generated encodeable types and dynamically-added complex types can expose their schemas in every supported encoding. Stacked on the OPC UA Part 14 (PubSub) work and targets the
part14pubsubbranch (#3892).Two new trimmable, NativeAOT-compatible libraries:
Stack/Opc.Ua.Core.Schema— injectableISchemaProviderviaservices.AddOpcUa().AddSchemaGeneration()(direct construction also supported). Generators, each per-type and per-namespace (with per-namespace$ref/importresolution across namespaces):JsonEncoder(Int64/UInt64 → string, ByteString → base64, Float/Double →number|string, standard built-ins emitted once in$defs, unions, enums, value ranks,$refdependency closure, and the compactSwitchField/EncodingMaskmembers).System.Xml.Schema.XmlSchemaobject model, per-namespacexs:import.Opc.Ua.Schema.Binaryobject model serialized via a directXmlWriter; optional-field structs use the leading 32-bitEncodingMask, unions useSwitchField, per-namespaceopc:Import.IDataTypeDefinitionResolver, in-memoryDataTypeDefinitionRegistry,EncodeableFactoryDefinitionSource(reads definitions exposed by the encodeable factory) andCompositeDataTypeDefinitionResolver; thin extension API (GetXmlSchema/GetBinarySchema/GetJsonSchema/TryGetJsonSchema).Libraries/Opc.Ua.PubSub.Schema—AddPubSubSchema()→IPubSubSchemaProvider: per-DataSet field schemas built fromDataSetMetaDataType/FieldMetaDatahonoringDataSetFieldContentMask, plusua-dataNetworkMessage / DataSetMessage /ua-metadataenvelope schemas parameterized by the JSON content masks.Types expose their own schemas (no manual registration required): a new
IDataTypeDefinitionSourceis implemented by the encodeable activators; the source generator emits aGetDataTypeDefinitionoverride on generated data types;ComplexTypeSystem.RegisterDataTypeDefinitions(...)mirrors dynamically-built complex types; and a server-sideRegisterDataTypeSchemasAsync(...)registers address-space DataType nodes.Schemas are built in code as strongly-typed object models (no embedded schema strings), so unused generation paths trim away. Shipping code uses in-box models only — no
XmlSerializer, noXmlSchema.Write, no genericJsonArray.Add<T>.JsonSchema.Netis a test-only dependency used to validate the generated schemas against real encoded OPC UA JSON.Documentation:
Docs/SchemaGeneration.md(linked fromDocs/README.md).Verification
UA.slnxsolution builds with 0 warnings on net10.0; the changed libraries also build clean on net48 and netstandard2.1.Opc.Ua.Core.Schema.Tests64,Opc.Ua.PubSub.Schema.Tests23,Opc.Ua.Client.ComplexTypes.Tests2729,Opc.Ua.Server.Tests1894,Opc.Ua.Core.Tests3276,Opc.Ua.Types.Tests7570,Opc.Ua.SourceGeneration.Core.Tests3653, plus NativeAOT smoke tests inOpc.Ua.Aot.Tests(a published AOT binary was exercised).Notes
UA Core Library.slnx);Opc.Ua.Core.Schemais a standalone/optional package (not a forced dependency of theOpc.Uameta-package), matching how the PubSub packages ship.ValueRanks.AnyJSON is modeled as scalar-or-array (multi-dimensional arrays are accepted but not dimension-constrained).Related Issues
Stacked on and targets the OPC UA Part 14 (PubSub) branch — #3892.
Checklist
Put an
xin the boxes that apply. You can complete these step by step after opening the PR.