{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Devices Response",
    "description": "Response Object for the GET /api/v1/devices endpoint.",
    "type": "object",
    "properties": {
        "usb": {
            "type": "array",
            "description": "An array containing all USB devices in the system",
            "items": {
                "type": "object",
                "description": "A single USB device in the system",
                "properties": {
                    "vendorId": {
                        "description": "Vendor Identifier",
                        "$ref": "#/$defs/v1-vidPid"
                    },
                    "productId": {
                        "description": "Product Identifier",
                        "$ref": "#/$defs/v1-vidPid"
                    },
                    "speedActual": {
                        "description": "Current enumerated speed",
                        "$ref": "#/$defs/v1-speed"
                    },
                    "maxSpeed": {
                        "description": "Maximum supported speed",
                        "$ref": "#/$defs/v1-speed"
                    },
                    "serialNumber": {
                        "description": "Vendor-provided serial number",
                        "$ref": "#/$defs/v1-name"
                    },
                    "manufacturer": {
                        "description": "Vendor-provided manufacturer name",
                        "$ref": "#/$defs/v1-name"
                    },
                    "productName": {
                        "description": "Vendor-provided product name",
                        "$ref": "#/$defs/v1-name"
                    },
                    "deviceClass": {
                        "description": "Device Class Code",
                        "$ref": "#/$defs/v1-classCode"
                    },
                    "interfaces": {
                        "type": "array",
                        "description": "List of all interfaces provided by device",
                        "items": {
                            "type": "object",
                            "properties": {
                                "interfaceIndex": {
                                    "description": "Interface Index within this device",
                                    "$ref": "#/$defs/v1-uint8"
                                },
                                "entryIndex": {
                                    "description": "Alternate Setting Index within this interface",
                                    "$ref": "#/$defs/v1-uint8"
                                },
                                "kClass": {
                                    "description": "USB-IF class code for this interface",
                                    "$ref": "#/$defs/v1-classCode"
                                },
                                "kSubclass": {
                                    "description": "USB-IF subclass code for this interface, qualified by the kClass code",
                                    "$ref": "#/$defs/v1-classCode"
                                },
                                "kProtocol": {
                                    "description": "USB-IF protocol code for this interface, qualified by the kClass and kSubclass codes",
                                    "$ref": "#/$defs/v1-uint8"
                                }
                            },
                            "required": ["interfaceIndex", "entryIndex", "kClass", "kSubclass", "kProtocol"]
                        },
                        "uniqueItems": true
                    },
                    "portPath": {
                        "type": "array",
                        "description": "List of the logical IDs of each parent node, starting with the controller ID and followed by the port ID for each parent device.",
                        "items": {
                            "$ref": "#/$defs/v1-uint8"
                        },
                        "minItems": 1,
                        "maxItems": 7
                    },
                    "acronameDevice": {
                        "type": "object",
                        "description": "If an Acroname device is detected in this device's parent tree, information about the Acroname device.",
                        "properties": {
                            "serialNumber": {
                                "description": "Acroname Serial Number",
                                "$ref": "#/$defs/v1-serialNumber"
                            },
                            "port": {
                                "description": "Physical port number on the Acroname device",
                                "$ref": "#/$defs/v1-uint8"
                            },
                            "distance": {
                                "description": "Number of parent tiers between Acroanme device and this device",
                                "$ref": "#/$defs/v1-uint8"
                            }
                        },
                        "required": ["serialNumber", "port", "distance"]
                    },
                    "bulkCapability": {
                        "description": "Capability information for Bulk Transfers",
                        "$ref": "#/$defs/v1-capability"
                    },
                    "isochronousCapability": {
                        "description": "Capability information for Isochronous Transfers",
                        "$ref": "#/$defs/v1-capability"
                    },
                    "interruptCapability": {
                        "description": "Capability information for Interrupt Transfers",
                        "$ref": "#/$defs/v1-capability"
                    }
                },
                "required": [
                    "vendorId",
                    "productId",
                    "speedActual",
                    "maxSpeed",
                    "serialNumber",
                    "manufacturer",
                    "productName",
                    "deviceClass",
                    "interfaces",
                    "portPath",
                    "bulkCapability",
                    "isochronousCapability",
                    "interruptCapability"
                ]
            },
            "uniqueItems": true
        }
    },
    "required": ["usb"],
    "$defs": {
        "v1-vidPid": {
            "description": "Representation of a USB Device or Vendor ID",
            "type": "string",
            "pattern": "^(0x)?[A-Fa-f0-9]{4}$"
        },
        "v1-serialNumber": {
            "description": "Representation of an Acroname device serial number",
            "type": "string",
            "pattern": "^(0x)?[A-Fa-f0-9]{8}$"
        },
        "v1-speed": {
            "description": "Enumeration of all possible USB speeds",
            "type": "string",
            "enum": [
                "Unknown",
                "1.5 Mbps",
                "12 Mbps",
                "480 Mbps",
                "5 Gbps",
                "10 Gbps"
            ]
        },
        "v1-name": {
            "description": "USB-IF Compliant Name Field",
            "type": "string",
            "maxLength": 126
        },
        "v1-classCode": {
            "description": "Enumeration of all possible USB device/interface classes (https://vovkos.github.io/doxyrest/samples/libusb/enum_libusb_class_code.html)",
            "type": "integer",
            "enum": [0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 220, 224, 254, 255]
        },
        "v1-uint8": {
            "description": "Unsigned 8-bit integer",
            "type": "integer",
            "minimum": 0,
            "maximum": 255
        },
        "v1-capability": {
            "description": "Description for a capability of a device",
            "type": "object",
            "properties": {
                "isDoing": {
                    "description": "Whether the device is currently using this capability",
                    "type": "boolean"
                },
                "isCapable": {
                    "description": "Whether the device is capable of using this capability",
                    "type": "boolean"
                }
            },
            "required": ["isDoing", "isCapable"]
        },
        "v1-aErr": {
            "description": "Enumeration of all possible error results",
            "type": "string",
            "enum": [
                "aErrNone",
                "aErrMemory",
                "aErrParam",
                "aErrNotFound",
                "aErrFileNameLength",
                "aErrBusy",
                "aErrIO",
                "aErrMode",
                "aErrWrite",
                "aErrRead",
                "aErrEOF",
                "aErrNotReady",
                "aErrPermission",
                "aErrRange",
                "aErrSize",
                "aErrOverrun",
                "aErrParse",
                "aErrConfiguration",
                "aErrTimeout",
                "aErrInitialization",
                "aErrVersion",
                "aErrUnimplemented",
                "aErrDuplicate",
                "aErrCancel",
                "aErrPacket",
                "aErrConnection",
                "aErrIndexRange",
                "aErrShortCommand",
                "aErrInvalidEntity",
                "aErrInvalidOption",
                "aErrResource",
                "aErrMedia",
                "aErrAsyncReturn",
                "aErrOperation",
                "aErrUnknown"
            ]
        },
        "v1-error": {
            "description": "Error containing an Acroname error",
            "type": "object",
            "properties": {
                "errorCode": {
                    "description": "Acroname error code",
                    "$ref": "#/$defs/v1-aErr"
                },
                "errorMessage": {
                    "description": "A human-readable message to describe the context of the error.",
                    "type": "string",
                    "minLength": 1
                }
            },
            "required": ["errorCode"]
        }
    }
}
