Skip to content

Commit c7d18fc

Browse files
Refactor MXL staged parameter schema to support both "auto" and "null" as valid values. Update related functions and constraints to accommodate the new schema structure.
1 parent 42de1c2 commit c7d18fc

1 file changed

Lines changed: 55 additions & 44 deletions

File tree

Development/nmos/connection_api.cpp

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -131,37 +131,15 @@ namespace nmos
131131
staged_core_validator().validate(staged, experimental::make_connectionapi_staged_patch_request_schema_uri(version, type));
132132
}
133133

134-
// Extend an existing schema with "auto" as a valid value
135-
web::json::value make_auto_schema(const web::json::value& schema)
136-
{
137-
using web::json::value_of;
138-
139-
const bool keep_order = true;
140-
141-
return value_of({
142-
{ U("anyOf"), value_of({
143-
value_of({
144-
{ U("type"), U("string") },
145-
{ U("pattern"), U("^auto$") }
146-
}, keep_order),
147-
schema
148-
}) }
149-
});
150-
}
151-
152-
// BCP-007-03: MXL staged transport parameters accept null (unconfigured) as well as constraint values (and auto where applicable)
153-
// See https://specs.amwa.tv/bcp-007-03/branches/publish-auto-null/docs/NMOS-With-MXL.html
154-
// and sender_transport_params_mxl.json / receiver_transport_params_mxl.json
155-
web::json::value make_mxl_staged_param_schema(const web::json::value& schema, bool auto_value)
134+
// Extend an existing schema with "auto" and/or null as valid values
135+
web::json::value make_staged_param_schema(const web::json::value& schema, bool auto_value, bool null_value)
156136
{
157137
using web::json::value;
158138
using web::json::value_of;
159139

160-
const bool keep_order = true;
140+
if (!auto_value && !null_value) return schema;
161141

162-
static const utility::string_t mxl_uuid_pattern{
163-
U("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$")
164-
};
142+
const bool keep_order = true;
165143

166144
auto any_of = value::array();
167145

@@ -173,22 +151,15 @@ namespace nmos
173151
}, keep_order));
174152
}
175153

176-
if (!schema.as_object().empty())
177-
{
178-
web::json::push_back(any_of, schema);
179-
}
180-
else
154+
web::json::push_back(any_of, schema);
155+
156+
if (null_value)
181157
{
182158
web::json::push_back(any_of, value_of({
183-
{ U("type"), U("string") },
184-
{ U("pattern"), mxl_uuid_pattern }
159+
{ U("type"), U("null") }
185160
}, keep_order));
186161
}
187162

188-
web::json::push_back(any_of, value_of({
189-
{ U("type"), U("null") }
190-
}, keep_order));
191-
192163
return value_of({
193164
{ U("anyOf"), any_of }
194165
}, keep_order);
@@ -312,6 +283,31 @@ namespace nmos
312283
return auto_constraints;
313284
}
314285

286+
static const std::map<nmos::type, std::set<utility::string_t>>& mxl_null_constraints()
287+
{
288+
// These are the constraints that support null (unconfigured) in /staged
289+
// See https://specs.amwa.tv/bcp-007-03/branches/publish-auto-null/docs/NMOS-With-MXL.html
290+
// and sender_transport_params_mxl.json / receiver_transport_params_mxl.json
291+
static const std::map<nmos::type, std::set<utility::string_t>> null_constraints
292+
{
293+
{
294+
nmos::types::sender,
295+
{
296+
nmos::fields::mxl_domain_id,
297+
nmos::fields::mxl_flow_id
298+
}
299+
},
300+
{
301+
nmos::types::receiver,
302+
{
303+
nmos::fields::mxl_domain_id,
304+
nmos::fields::mxl_flow_id
305+
}
306+
}
307+
};
308+
return null_constraints;
309+
}
310+
315311
static const std::map<nmos::type, std::set<utility::string_t>>& auto_constraints(const nmos::transport& transport_base)
316312
{
317313
if (nmos::transports::rtp == transport_base) return rtp_auto_constraints();
@@ -331,6 +327,22 @@ namespace nmos
331327
return no_auto_constraints;
332328
}
333329

330+
static const std::map<nmos::type, std::set<utility::string_t>>& null_constraints(const nmos::transport& transport_base)
331+
{
332+
if (nmos::transports::mxl == transport_base) return mxl_null_constraints();
333+
334+
static const std::map<nmos::type, std::set<utility::string_t>> no_null_constraints
335+
{
336+
{
337+
nmos::types::sender, {}
338+
},
339+
{
340+
nmos::types::receiver, {}
341+
}
342+
};
343+
return no_null_constraints;
344+
}
345+
334346
// Make a json schema from /constraints and /transporttype
335347
web::json::value make_constraints_schema(const nmos::type& type, const web::json::value& constraints, const nmos::transport& transport_base)
336348
{
@@ -342,21 +354,20 @@ namespace nmos
342354
auto items = value::array();
343355

344356
auto& type_auto_constraints = auto_constraints(transport_base).at(type);
357+
auto& type_null_constraints = null_constraints(transport_base).at(type);
345358

346359
for (const auto& leg : constraints.as_array())
347360
{
348361
auto properties = value::object();
349362

350363
for (const auto& constraint : leg.as_object())
351364
{
352-
if (nmos::transports::mxl == transport_base)
353-
{
354-
const bool auto_value = type_auto_constraints.end() != type_auto_constraints.find(constraint.first);
355-
properties[constraint.first] = make_mxl_staged_param_schema(constraint.second, auto_value);
356-
}
357-
else if (type_auto_constraints.end() != type_auto_constraints.find(constraint.first))
365+
const bool auto_value = type_auto_constraints.end() != type_auto_constraints.find(constraint.first);
366+
const bool null_value = type_null_constraints.end() != type_null_constraints.find(constraint.first);
367+
368+
if (auto_value || null_value)
358369
{
359-
properties[constraint.first] = make_auto_schema(constraint.second);
370+
properties[constraint.first] = make_staged_param_schema(constraint.second, auto_value, null_value);
360371
}
361372
else
362373
{

0 commit comments

Comments
 (0)