%YAML 1.1
#
# OpenDMI: Cross-platform DMI/SMBIOS framework
# Copyright (c) 2025-2026, The OpenDMI contributors
#
# SPDX-License-Identifier: BSD-3-Clause
#
# Schema of the documents `opendmi export --format=yaml` writes, applied to
# the data a YAML reader loads out of them. Handles, offsets and hexadecimal
# numbers are written as plain scalars, e.g. `0x0100`, which the readers load
# as integers, and strings which are not valid UTF-8 are written as `!!binary`
# scalars, which the readers load as bytes rather than as strings.
#
---
$schema: "https://json-schema.org/draft/2020-12/schema"
$id: "https://opendmi.org/schemas/opendmi.yml"
title: OpenDMI YAML schema

type: object
properties:
    entry:
        description: Entry point data
        type: object
        properties:
            smbios-version:
                description: SMBIOS version the entry point declares
                $ref: "#/$defs/version"
        required:
          - smbios-version
        additionalProperties: false

    table:
        description: Structures of the table, in the order the table holds them
        type: array
        items:
            $ref: "#/$defs/entity"

required:
  - entry
  - table
additionalProperties: false

$defs:
    entity:
        description: SMBIOS structure
        type: object
        properties:
            handle:
                $ref: "#/$defs/handle"
            type:
                description: Structure type
                type: integer
                minimum: 0
                maximum: 255
            length:
                description: >-
                    Total length of the structure, including its header and
                    its strings
                type: integer
                minimum: 4
            level:
                description: >-
                    Version of the specification the structure conforms to,
                    or null if the structure is not decoded or is not versioned
                oneOf:
                  - $ref: "#/$defs/version"
                  - type: "null"
            state:
                description: State flags of the structure
                type: array
                items:
                    enum:
                      - decoded
                      - linked
                      - valid
                      - incomplete
                      - partial
                uniqueItems: true
            description:
                description: Name of the structure type
                type: string
            attributes:
                description: >-
                    Decoded values of the structure, keyed by the codes of the
                    attributes of its type
                $ref: "#/$defs/attributes"
            properties:
                description: String properties added by type 46 structures
                type: array
                items:
                    $ref: "#/$defs/property"
            overlays:
                description: >-
                    Additional information entries (type 40) applied to the
                    structure
                type: array
                items:
                    $ref: "#/$defs/overlay"
            data:
                description: >-
                    Formatted area of the structure, including its header
                $ref: "#/$defs/binary"
            strings:
                description: >-
                    Strings of the structure, the first one being string 1
                type: array
                items:
                    $ref: "#/$defs/text"
                minItems: 1
                maxItems: 255
        required:
          - handle
          - type
          - length
          - level
          - state
          - description
        dependentSchemas:
            attributes:
                not:
                    anyOf:
                      - required: [data]
                      - required: [strings]
            properties:
                required: [attributes]
            overlays:
                required: [attributes]
            strings:
                required: [data]
        additionalProperties: false

    attributes:
        type: object
        additionalProperties:
            $ref: "#/$defs/attributeValue"

    attributeValue:
        description: >-
            Value of an attribute: a scalar, null if the value is not
            specified, "unknown" if the data says that it is unknown, a
            mapping of flag codes to booleans for a set of flags, a mapping
            of attribute codes to values for a nested structure, or a
            sequence of values for an array
        anyOf:
          - type: ["null", boolean, integer, number, string]
          - $ref: "#/$defs/binary"
          - $ref: "#/$defs/attributes"
          - type: array
            items:
                $ref: "#/$defs/attributeValue"

    property:
        description: String property
        type: object
        properties:
            id:
                description: Property identifier
                type: integer
                minimum: 0x0000
                maximum: 0xFFFF
            code:
                description: >-
                    Code of the property, or null if the identifier is not
                    known
                type: ["string", "null"]
            value:
                description: Value of the property, or null if not specified
                oneOf:
                  - $ref: "#/$defs/text"
                  - type: "null"
        required:
          - id
          - code
          - value
        additionalProperties: false

    overlay:
        description: Additional information entry applied to the structure
        type: object
        properties:
            source:
                description: Handle of the type 40 structure holding the entry
                $ref: "#/$defs/handle"
            index:
                description: Index of the entry within its structure
                type: integer
                minimum: 0
            offset:
                description: Offset of the field the entry refers to
                type: integer
                minimum: 0x00
                maximum: 0xFF
            value:
                description: Value of the entry, as hexadecimal digits
                type: string
            string:
                description: String of the entry, or null if it has none
                oneOf:
                  - $ref: "#/$defs/text"
                  - type: "null"
        required:
          - source
          - index
          - offset
          - value
          - string
        additionalProperties: false

    handle:
        description: Structure handle
        type: integer
        minimum: 0x0000
        maximum: 0xFFFF

    version:
        description: Version number
        type: string
        pattern: "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$"

    text:
        description: String, which is loaded as bytes if it is not valid UTF-8
        anyOf:
          - type: string
          - $ref: "#/$defs/binary"

    binary:
        description: >-
            Binary data, written as a !!binary scalar, which YAML readers load
            as bytes rather than as any of the JSON types
        not:
            type: ["null", boolean, number, string, array, object]
