-
Notifications
You must be signed in to change notification settings - Fork 62
feat(br_server): add REST API discovery endpoint (/.well-known/thread/esp-br-rest) #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # REST API Changelog | ||
|
|
||
| Version history of the esp-thread-br REST API, as reported by `ESP_OT_REST_API_VERSION` | ||
| (`private_include/esp_br_web_api.h`) and `openapi.yaml`'s `info.version`. Follows | ||
| [Semantic Versioning](https://semver.org/): MAJOR for incompatible API changes, MINOR for | ||
| backward-compatible additions, PATCH for backward-compatible fixes. | ||
|
|
||
| ## [1.1.0] | ||
|
|
||
| ### Added | ||
| - Border Agent ephemeral key (ePSKc) endpoints: `GET`/`PUT /node/ba-epskc/state` and | ||
| `GET`/`POST`/`DELETE /node/ba-epskc/key`. | ||
| - REST API discovery endpoint: `GET /.well-known/thread/esp-br-rest`, returning the running | ||
| REST API version and RFC 8288 links to its entry points | ||
| (see https://github.com/espressif/esp-thread-br/pull/216). | ||
|
|
||
| ## [1.0.0] | ||
|
|
||
| ### Added | ||
| - Initial versioned REST API surface: `/node`, `/node/rloc`, `/node/rloc16`, `/node/state`, | ||
| `/node/ext-address`, `/node/network-name`, `/node/leader-data`, `/node/num-of-router`, | ||
| `/node/ext-panid`, `/node/ba-id`, `/node/dataset/active`, `/node/dataset/pending`, and | ||
| `/diagnostics`. |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """ | ||
| Check that ESP_OT_REST_API_VERSION (the runtime source of truth returned by the | ||
| REST API discovery endpoint) and openapi.yaml's `info.version` stay in sync, so the | ||
| two do not silently drift apart when one is bumped without the other. | ||
|
|
||
| See https://github.com/espressif/esp-thread-br/pull/216#discussion_r3819911931. | ||
| """ | ||
|
|
||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import yaml | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[2] | ||
| HEADER_PATH = REPO_ROOT / "components/esp_ot_br_server/private_include/esp_br_web_api.h" | ||
| OPENAPI_PATH = REPO_ROOT / "components/esp_ot_br_server/src/openapi.yaml" | ||
|
|
||
| VERSION_DEFINE_RE = re.compile(r'#define\s+ESP_OT_REST_API_VERSION\s+"([^"]+)"') | ||
|
|
||
|
|
||
| def get_header_version(path: Path) -> str: | ||
| match = VERSION_DEFINE_RE.search(path.read_text()) | ||
| if not match: | ||
| print(f"Failed to find ESP_OT_REST_API_VERSION in {path}") | ||
| sys.exit(1) | ||
| return match.group(1) | ||
|
|
||
|
|
||
| def get_openapi_version(path: Path) -> str: | ||
| with open(path) as f: | ||
| spec = yaml.safe_load(f) | ||
| try: | ||
| return spec["info"]["version"] | ||
| except (KeyError, TypeError): | ||
| print(f"Failed to find info.version in {path}") | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| header_version = get_header_version(HEADER_PATH) | ||
| openapi_version = get_openapi_version(OPENAPI_PATH) | ||
|
|
||
| if header_version != openapi_version: | ||
| print( | ||
| f"REST API version mismatch: ESP_OT_REST_API_VERSION in {HEADER_PATH} is " | ||
| f"'{header_version}', but info.version in {OPENAPI_PATH} is '{openapi_version}'. " | ||
| "Bump both together." | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| print(f"REST API version check passed: {header_version}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the
apipointer is NULL before we use it.