Skip to content

Commit

Permalink
fixup! feat!: improve TD serialization behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jan 3, 2024
1 parent f06f37d commit 6207769
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/src/core/augmented_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// SPDX-License-Identifier: BSD-3-Clause

import "package:collection/collection.dart";
import "package:json_schema/json_schema.dart";
import "package:meta/meta.dart";
import "package:uri/uri.dart";
Expand Down Expand Up @@ -99,6 +100,8 @@ final class AugmentedForm implements Form {
.allMatches(decodedUri)
.map((e) => e.group(1))
.whereType<String>()
.map((e) => e.split(","))
.flattened
.toList(growable: false);
}

Expand Down
2 changes: 1 addition & 1 deletion test/binding_mqtt/mqtt_extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// SPDX-License-Identifier: BSD-3-Clause

import "package:dart_wot/dart_wot.dart";
import 'package:dart_wot/src/binding_mqtt/mqtt_extensions.dart';
import "package:dart_wot/src/binding_mqtt/mqtt_extensions.dart";
import "package:dart_wot/src/definitions/validation/validation_exception.dart";
import "package:test/test.dart";

Expand Down
63 changes: 63 additions & 0 deletions test/core/augmented_form_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,68 @@ void main() {
);
expect(augmentedForm2.href, Uri.parse("$href2/test"));
});

test("handle URI variables", () {
final thingDescription = ThingDescription.fromJson(
const {
"@context": "https://www.w3.org/2022/wot/td/v1.1",
"title": "Test TD",
"properties": {
"test": {
"uriVariables": {
"lat": {
"type": "number",
"minimum": 0,
"maximum": 90,
"description":
"Latitude for the desired location in the world",
},
"long": {
"type": "number",
"minimum": -180,
"maximum": 180,
"description":
"Longitude for the desired location in the world",
},
},
"forms": [
{
"href": "http://example.org/weather/{?lat,long}",
}
],
},
"test2": {
"forms": [
{
"href": "/test",
},
],
},
},
"security": ["nosec_sc"],
"securityDefinitions": {
"nosec_sc": {
"scheme": "nosec",
},
},
},
);
final affordance = thingDescription.properties?["test"];

final augmentedForm = AugmentedForm(
affordance!.forms.first,
affordance,
thingDescription,
const {
"lat": 5,
"long": 10,
},
);

expect(
augmentedForm.resolvedHref,
Uri.parse("http://example.org/weather/?lat=5&long=10"),
);
});
});
}

0 comments on commit 6207769

Please sign in to comment.