/* ========================================================================
* Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Opc.Ua.WotCon.Server.ThingDescriptions
{
///
/// W3C WoT Thing Description root document. Only the fields consumed
/// by the WoT Connectivity mapping (OPC 10100-1 §6) are modelled;
/// unknown fields are tolerated and ignored.
///
public sealed class ThingDescription
{
/// The TD @context array.
[JsonPropertyName("@context")]
public JsonElement? Context { get; set; }
/// The TD id.
[JsonPropertyName("id")]
public string? Id { get; set; }
/// The TD @type array.
[JsonPropertyName("@type")]
public JsonElement? Type { get; set; }
/// Thing name (used as the OPC UA asset BrowseName).
[JsonPropertyName("name")]
public string? Name { get; set; }
/// Base URI used by relative-href forms.
[JsonPropertyName("base")]
public string? Base { get; set; }
/// Human-readable title.
[JsonPropertyName("title")]
public string? Title { get; set; }
/// Optional description.
[JsonPropertyName("description")]
public string? Description { get; set; }
/// WoT properties keyed by property name.
[JsonPropertyName("properties")]
public Dictionary? Properties { get; set; }
/// WoT actions keyed by action name (OPC 10100-1 §6.3.9).
[JsonPropertyName("actions")]
public Dictionary? Actions { get; set; }
}
///
/// W3C WoT property definition. The string is
/// mapped to an OPC UA DataType per OPC 10100-1 §6.3.8 Table 14.
///
public sealed class WotProperty
{
/// WoT JSON Schema type (e.g. "number").
[JsonPropertyName("type")]
public string? Type { get; set; }
/// Optional title.
[JsonPropertyName("title")]
public string? Title { get; set; }
/// Optional description.
[JsonPropertyName("description")]
public string? Description { get; set; }
/// true for read-only properties.
[JsonPropertyName("readOnly")]
public bool ReadOnly { get; set; }
/// true when the property is observable.
[JsonPropertyName("observable")]
public bool Observable { get; set; }
/// Item schema when is array.
[JsonPropertyName("items")]
public WotPropertyItems? Items { get; set; }
/// Optional engineering unit suffix.
[JsonPropertyName("unit")]
public string? Unit { get; set; }
/// Optional OPC UA NodeId override (when the TD pins one).
[JsonPropertyName("opcua:nodeId")]
public string? OpcUaNodeId { get; set; }
/// Forms — protocol-binding specific endpoints.
[JsonPropertyName("forms")]
public List? Forms { get; set; }
}
///
/// Item schema for an array WoT property.
///
public sealed class WotPropertyItems
{
/// The element JSON-schema type.
[JsonPropertyName("type")]
public string? Type { get; set; }
}
///
/// W3C WoT action definition (OPC 10100-1 §6.3.9). Maps to an OPC UA
/// MethodNode with input/output arguments derived from the
/// / JSON schemas.
///
public sealed class WotAction
{
/// Optional title.
[JsonPropertyName("title")]
public string? Title { get; set; }
/// Optional description.
[JsonPropertyName("description")]
public string? Description { get; set; }
///
/// Input JSON schema. Only type: object with flat
/// properties is mapped to s; other
/// shapes are mapped to a single BaseDataType argument with
/// the schema serialised as the description.
///
[JsonPropertyName("input")]
public WotActionSchema? Input { get; set; }
/// Output JSON schema. Same rules as .
[JsonPropertyName("output")]
public WotActionSchema? Output { get; set; }
/// Forms — protocol-binding specific endpoints.
[JsonPropertyName("forms")]
public List? Forms { get; set; }
}
///
/// JSON-schema fragment describing a WoT action argument set.
///
public sealed class WotActionSchema
{
/// Schema type (e.g. object).
[JsonPropertyName("type")]
public string? Type { get; set; }
/// Optional title.
[JsonPropertyName("title")]
public string? Title { get; set; }
/// Optional description.
[JsonPropertyName("description")]
public string? Description { get; set; }
///
/// Object members. Iteration order is the OPC UA argument order.
///
[JsonPropertyName("properties")]
public Dictionary? Properties { get; set; }
}
///
/// One member of a WoT action input/output object.
///
public sealed class WotActionMember
{
/// JSON-schema type.
[JsonPropertyName("type")]
public string? Type { get; set; }
/// Optional description.
[JsonPropertyName("description")]
public string? Description { get; set; }
/// Optional engineering unit suffix.
[JsonPropertyName("unit")]
public string? Unit { get; set; }
/// Optional minimum value (numeric schemas).
[JsonPropertyName("minimum")]
public double? Minimum { get; set; }
/// Optional maximum value (numeric schemas).
[JsonPropertyName("maximum")]
public double? Maximum { get; set; }
/// Element schema for array members.
[JsonPropertyName("items")]
public WotPropertyItems? Items { get; set; }
}
}