header.py 3.41 KB
Newer Older
1 2 3 4 5 6
route_clients = {
    "type": "string",
    "description": "Client-ID",
    "example": "proj-x-relay",
}

7 8 9 10 11
message_header = {
    "type": "object",
    "properties": {
        "message_ID": {
            "type": "string",
12 13
            "format": "uuid",
            "pattern": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
14
            "description": "An identifier for the type of message received.",
15
            "example": "b427003c-0000-11aa-a1eb-b1cdf2342fdd",
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
        },
        "timestamp": {
            "type": "string",
            "format": "date-time",
            "description": "Timestamp of message",
            "example": "2022-11-16T00:00:00Z",
        },
        "source": {
            "type": "string",
            "description": "The sender; Where is this message from",
            "example": "autonomy_engine",
        },
        "destination": {
            "type": "string",
            "description": "Publisher topic; What is the destination"
            + " of this message",
            "example": "ah1",
        },
34 35 36 37 38
        "route": {
            "type": "array",
            "items": route_clients,
            "description": "Client-IDs of adapter between forwarding the message between the source adapter and destination adapter",
        },
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
        "encoded": {
            "type": "boolean",
            "description": "Indicate that message raw (encoded) or decoded. "
            + "Options: encoded=true, decoded=false",
            "example": False,
        },
        "delivery_type": {
            "type": "string",
            "description": "To publish or broadcast this message.",
            "enum": ["broadcast", "publish"],
            "example": "publish",
            "default": "publish",
        },
    },
    "oneOf": [
        {
            # semver pattern https://semver.org/
            # https://regex101.com/r/Ly7O1x/3/
            # + optionally include 'v' prefix
            # escape backslashes get doubled so use char groups
            # simplify to planned variants
            "type": "object",
            "properties": {
                "version": {
                    "type": "string",
                    "pattern": "^(v{0,1}(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)"
                    + "(?:-(alpha|beta)[.](0|[1-9][0-9]*))?)$",
                }
            },
            "required": ["version"],
        },
        {
            # commit ref
            "type": "object",
            "properties": {
                "version": {
                    "type": "string",
                    "pattern": "^([0-9a-f]+)$",
                }
            },
            "required": ["version"],
        },
        {
            # reserved word
            "type": "object",
            "properties": {
                "version": {
                    "type": "string",
                    "enum": ["dev", "master", "latest"],
                }
            },
            "required": ["version"],
        },
        {
            # existing float version
            "type": "object",
            "properties": {
                "version": {
                    "type": "number",
                    "format": "float",
                    "example": 2.0,
                }
            },
            "required": ["version"],
        },
    ],
    "required": [
        "message_ID",
        "timestamp",
        "source",
        "destination",
        "delivery_type",
        "encoded",
    ],
}