Skip to content

[Web runtime] Add OpenAPI 3.1 export from the capability registry - #1565

Open
minggangw wants to merge 8 commits into
RobotWebTools:developfrom
minggangw:fix-1564
Open

[Web runtime] Add OpenAPI 3.1 export from the capability registry#1565
minggangw wants to merge 8 commits into
RobotWebTools:developfrom
minggangw:fix-1564

Conversation

@minggangw

@minggangw minggangw commented Jul 27, 2026

Copy link
Copy Markdown
Member
  • Add lib/openapi.js: maps CapabilityRegistry.list() and rosidl introspection into an OpenAPI 3.1 document via buildOpenApiDocument(capabilities, {title, basePath}). CLI-only, not part of the rclnodejs/web/server API; lives in lib/, not lib/runtime/, since it has no runtime/transport dependency.
  • JSON Schema mapper: int64/uint64 as 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 $ref components for nested types; unresolvable types degrade to a placeholder instead of aborting the document.
  • Add the rclnodejs-web openapi [config.json] CLI subcommand: resolves expose capabilities to schemas and prints the document to stdout without starting any transport or calling rclnodejs.init().
  • Derive servers and route basePath from the resolved HTTP config, matching the server transport's own fallback and its wildcard-to-localhost host display, so generated documents always describe the routes the runtime actually serves and honor a configured --http-host.
  • Document all three capability kinds, including GET /capability/subscribe/<name> as text/event-stream — noted as not testable via "Try it out" in API explorers, since the response never completes.
  • Extend --help usage text with the new subcommand.
  • Add test/test-openapi.js covering the schema mapper, document assembly, and CLI behavior.

Fix: #1564

Copilot AI review requested due to automatic review settings July 27, 2026 06:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.js to map capability registry entries + rosidl introspection into an OpenAPI 3.1 document with shared $ref components.
  • Extends bin/rclnodejs-web.js with an openapi subcommand that prints the document and derives servers from HTTP config.
  • Adds test/test-openapi.js coverage 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 thread lib/openapi.js
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 thread lib/openapi.js Outdated
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 thread test/test-openapi.js
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);

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.

@coveralls

coveralls commented Jul 27, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 91.112% (+0.009%) from 91.103% — minggangw:fix-1564 into RobotWebTools:develop

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

Comment thread lib/openapi.js Outdated
Comment on lines +234 to +236
function buildOpenApiDocument(capabilities, options = {}) {
const { title = 'rclnodejs/web capability API', basePath = '/capability' } =
options;
Comment thread lib/openapi.js
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(),
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI support

3 participants