[Web runtime] Add OpenAPI 3.1 export from the capability registry - #1565
Open
minggangw wants to merge 8 commits into
Open
[Web runtime] Add OpenAPI 3.1 export from the capability registry#1565minggangw wants to merge 8 commits into
minggangw wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an OpenAPI 3.1 export path for the rclnodejs Web Runtime capability registry, including a new CLI subcommand to emit the document without starting the runtime.
Changes:
- Introduces
lib/openapi.jsto map capability registry entries + rosidl introspection into an OpenAPI 3.1 document with shared$refcomponents. - Extends
bin/rclnodejs-web.jswith anopenapisubcommand that prints the document and derivesserversfrom HTTP config. - Adds
test/test-openapi.jscoverage for the schema mapper, document assembly, and CLI behavior; updates CLI help text.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lib/openapi.js |
New OpenAPI/JSON Schema generator driven by message introspection and capability registry snapshots. |
bin/rclnodejs-web.js |
Adds openapi subcommand to output OpenAPI JSON without starting transports / ROS init. |
lib/runtime/cli-config.js |
Updates --help text to document the new openapi subcommand. |
test/test-openapi.js |
Adds tests for schema mapping, document structure, server derivation, and CLI subcommand behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+95
to
+103
| if (INT64_TYPES.has(type)) { | ||
| // See the docstring above — deliberately string, not integer. | ||
| return { | ||
| type: 'string', | ||
| format: 'int64', | ||
| pattern: '^-?[0-9]+n$', | ||
| description: `ROS 2 ${type}, transmitted as a BigInt-string (e.g. "42n") for precision-safety.`, | ||
| }; | ||
| } |
Comment on lines
+191
to
+199
| function topLevelSchema(typeName, subType, components, seen) { | ||
| const typeClass = interfaceLoader.loadInterface(typeName); | ||
| const resolved = subType ? typeClass[subType] : typeClass; | ||
| const schema = getMessageSchema(resolved); | ||
| if (!schema) { | ||
| return { type: 'object', description: `Could not resolve ${typeName}` }; | ||
| } | ||
| return messageSchemaToJsonSchema(schema, components, seen); | ||
| } |
Comment on lines
+28
to
+33
| let stdout = ''; | ||
| let stderr = ''; | ||
| p.stdout.on('data', (d) => (stdout += d.toString())); | ||
| p.stderr.on('data', (d) => (stderr += d.toString())); | ||
| p.on('exit', (code) => resolve({ code, stdout, stderr })); | ||
| p.on('error', reject); |
Comment on lines
+234
to
+236
| function buildOpenApiDocument(capabilities, options = {}) { | ||
| const { title = 'rclnodejs/web capability API', basePath = '/capability' } = | ||
| options; |
Comment on lines
+310
to
+320
| responses: { | ||
| 200: { | ||
| description: `Server-Sent Events stream of ${typeName} messages`, | ||
| content: { | ||
| 'text/event-stream': { | ||
| schema: topLevelSchema(typeName, null, components, seen), | ||
| }, | ||
| }, | ||
| }, | ||
| 404: notExposedResponse(), | ||
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
lib/openapi.js: mapsCapabilityRegistry.list()and rosidl introspection into an OpenAPI 3.1 document viabuildOpenApiDocument(capabilities, {title, basePath}). CLI-only, not part of therclnodejs/web/serverAPI; lives inlib/, notlib/runtime/, since it has no runtime/transport dependency.int64/uint64as BigInt-strings with distinct signed/unsigned patterns, both using a shared"42n"example (avoids API explorers synthesizing an arbitrarily long digit string from the unbounded pattern); bounded/fixed-size arrays; de-duplicated$refcomponents for nested types; unresolvable types degrade to a placeholder instead of aborting the document.rclnodejs-web openapi [config.json]CLI subcommand: resolvesexposecapabilities to schemas and prints the document to stdout without starting any transport or callingrclnodejs.init().serversand routebasePathfrom the resolved HTTP config, matching the server transport's own fallback and its wildcard-to-localhosthost display, so generated documents always describe the routes the runtime actually serves and honor a configured--http-host.GET /capability/subscribe/<name>astext/event-stream— noted as not testable via "Try it out" in API explorers, since the response never completes.--helpusage text with the new subcommand.test/test-openapi.jscovering the schema mapper, document assembly, and CLI behavior.Fix: #1564