diff --git a/lib/src/core/content_serdes.dart b/lib/src/core/content_serdes.dart index 814ef3f9..3eaf7565 100644 --- a/lib/src/core/content_serdes.dart +++ b/lib/src/core/content_serdes.dart @@ -140,12 +140,19 @@ class ContentSerdes { } void _validateValue(Object? value, DataSchema? dataSchema) { - final dataSchemaJson = dataSchema?.rawJson; - if (dataSchemaJson == null) { + // TODO(JKRhb): The process of validating values according to a dataschema + // needs to be reworked. + const filteredKeys = ['uriVariables']; + + final filteredDataSchemaJson = dataSchema?.rawJson?.entries + .where((element) => !filteredKeys.contains(element.key)); + if (filteredDataSchemaJson == null) { return; } - final schema = - JsonSchema.create(dataSchemaJson, schemaVersion: SchemaVersion.draft7); + final schema = JsonSchema.create( + Map.fromEntries(filteredDataSchemaJson), + schemaVersion: SchemaVersion.draft7, + ); if (!schema.validate(value).isValid) { throw ContentSerdesException('JSON Schema validation failed.'); } diff --git a/lib/src/definitions/form.dart b/lib/src/definitions/form.dart index df164a18..ba640aae 100644 --- a/lib/src/definitions/form.dart +++ b/lib/src/definitions/form.dart @@ -318,34 +318,23 @@ class Form { return null; } - if (affordanceUriVariables.isEmpty) { - throw UriVariableException( - 'The Form href $href contains URI ' - 'variables but the TD does not provide a uriVariables definition.', + if (uriVariables != null) { + // Perform additional validation + _validateUriVariables( + hrefUriVariables, + affordanceUriVariables, + uriVariables, ); } - if (uriVariables == null) { - throw ValidationException( - 'The Form href $href contains URI variables ' - 'but no values were provided as InteractionOptions.', - ); - } - - // Perform additional validation - _validateUriVariables( - hrefUriVariables, - affordanceUriVariables, - uriVariables, - ); - // As "{" and "}" are "percent encoded" due to Uri.parse(), we need to // revert the encoding first before we can insert the values. final decodedHref = Uri.decodeFull(href.toString()); // Everything should be okay at this point, we can simply insert the values // and return the result. - final newHref = Uri.parse(UriTemplate(decodedHref).expand(uriVariables)); + final newHref = + Uri.parse(UriTemplate(decodedHref).expand(uriVariables ?? {})); return _copy(newHref); } }