Do not return empty relationships

If no relationships of a particular type are defined for a resource, the
key for that relationship should not be defined.
This commit is contained in:
Markus Mäkelä
2017-10-23 10:31:14 +03:00
parent d371ecb30f
commit 582a65f77c
5 changed files with 47 additions and 10 deletions

View File

@ -1502,8 +1502,19 @@ static json_t* server_to_json_data(const SERVER* server, const char* host)
/** Relationships */
json_t* rel = json_object();
json_object_set_new(rel, CN_SERVICES, service_relations_to_server(server, host));
json_object_set_new(rel, CN_MONITORS, monitor_relations_to_server(server, host));
json_t* service_rel = service_relations_to_server(server, host);
json_t* monitor_rel = monitor_relations_to_server(server, host);
if (service_rel)
{
json_object_set_new(rel, CN_SERVICES, service_rel);
}
if (monitor_rel)
{
json_object_set_new(rel, CN_MONITORS, monitor_rel);
}
json_object_set_new(rval, CN_RELATIONSHIPS, rel);
/** Attributes */
json_object_set_new(rval, CN_ATTRIBUTES, server_json_attributes(server));