Skip to content

Commit bb5bfc1

Browse files
author
Michał Fąferek
committed
[#40] fix: return server capabilities at GET / and add GET /version-info
- GET / now returns server capabilities and entry points per REQ_INTEROP_010 (name, version, endpoints list, capabilities object) - Add GET /version-info for version information per REQ_INTEROP_001 (status, version, timestamp) - Update test_01_root_endpoint to verify capabilities response - Add test_01b_version_info_endpoint for new endpoint - Update Postman collection with new requests
1 parent e034a4d commit bb5bfc1

File tree

4 files changed

+98
-6
lines changed

4 files changed

+98
-6
lines changed

postman/collections/ros2-medkit-gateway.postman_collection.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"name": "Discovery",
1010
"item": [
1111
{
12-
"name": "GET Gateway Info",
12+
"name": "GET Server Capabilities",
1313
"request": {
1414
"method": "GET",
1515
"header": [],
@@ -22,7 +22,25 @@
2222
""
2323
]
2424
},
25-
"description": "Get gateway status and version information"
25+
"description": "Get server capabilities and entry points (REQ_INTEROP_010). Returns server name, version, available endpoints, and capabilities."
26+
},
27+
"response": []
28+
},
29+
{
30+
"name": "GET Version Info",
31+
"request": {
32+
"method": "GET",
33+
"header": [],
34+
"url": {
35+
"raw": "{{base_url}}/version-info",
36+
"host": [
37+
"{{base_url}}"
38+
],
39+
"path": [
40+
"version-info"
41+
]
42+
},
43+
"description": "Get gateway status and version information (REQ_INTEROP_001). Returns status, version, and timestamp."
2644
},
2745
"response": []
2846
},

src/ros2_medkit_gateway/include/ros2_medkit_gateway/rest_server.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class RESTServer {
4040
// Route handlers
4141
void handle_health(const httplib::Request& req, httplib::Response& res);
4242
void handle_root(const httplib::Request& req, httplib::Response& res);
43+
void handle_version_info(const httplib::Request& req, httplib::Response& res);
4344
void handle_list_areas(const httplib::Request& req, httplib::Response& res);
4445
void handle_list_components(const httplib::Request& req, httplib::Response& res);
4546
void handle_area_components(const httplib::Request& req, httplib::Response& res);

src/ros2_medkit_gateway/src/rest_server.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ void RESTServer::setup_routes() {
4444
handle_health(req, res);
4545
});
4646

47-
// Root
47+
// Root - server capabilities and entry points (REQ_INTEROP_010)
4848
server_->Get("/", [this](const httplib::Request& req, httplib::Response& res) {
4949
handle_root(req, res);
5050
});
5151

52+
// Version info (REQ_INTEROP_001)
53+
server_->Get("/version-info", [this](const httplib::Request& req, httplib::Response& res) {
54+
handle_version_info(req, res);
55+
});
56+
5257
// Areas
5358
server_->Get("/areas", [this](const httplib::Request& req, httplib::Response& res) {
5459
handle_list_areas(req, res);
@@ -160,6 +165,39 @@ void RESTServer::handle_health(const httplib::Request& req, httplib::Response& r
160165
void RESTServer::handle_root(const httplib::Request& req, httplib::Response& res) {
161166
(void)req; // Unused parameter
162167

168+
try {
169+
json response = {
170+
{"name", "ROS 2 Medkit Gateway"},
171+
{"version", "0.1.0"},
172+
{"endpoints", json::array({
173+
"/health",
174+
"/version-info",
175+
"/areas",
176+
"/components",
177+
"/areas/{area_id}/components",
178+
"/components/{component_id}/data",
179+
"/components/{component_id}/data/{topic_name}"
180+
})},
181+
{"capabilities", {
182+
{"discovery", true},
183+
{"data_access", true}
184+
}}
185+
};
186+
187+
res.set_content(response.dump(2), "application/json");
188+
} catch (const std::exception& e) {
189+
res.status = StatusCode::InternalServerError_500;
190+
res.set_content(
191+
json{{"error", "Internal server error"}}.dump(),
192+
"application/json"
193+
);
194+
RCLCPP_ERROR(rclcpp::get_logger("rest_server"), "Error in handle_root: %s", e.what());
195+
}
196+
}
197+
198+
void RESTServer::handle_version_info(const httplib::Request& req, httplib::Response& res) {
199+
(void)req; // Unused parameter
200+
163201
try {
164202
json response = {
165203
{"status", "ROS 2 Medkit Gateway running"},
@@ -174,7 +212,11 @@ void RESTServer::handle_root(const httplib::Request& req, httplib::Response& res
174212
json{{"error", "Internal server error"}}.dump(),
175213
"application/json"
176214
);
177-
RCLCPP_ERROR(rclcpp::get_logger("rest_server"), "Error in handle_root: %s", e.what());
215+
RCLCPP_ERROR(
216+
rclcpp::get_logger("rest_server"),
217+
"Error in handle_version_info: %s",
218+
e.what()
219+
);
178220
}
179221
}
180222

src/ros2_medkit_gateway/test/test_integration.test.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,47 @@ def _get_json(self, endpoint: str):
167167

168168
def test_01_root_endpoint(self):
169169
"""
170-
Test GET / returns gateway status and version.
170+
Test GET / returns server capabilities and entry points.
171171
172172
@verifies REQ_INTEROP_010
173173
"""
174174
data = self._get_json('/')
175+
self.assertIn('name', data)
176+
self.assertIn('version', data)
177+
self.assertIn('endpoints', data)
178+
self.assertIn('capabilities', data)
179+
180+
self.assertEqual(data['name'], 'ROS 2 Medkit Gateway')
181+
self.assertEqual(data['version'], '0.1.0')
182+
183+
# Verify endpoints list
184+
self.assertIsInstance(data['endpoints'], list)
185+
self.assertIn('/health', data['endpoints'])
186+
self.assertIn('/version-info', data['endpoints'])
187+
self.assertIn('/areas', data['endpoints'])
188+
self.assertIn('/components', data['endpoints'])
189+
190+
# Verify capabilities
191+
self.assertIn('discovery', data['capabilities'])
192+
self.assertIn('data_access', data['capabilities'])
193+
self.assertTrue(data['capabilities']['discovery'])
194+
self.assertTrue(data['capabilities']['data_access'])
195+
print('✓ Root endpoint test passed')
196+
197+
def test_01b_version_info_endpoint(self):
198+
"""
199+
Test GET /version-info returns gateway status and version.
200+
201+
@verifies REQ_INTEROP_001
202+
"""
203+
data = self._get_json('/version-info')
175204
self.assertIn('status', data)
176205
self.assertIn('version', data)
206+
self.assertIn('timestamp', data)
177207
self.assertEqual(data['status'], 'ROS 2 Medkit Gateway running')
178208
self.assertEqual(data['version'], '0.1.0')
179-
print('✓ Root endpoint test passed')
209+
self.assertIsInstance(data['timestamp'], int)
210+
print('✓ Version info endpoint test passed')
180211

181212
def test_02_list_areas(self):
182213
"""

0 commit comments

Comments
 (0)