Skip to content

[rest] add REST JSON:API for commissioner and diagnostics#2514

Merged
jwhui merged 1 commit intoopenthread:mainfrom
martinzi:rest-jsonapi
Sep 10, 2025
Merged

[rest] add REST JSON:API for commissioner and diagnostics#2514
jwhui merged 1 commit intoopenthread:mainfrom
martinzi:rest-jsonapi

Conversation

@martinzi
Copy link
Copy Markdown
Contributor

@martinzi martinzi commented Sep 27, 2024

In this PR, we propose an extended REST API functionality providing capabilities for commissioning and on-mesh diagnostics to generic off-mesh http clients. The implementation is guided by the JSON:API specification and provides following parts

  • api/node - pointing to api/devices/thisdevice
  • api/devices - a collection of discovered devices
  • api/actions - indirect processing of tasks, in particular for those that may need more time
    • addThreadDeviceTask - starts the on-mesh commissioner and adds the joiner candidate into the joiner table
    • getNetworkDiagnosticTask - sends diagnostic requests and diagnostic queries to the destination
    • resetNetworkDiagCounterTask - resets the network diagnostic mle and/or mac counter
    • getEnergyScanTask - starts the commissioner and sends energy scan requests to the destination
    • updateDeviceCollectionTask - (re-)discovers the devices in the Thread network and updates the collection in api/devices
  • api/diagnostics
    • networkDiagnostic - all the Diagnostic TLV details
    • energyScanReport - results of energy scans

The PR provides integration tests for local validation, see tests/restjsonapi.

The Readme provides more details and descriptions in src/rest/README.md, also see openapi specification.

Related to specification item SPEC-1349

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 27, 2024

Codecov Report

❌ Patch coverage is 61.38123% with 1247 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.64%. Comparing base (2b41187) to head (46d7e3a).
⚠️ Report is 1223 commits behind head on main.

Files with missing lines Patch % Lines
src/rest/json.cpp 51.95% 217 Missing and 53 partials ⚠️
src/rest/network_diag_handler.cpp 67.41% 184 Missing and 63 partials ⚠️
src/rest/rest_web_server.cpp 61.46% 135 Missing and 28 partials ⚠️
src/rest/commissioner_manager.cpp 54.05% 98 Missing and 21 partials ⚠️
src/rest/actions/add_thread_device.cpp 45.00% 61 Missing and 16 partials ⚠️
src/rest/actions_list.cpp 50.00% 63 Missing and 4 partials ⚠️
src/rest/rest_generic_collection.cpp 63.74% 53 Missing and 9 partials ⚠️
src/rest/actions/energy_scan.cpp 63.63% 29 Missing and 11 partials ⚠️
src/rest/actions/action.cpp 60.43% 30 Missing and 6 partials ⚠️
src/rest/actions/network_diagnostic.cpp 65.88% 21 Missing and 8 partials ⚠️
... and 13 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2514      +/-   ##
==========================================
- Coverage   55.77%   46.64%   -9.13%     
==========================================
  Files          87      142      +55     
  Lines        6890    17175   +10285     
  Branches        0     1413    +1413     
==========================================
+ Hits         3843     8012    +4169     
- Misses       3047     8613    +5566     
- Partials        0      550     +550     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@martinzi
Copy link
Copy Markdown
Contributor Author

Happy to discuss thoughts and improvements. Note: we will add a commit fixing the broken topology browser in otbr-web service asap.

@wgtdkp
Copy link
Copy Markdown
Member

wgtdkp commented Sep 30, 2024

It looks #2515 is also adding the REST commissioner API.

@wgtdkp
Copy link
Copy Markdown
Member

wgtdkp commented Sep 30, 2024

Happy to discuss thoughts and improvements. Note: we will add a commit fixing the broken topology browser in otbr-web service asap.

@martinzi Thanks for this contribution! But this PR is about 12K lines of change that it's too hard to review. Could you help split this PR by creating a separate smaller PR for each feature? For example, one PR for commissioner API and another PR for network diagnostic.

@martinzi
Copy link
Copy Markdown
Contributor Author

