From 63f59f595ff96c0524209febd2401dde5b35ec42 Mon Sep 17 00:00:00 2001 From: Jacob Bandes-Storch Date: Mon, 28 Aug 2023 11:13:07 -0700 Subject: [PATCH] Generate .idl schemas (#126) Adds OMG IDL definitions for Foxglove schemas. --- README.md | 2 +- internal/generateFlatbufferSchema.test.ts | 4 +- internal/generateJsonSchema.test.ts | 8 +- internal/generateOmgIdl.test.ts | 187 ++++++++++++++++++ internal/generateOmgIdl.ts | 141 +++++++++++++ internal/generateProto.test.ts | 4 +- internal/generateRos.test.ts | 50 ++--- internal/generateTypeScript.test.ts | 4 +- internal/testFixtures.ts | 4 +- package.json | 1 + schemas/omgidl/foxglove/ArrowPrimitive.idl | 29 +++ schemas/omgidl/foxglove/CameraCalibration.idl | 75 +++++++ schemas/omgidl/foxglove/CircleAnnotation.idl | 30 +++ schemas/omgidl/foxglove/Color.idl | 24 +++ schemas/omgidl/foxglove/CompressedImage.idl | 24 +++ schemas/omgidl/foxglove/CompressedVideo.idl | 24 +++ schemas/omgidl/foxglove/CubePrimitive.idl | 21 ++ schemas/omgidl/foxglove/CylinderPrimitive.idl | 27 +++ schemas/omgidl/foxglove/Duration.idl | 8 + schemas/omgidl/foxglove/FrameTransform.idl | 27 +++ schemas/omgidl/foxglove/FrameTransforms.idl | 13 ++ schemas/omgidl/foxglove/GeoJSON.idl | 11 ++ schemas/omgidl/foxglove/Grid.idl | 40 ++++ schemas/omgidl/foxglove/ImageAnnotations.idl | 21 ++ schemas/omgidl/foxglove/KeyValuePair.idl | 14 ++ schemas/omgidl/foxglove/LaserScan.idl | 32 +++ schemas/omgidl/foxglove/LinePrimitive.idl | 39 ++++ schemas/omgidl/foxglove/LineType.idl | 20 ++ schemas/omgidl/foxglove/LocationFix.idl | 32 +++ schemas/omgidl/foxglove/Log.idl | 29 +++ schemas/omgidl/foxglove/LogLevel.idl | 26 +++ schemas/omgidl/foxglove/ModelPrimitive.idl | 33 ++++ schemas/omgidl/foxglove/NumericType.idl | 35 ++++ .../omgidl/foxglove/PackedElementField.idl | 19 ++ schemas/omgidl/foxglove/Point2.idl | 14 ++ schemas/omgidl/foxglove/Point3.idl | 17 ++ schemas/omgidl/foxglove/PointCloud.idl | 30 +++ schemas/omgidl/foxglove/PointsAnnotation.idl | 34 ++++ .../omgidl/foxglove/PointsAnnotationType.idl | 27 +++ schemas/omgidl/foxglove/Pose.idl | 17 ++ schemas/omgidl/foxglove/PoseInFrame.idl | 20 ++ schemas/omgidl/foxglove/PosesInFrame.idl | 20 ++ .../foxglove/PositionCovarianceType.idl | 20 ++ schemas/omgidl/foxglove/Quaternion.idl | 21 ++ schemas/omgidl/foxglove/RawImage.idl | 33 ++++ schemas/omgidl/foxglove/SceneEntity.idl | 62 ++++++ .../omgidl/foxglove/SceneEntityDeletion.idl | 20 ++ .../foxglove/SceneEntityDeletionType.idl | 16 ++ schemas/omgidl/foxglove/SceneUpdate.idl | 17 ++ schemas/omgidl/foxglove/SpherePrimitive.idl | 21 ++ schemas/omgidl/foxglove/TextAnnotation.idl | 31 +++ schemas/omgidl/foxglove/TextPrimitive.idl | 29 +++ schemas/omgidl/foxglove/Time.idl | 8 + .../omgidl/foxglove/TriangleListPrimitive.idl | 29 +++ schemas/omgidl/foxglove/Vector2.idl | 16 ++ schemas/omgidl/foxglove/Vector3.idl | 20 ++ scripts/updateGeneratedFiles.ts | 19 ++ yarn.lock | 12 ++ 58 files changed, 1574 insertions(+), 37 deletions(-) create mode 100644 internal/generateOmgIdl.test.ts create mode 100644 internal/generateOmgIdl.ts create mode 100644 schemas/omgidl/foxglove/ArrowPrimitive.idl create mode 100644 schemas/omgidl/foxglove/CameraCalibration.idl create mode 100644 schemas/omgidl/foxglove/CircleAnnotation.idl create mode 100644 schemas/omgidl/foxglove/Color.idl create mode 100644 schemas/omgidl/foxglove/CompressedImage.idl create mode 100644 schemas/omgidl/foxglove/CompressedVideo.idl create mode 100644 schemas/omgidl/foxglove/CubePrimitive.idl create mode 100644 schemas/omgidl/foxglove/CylinderPrimitive.idl create mode 100644 schemas/omgidl/foxglove/Duration.idl create mode 100644 schemas/omgidl/foxglove/FrameTransform.idl create mode 100644 schemas/omgidl/foxglove/FrameTransforms.idl create mode 100644 schemas/omgidl/foxglove/GeoJSON.idl create mode 100644 schemas/omgidl/foxglove/Grid.idl create mode 100644 schemas/omgidl/foxglove/ImageAnnotations.idl create mode 100644 schemas/omgidl/foxglove/KeyValuePair.idl create mode 100644 schemas/omgidl/foxglove/LaserScan.idl create mode 100644 schemas/omgidl/foxglove/LinePrimitive.idl create mode 100644 schemas/omgidl/foxglove/LineType.idl create mode 100644 schemas/omgidl/foxglove/LocationFix.idl create mode 100644 schemas/omgidl/foxglove/Log.idl create mode 100644 schemas/omgidl/foxglove/LogLevel.idl create mode 100644 schemas/omgidl/foxglove/ModelPrimitive.idl create mode 100644 schemas/omgidl/foxglove/NumericType.idl create mode 100644 schemas/omgidl/foxglove/PackedElementField.idl create mode 100644 schemas/omgidl/foxglove/Point2.idl create mode 100644 schemas/omgidl/foxglove/Point3.idl create mode 100644 schemas/omgidl/foxglove/PointCloud.idl create mode 100644 schemas/omgidl/foxglove/PointsAnnotation.idl create mode 100644 schemas/omgidl/foxglove/PointsAnnotationType.idl create mode 100644 schemas/omgidl/foxglove/Pose.idl create mode 100644 schemas/omgidl/foxglove/PoseInFrame.idl create mode 100644 schemas/omgidl/foxglove/PosesInFrame.idl create mode 100644 schemas/omgidl/foxglove/PositionCovarianceType.idl create mode 100644 schemas/omgidl/foxglove/Quaternion.idl create mode 100644 schemas/omgidl/foxglove/RawImage.idl create mode 100644 schemas/omgidl/foxglove/SceneEntity.idl create mode 100644 schemas/omgidl/foxglove/SceneEntityDeletion.idl create mode 100644 schemas/omgidl/foxglove/SceneEntityDeletionType.idl create mode 100644 schemas/omgidl/foxglove/SceneUpdate.idl create mode 100644 schemas/omgidl/foxglove/SpherePrimitive.idl create mode 100644 schemas/omgidl/foxglove/TextAnnotation.idl create mode 100644 schemas/omgidl/foxglove/TextPrimitive.idl create mode 100644 schemas/omgidl/foxglove/Time.idl create mode 100644 schemas/omgidl/foxglove/TriangleListPrimitive.idl create mode 100644 schemas/omgidl/foxglove/Vector2.idl create mode 100644 schemas/omgidl/foxglove/Vector3.idl diff --git a/README.md b/README.md index e6563f40..65962386 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Message schemas supported by [Foxglove Studio](https://studio.foxglove.dev) See [Foxglove Schemas documentation](https://foxglove.dev/docs/studio/messages). -The [schemas](./schemas) folder contains type definitions generated for ROS 1, ROS 2, Protobuf, JSON Schema, and TypeScript. +The [schemas](./schemas) folder contains type definitions generated for ROS 1, ROS 2, Protobuf, JSON Schema, TypeScript, and OMG IDL. These schemas can be used in [MCAP](https://github.com/foxglove/mcap) files or [Foxglove WebSocket](https://github.com/foxglove/ws-protocol) servers to take advantage of Foxglove Studio's visualizations. diff --git a/internal/generateFlatbufferSchema.test.ts b/internal/generateFlatbufferSchema.test.ts index c9fa3fa9..a93a2988 100644 --- a/internal/generateFlatbufferSchema.test.ts +++ b/internal/generateFlatbufferSchema.test.ts @@ -16,10 +16,10 @@ describe("generateFlatbuffers", () => { /// An example enum enum ExampleEnum : ubyte { /// Value A - A = 1, + A = 0, /// Value B - B = 2, + B = 1, } /// An example type table ExampleMessage { diff --git a/internal/generateJsonSchema.test.ts b/internal/generateJsonSchema.test.ts index b2c8a84e..c7bec029 100644 --- a/internal/generateJsonSchema.test.ts +++ b/internal/generateJsonSchema.test.ts @@ -111,12 +111,12 @@ describe("generateJsonSchema", () => { "description": "An enum field", "oneOf": [ { - "const": 1, + "const": 0, "description": "Value A", "title": "A", }, { - "const": 2, + "const": 1, "description": "Value B", "title": "B", }, @@ -129,12 +129,12 @@ describe("generateJsonSchema", () => { "description": "An enum array field", "oneOf": [ { - "const": 1, + "const": 0, "description": "Value A", "title": "A", }, { - "const": 2, + "const": 1, "description": "Value B", "title": "B", }, diff --git a/internal/generateOmgIdl.test.ts b/internal/generateOmgIdl.test.ts new file mode 100644 index 00000000..6d9ae95a --- /dev/null +++ b/internal/generateOmgIdl.test.ts @@ -0,0 +1,187 @@ +import { parseIdl } from "@foxglove/omgidl-parser"; + +import { DURATION_IDL, TIME_IDL, generateOmgIdl } from "./generateOmgIdl"; +import { foxgloveEnumSchemas, foxgloveMessageSchemas } from "./schemas"; +import { exampleEnum, exampleMessage } from "./testFixtures"; + +describe("generateOmgIdl", () => { + it("generates .idl files", () => { + expect(generateOmgIdl(exampleEnum)).toMatchInlineSnapshot(` + "// Generated by https://github.com/foxglove/schemas + + module foxglove { + + // An example enum + enum ExampleEnum { + // Value A + // Value: 0 + A, + + // Value B + // Value: 1 + B + }; + + }; + " + `); + expect(generateOmgIdl(exampleMessage)).toMatchInlineSnapshot(` + "// Generated by https://github.com/foxglove/schemas + + #include "foxglove/Duration.idl" + #include "foxglove/ExampleEnum.idl" + #include "foxglove/NestedMessage.idl" + #include "foxglove/Time.idl" + + module foxglove { + + // An example type + struct ExampleMessage { + // duration field + Duration field_duration; + + // time field + Time field_time; + + // boolean field + @default(TRUE) + boolean field_boolean; + + // bytes field + sequence field_bytes; + + // float64 field + @default(1.0) + double field_float64; + + // uint32 field + @default(5) + uint32 field_uint32; + + // string field + @default("string-type") + string field_string; + + // duration array field + sequence field_duration_array; + + // time array field + sequence