Skip to content

Commit

Permalink
fix(core): correctly serialize property affordances
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Nov 1, 2024
1 parent 90e0622 commit 702fa7a
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/src/core/definitions/interaction_affordances/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Property extends InteractionAffordance implements DataSchema {
super.uriVariables,
super.additionalFields,
required this.dataSchema,
this.observable = false,
this.observable = _defaultObservableValue,
});

/// Creates a new [Property] from a [json] object.
Expand Down Expand Up @@ -51,6 +51,22 @@ class Property extends InteractionAffordance implements DataSchema {
return property;
}

@override
Map<String, dynamic> toJson() {
final result = {
...super.toJson(),
...dataSchema.toJson(),
};

if (observable != _defaultObservableValue) {
result["observable"] = observable;
}

return result;
}

static const _defaultObservableValue = false;

/// The internal [DataSchema] this property is based on.
final DataSchema dataSchema;

Expand Down Expand Up @@ -148,8 +164,15 @@ class Property extends InteractionAffordance implements DataSchema {

@override
Map<String, dynamic> get additionalFields {
final additionalDataSchemaFields = dataSchema.additionalFields.entries
.where((entry) => super.additionalFields.containsKey(entry.key));
final additionalDataSchemaFields =
dataSchema.additionalFields.entries.where(
(entry) => [
...super.additionalFields.keys,
"observable",
].contains(
entry.key,
),
);

return Map.fromEntries(additionalDataSchemaFields);
}
Expand Down

0 comments on commit 702fa7a

Please sign in to comment.