@martinzi Thanks for this contribution! But this PR is about 12K lines of change that it's too hard to review. Could you help split this PR by creating a separate smaller PR for each feature? For example, one PR for commissioner API and another PR for network diagnostic.

Agree, it became quite large. See a first part split into PR2517. More to follow ...

@martinzi martinzi force-pushed the rest-jsonapi branch 5 times, most recently from 5627bd7 to 1d140d7 Compare February 25, 2025 20:00
@martinzi martinzi marked this pull request as draft February 25, 2025 20:13
@martinzi martinzi marked this pull request as ready for review March 3, 2025 12:16
Copy link
Copy Markdown
Member

@abtink abtink left a comment

Choose a reason for hiding this comment

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

Thanks @martinzi. looks great.

One small naming suggestion below:

Comment thread src/rest/uuid.hpp Outdated
@jwhui jwhui requested a review from Copilot June 13, 2025 11:29

This comment was marked as outdated.

@jwhui
Copy link
Copy Markdown
Member

jwhui commented Jun 13, 2025

@gemini-code-assist review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an extensive REST JSON:API for commissioner and diagnostics functionalities. It adds new C++ classes for managing actions, devices, and diagnostics collections, along with a commissioner manager and network diagnostic handler. The changes also include a comprehensive README for the new API, updates to the frontend web UI to utilize these new endpoints, and a new set of Bruno tests for validating the API. Key improvements include a more structured approach to handling asynchronous tasks via an actions queue, detailed device inventory, and enhanced diagnostic capabilities. The JSON key naming has been largely standardized to camelCase for better consistency. Overall, this is a significant feature addition that greatly expands the REST API's capabilities.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a REST JSON:API for commissioner and diagnostics, guided by the JSON:API specification. It includes new REST resources for devices, diagnostics, and actions, along with corresponding data structures and handlers. The changes also involve adding new files for actions, diagnostic types, and JSON handling, as well as updating existing files to incorporate the new functionality. The code appears well-structured and follows the JSON:API specification. The review comments suggest minor improvements related to code readability, efficiency, and compatibility.

Comment thread src/rest/actions/action.cpp
Comment thread src/rest/actions_list.cpp
Comment thread src/rest/actions_list.cpp Outdated
Comment thread src/rest/commissioner_manager.cpp
@bukepo bukepo requested a review from Copilot July 11, 2025 11:49
@bukepo
Copy link
Copy Markdown
Member

bukepo commented Jul 11, 2025

@gemini-code-assist review

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds JSON:API–compliant REST endpoints for commissioning and on-mesh diagnostics and integrates end-to-end tests and frontend updates.

  • Enable mesh diagnostics in the OpenThread build
  • Add Bruno CLI integration tests under tests/restjsonapi for the new /api routes
  • Implement JSON:API handlers for actions, devices, and diagnostics in src/rest, plus corresponding frontend and legacy-test updates

Reviewed Changes

