@@ -1433,6 +1433,47 @@ def test_missing_tx_bytes(self):
14331433 self .assertEqual (points [0 ].get ("rx_bytes" ), 324 )
14341434 self .assertEqual (points [0 ].get ("tx_bytes" ), 0 )
14351435
1436+ def test_device_metric_view_schema_not_empty (self ):
1437+ """
1438+ Regression test for https://github.com/openwisp/openwisp-monitoring/issues/716.
1439+ Ensures DeviceMetricView exposes correctly populated schema fields via drf-yasg.
1440+ """
1441+ try :
1442+ from drf_yasg import openapi
1443+ from drf_yasg .generators import OpenAPISchemaGenerator
1444+ except ImportError :
1445+ self .skipTest ("drf-yasg is not installed" )
1446+
1447+ info = openapi .Info (title = "OpenWISP Monitoring API" , default_version = "v1" )
1448+ generator = OpenAPISchemaGenerator (info = info )
1449+ schema = generator .get_schema (public = True )
1450+ schema_dict = schema .as_dict ()
1451+
1452+ path_item = None
1453+ for path_name , path_obj in schema_dict .get ("paths" , {}).items ():
1454+ if "monitoring/device/" in path_name and (
1455+ "{id}" in path_name or "{uuid}" in path_name
1456+ ):
1457+ path_item = path_obj
1458+ break
1459+
1460+ self .assertIsNotNone (path_item , "Device Metric API path not found in schema" )
1461+ self .assertIn ("get" , path_item )
1462+
1463+ resp_200 = path_item ["get" ]["responses" ].get ("200" )
1464+ self .assertIsNotNone (resp_200 )
1465+ self .assertIn ("schema" , resp_200 )
1466+
1467+ schema_obj = resp_200 ["schema" ]
1468+ if "$ref" in schema_obj :
1469+ ref_path = schema_obj ["$ref" ]
1470+ definition_name = ref_path .split ("/" )[- 1 ]
1471+ schema_obj = schema_dict .get ("definitions" , {}).get (definition_name , {})
1472+
1473+ self .assertIn ("properties" , schema_obj )
1474+ self .assertIn ("mac_address" , schema_obj ["properties" ])
1475+ self .assertIn ("management_ip" , schema_obj ["properties" ])
1476+
14361477
14371478class TestGeoApi (TestGeoMixin , AuthenticationMixin , DeviceMonitoringTestCase ):
14381479 location_model = Location
0 commit comments