sdbus++: events: add schema

Add jsonschema for new error and event design[1].  Schema is based
on the schema originally in the document but enhanced for better
schema validation of required and/or conflicting properties.

[1]: https://github.com/openbmc/docs/blob/master/designs/event-logging.md

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ic64a98825080d990d904b788cfaed45b91e8a39e
diff --git a/tools/meson.build b/tools/meson.build
index 943e941..4da16d6 100644
--- a/tools/meson.build
+++ b/tools/meson.build
@@ -12,6 +12,7 @@
   'sdbusplus/renderer.py',
   'sdbusplus/servicename.py',
   'sdbusplus/signal.py',
+  'sdbusplus/schemas/events.schema.yaml',
   'sdbusplus/templates/error.cpp.mako',
   'sdbusplus/templates/error.hpp.mako',
   'sdbusplus/templates/error.md.mako',
diff --git a/tools/sdbusplus/schemas/events.schema.yaml b/tools/sdbusplus/schemas/events.schema.yaml
new file mode 100644
index 0000000..e0c6ebb
--- /dev/null
+++ b/tools/sdbusplus/schemas/events.schema.yaml
@@ -0,0 +1,137 @@
+$id: https://openbmc-project.xyz/sdbusplus/events.schema.yaml
+$schema: https://json-schema.org/draft/2020-12/schema
+title: Event and error definitions
+type: object
+$defs:
+    base-event:
+        type: object
+        properties:
+            name:
+                type: string
+                description:
+                    An identifier for the event in UpperCamelCase; used as the
+                    class and Redfish Message ID.
+            deprecated:
+                type: string
+                pattern: "^[0-9]+\\.[0-9]+\\.[0-9]+$"
+                description:
+                    Indicates that the event is now deprecated and should not be
+                    created by any OpenBMC software, but is required to still
+                    exist for generation in the Redfish Message Registry. The
+                    version listed here should be the first version where the
+                    error is no longer used.
+            metadata:
+                type: array
+                items:
+                    type: object
+                    properties:
+                        name:
+                            type: string
+                            description: The name of the metadata field.
+                        type:
+                            enum:
+                                - string
+                                - size
+                                - int64
+                                - uint64
+                                - double
+                                - object_path
+                            description: The type of the metadata field.
+                        primary:
+                            type: boolean
+                            description:
+                                Set to true when the metadata field is expected
+                                to be part of the Redfish `MessageArgs` (and not
+                                only in the extended `DiagnosticData`).
+                minItems: 1
+        required:
+            - name
+    event:
+        type: object
+        allOf:
+            - $ref: "#/$defs/base-event"
+            - oneOf:
+                  - $ref: "#/$defs/redfish-messages"
+                  - $ref: "#/$defs/redfish-map"
+    error:
+        type: object
+        $ref: "#/$defs/event"
+        properties:
+            severity:
+                enum:
+                    - emergency
+                    - alert
+                    - critical
+                    - error
+                    - warning
+                    - notice
+                    - informational
+                    - debug
+                description:
+                    The `xyz.openbmc_project.Logging.Entry.Level` value for this
+                    error.
+            errno:
+                type: string
+                pattern: "^E[A-Z0-9]+$"
+                description: The errno used for this error.
+        required:
+            - severity
+            - errno
+    redfish-messages:
+        type: object
+        properties:
+            en:
+                $ref: "#/$defs/redfish-lang-message"
+                description: English message details.
+        required:
+            - en
+    redfish-lang-message:
+        type: object
+        description: The message details for any language.
+        properties:
+            description:
+                type: string
+                description:
+                    A developer-applicable description of the error reported.
+                    These form the "description" of the Redfish message.
+            message:
+                type: string
+                description:
+                    The end-user message, including placeholders for arguemnts.
+            resolution:
+                type: string
+                description: The end-user resolution.
+        required:
+            - message
+    redfish-map:
+        type: object
+        properties:
+            redfish-mapping:
+                type: string
+                description:
+                    Used when a `sdbusplus` event should map to a specific
+                    Redfish Message rather than a generated one. This is useful
+                    when an internal error has an analog in a standardized
+                    registry.
+        required:
+            - redfish-mapping
+
+properties:
+    version:
+        type: string
+        pattern: "^[0-9]+\\.[0-9]+\\.[0-9]+$"
+        description:
+            The version of the file, which will be used as the Redfish Message
+            Registry version.
+    errors:
+        type: array
+        items:
+            $ref: "#/$defs/error"
+        minItems: 1
+    events:
+        type: array
+        items:
+            $ref: "#/$defs/event"
+        minItems: 1
+required:
+    - version
diff --git a/tools/setup.py b/tools/setup.py
index c1f8ad6..9c25e2c 100755
--- a/tools/setup.py
+++ b/tools/setup.py
@@ -7,7 +7,7 @@
     packages=find_packages(),
     install_requires=["inflection", "mako", "pyyaml"],
     scripts=["sdbus++", "sdbus++-gen-meson"],
-    package_data={"sdbusplus": ["templates/*.mako"]},
+    package_data={"sdbusplus": ["schemas/*.yaml", "templates/*.mako"]},
     url="http://github.com/openbmc/sdbusplus",
     classifiers=["License :: OSI Approved :: Apache Software License"],
 )