Copilot reviewed 95 out of 96 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
third_party/openthread/CMakeLists.txt Enable OT_MESH_DIAG option for mesh diagnostics
tests/restjsonapi/* Add Bruno CLI–based JSON:API integration tests for devices, actions, and diagnostics
tests/rest/test_rest.py Update legacy Python REST tests to expect JSON and lowercase hex values
src/web/web-service/frontend/res/js/app.js Refactor UI to call new /api endpoints, add topology slider and TLV checkboxes
src/web/web-service/frontend/.../styles.css/html Adjust styling and bindings to match new API data shapes
src/rest/types.hpp, services.hpp, rest_web_server.cpp, timestamp.cpp, uuid.* Implement core JSON:API request parsing, routing, services, and timestamp formatting

Comment thread src/rest/timestamp.cpp Outdated
Comment thread src/rest/types.hpp Outdated
Comment thread src/rest/rest_web_server.cpp Outdated
Comment thread src/web/web-service/frontend/res/js/app.js
Comment thread tests/restjsonapi/test-restjsonapi-server
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a REST JSON:API for commissioning and diagnostics. I've focused on correctness and robustness, identifying areas where the implementation could be improved, particularly in handling joiner requests and parsing request URLs.

Comment thread src/rest/commissioner_manager.cpp
Comment thread src/rest/rest_server_common.cpp Outdated
Comment thread src/rest/rest_web_server.cpp Outdated
Comment thread script/_otbr Outdated
Comment thread src/rest/actions/action.cpp Outdated
Comment thread src/rest/actions/action.cpp Outdated
Comment thread src/rest/actions/action.hpp
Comment thread src/rest/actions/action.hpp Outdated
Comment thread src/rest/actions/action.hpp Outdated
@@ -0,0 +1,17 @@
meta {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should a license header be added?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh, it seems bru files do not have a concept for such header text.

Comment thread tests/rest/test_rest.py
Comment thread src/rest/rest_devices_coll.hpp
Comment thread src/rest/openapi.yaml Outdated
@martinzi martinzi force-pushed the rest-jsonapi branch 2 times, most recently from 122dc78 to 5ef6f4a Compare July 17, 2025 06:48
@martinzi martinzi force-pushed the rest-jsonapi branch 2 times, most recently from e8b706d to 3abe24f Compare July 17, 2025 13:47
Copy link
Copy Markdown
Member

@bukepo bukepo left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

Comment thread src/rest/README.md Outdated
@@ -0,0 +1,497 @@
# Add REST JSON:API for commissioner and diagnostics
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Vyrastas , can you help review this doc?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes I will get my review in by tomorrow if that's ok

@jwhui jwhui requested a review from Vyrastas August 27, 2025 20:36
Comment thread third_party/openthread/CMakeLists.txt Outdated
Comment thread tests/restjsonapi/http_action_client_demo.py
Comment thread tests/restjsonapi/bruno.json Outdated
Comment thread src/rest/json.hpp
Copy link
Copy Markdown
Member

@Vyrastas Vyrastas left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in review.

Good job on the README! Most of my comments are nits / copyedits.

Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Copy link
Copy Markdown
Member

@Vyrastas Vyrastas left a comment

Choose a reason for hiding this comment

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

Thank @martinzi ! Read through it again and found a few more nits and some copyedit updates. Should be good for docs after this update

Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
Comment thread src/rest/README.md Outdated
…o generic off-mesh clients

This commit implements following parts:
- api/node
- api/devices
- api/actions
    . addThreadDeviceTask
    . getNetworkDiagnosticsTask
    . resetNetworkDiagCounterTask
    . getEnergyScanTask
    . updateDeviceCollectionTask
- api/diagnostics
    . networkDiagnostic
    . energyScanReport

The commit also provides integration tests, see tests/restjsonapi.
For more details see README.md and openapi.yaml in src/rest.

squashed following former additional commits:
- fix(rest): fix carve-out from PR2514 and re-add diagnostic endpoint
- disable otBorderAgentState field causing build error in github actions
- update openapi.yaml
- fix(rest): delay test progress until node is attached
- fix(rest): return filtered node attributes
- feat(rest): add discerner joiner
- docs(rest): minor doc fixes
- Update src/rest/actions_list.cpp
- Update src/rest/actions/reset_diagnostic_counters.hpp, Fix typo in header guard
- fix(rest): use std::array to provide compile-time size information
- style(rest): change class name from UUID to Uuid
- fix(rest): byte order in SetServiceRoleFlags, set batteryLevel and supplyVoltage TLVs as omitable
- refact(rest): refactored for cpp-httplib
- fix: prevent incorrect timezone offset produced from offset in seconds rather than absolute POSIX time
- test(rest): let test script fail fast
- fix(rest): check for duplicated joiners
- fix(rest): action API by reference
- fix(rest): add sparsefields for api/actions
- refact(rest): use cpp-httplib path parser to get itemId
- fix(rest): cleanup extract queries
- test(rest): run cicd tests
- fix(rest): get border agent state
@martinzi martinzi requested a review from jwhui September 8, 2025 19:52
@jwhui jwhui changed the title [rest] Add REST JSON:API for commissioner and diagnostics [rest] add REST JSON:API for commissioner and diagnostics Sep 10, 2025
Copy link
Copy Markdown
Member

@jwhui jwhui left a comment

Choose a reason for hiding this comment

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

Thanks! 👍🏼

@jwhui jwhui merged commit 2e8ccf2 into openthread:main Sep 10, 2025
109 of 115 checks passed
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.

7 participants