Skip to content

Commit d265c4f

Browse files
committed
fix: fix handling of uri variables
1 parent 3a2d79a commit d265c4f

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

lib/src/core/implementation/augmented_form.dart

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,29 +145,20 @@ final class AugmentedForm implements Form {
145145
"level: ${uncoveredHrefUriVariables.join(", ")}.");
146146
}
147147

148-
final missingTdLevelUserInput = uriVariablesInHref.where(
149-
(uriVariableName) =>
150-
!userProvidedUriVariables.containsKey(uriVariableName),
151-
);
152-
153-
if (missingTdLevelUserInput.isNotEmpty) {
154-
throw UriVariableException(
155-
"The following URI template variables defined at the TD level are not "
156-
"covered by the values provided by the user: "
157-
"${missingTdLevelUserInput.join(", ")}. "
158-
"Values for the following variables were received: "
159-
"${userProvidedUriVariables.keys.join(", ")}.",
160-
);
161-
}
162-
163148
// We now assert that all user provided values comply to the Schema
164149
// definition in the TD.
165150
for (final affordanceUriVariable in affordanceUriVariables.entries) {
166151
final key = affordanceUriVariable.key;
167-
final value = affordanceUriVariable.value;
168152

169-
final schema = JsonSchema.create(value);
170-
final result = schema.validate(userProvidedUriVariables[key]);
153+
final userProvidedValue = userProvidedUriVariables[key];
154+
155+
if (userProvidedValue == null) {
156+
continue;
157+
}
158+
159+
final schemaValue = affordanceUriVariable.value;
160+
final schema = JsonSchema.create(schemaValue);
161+
final result = schema.validate(userProvidedValue);
171162

172163
if (!result.isValid) {
173164
throw ValidationException("Invalid type for URI variable $key");

test/core/augmented_form_test.dart

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ void main() {
164164
);
165165

166166
expect(
167-
() => augmentedForm2.resolvedHref,
168-
throwsA(isA<UriVariableException>()),
167+
augmentedForm2.resolvedHref,
168+
Uri.parse("http://example.org/weather/?lat=5"),
169169
);
170170

171171
final augmentedForm3 = AugmentedForm(
@@ -178,18 +178,8 @@ void main() {
178178
);
179179

180180
expect(
181-
() => augmentedForm3.resolvedHref,
182-
throwsA(
183-
predicate(
184-
(exception) =>
185-
exception is UriVariableException &&
186-
exception.toString() ==
187-
"UriVariableException: The following URI template "
188-
"variables defined at the TD level are not covered by "
189-
"the values provided by the user: lat. Values for the "
190-
"following variables were received: long.",
191-
),
192-
),
181+
augmentedForm3.resolvedHref,
182+
Uri.parse("http://example.org/weather/?long=10"),
193183
);
194184

195185
final augmentedForm4 = AugmentedForm(

0 commit comments

Comments
 (0)