Skip to content

Commit 3be4625

Browse files
authored
Merge pull request #82 from eclipse-thingweb/fix-uri-variables
fix: fix handling of URI variables
2 parents c33be91 + 207b362 commit 3be4625

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

lib/src/core/content_serdes.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,19 @@ class ContentSerdes {
140140
}
141141

142142
void _validateValue(Object? value, DataSchema? dataSchema) {
143-
final dataSchemaJson = dataSchema?.rawJson;
144-
if (dataSchemaJson == null) {
143+
// TODO(JKRhb): The process of validating values according to a dataschema
144+
// needs to be reworked.
145+
const filteredKeys = ['uriVariables'];
146+
147+
final filteredDataSchemaJson = dataSchema?.rawJson?.entries
148+
.where((element) => !filteredKeys.contains(element.key));
149+
if (filteredDataSchemaJson == null) {
145150
return;
146151
}
147-
final schema =
148-
JsonSchema.create(dataSchemaJson, schemaVersion: SchemaVersion.draft7);
152+
final schema = JsonSchema.create(
153+
Map.fromEntries(filteredDataSchemaJson),
154+
schemaVersion: SchemaVersion.draft7,
155+
);
149156
if (!schema.validate(value).isValid) {
150157
throw ContentSerdesException('JSON Schema validation failed.');
151158
}

lib/src/definitions/form.dart

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -318,34 +318,23 @@ class Form {
318318
return null;
319319
}
320320

321-
if (affordanceUriVariables.isEmpty) {
322-
throw UriVariableException(
323-
'The Form href $href contains URI '
324-
'variables but the TD does not provide a uriVariables definition.',
321+
if (uriVariables != null) {
322+
// Perform additional validation
323+
_validateUriVariables(
324+
hrefUriVariables,
325+
affordanceUriVariables,
326+
uriVariables,
325327
);
326328
}
327329

328-
if (uriVariables == null) {
329-
throw ValidationException(
330-
'The Form href $href contains URI variables '
331-
'but no values were provided as InteractionOptions.',
332-
);
333-
}
334-
335-
// Perform additional validation
336-
_validateUriVariables(
337-
hrefUriVariables,
338-
affordanceUriVariables,
339-
uriVariables,
340-
);
341-
342330
// As "{" and "}" are "percent encoded" due to Uri.parse(), we need to
343331
// revert the encoding first before we can insert the values.
344332
final decodedHref = Uri.decodeFull(href.toString());
345333

346334
// Everything should be okay at this point, we can simply insert the values
347335
// and return the result.
348-
final newHref = Uri.parse(UriTemplate(decodedHref).expand(uriVariables));
336+
final newHref =
337+
Uri.parse(UriTemplate(decodedHref).expand(uriVariables ?? {}));
349338
return _copy(newHref);
350339
}
351340
}

0 commit comments

Comments
 (0)