Skip to content

Commit

Permalink
feat!(form.dart): don't serialize default contentType value
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Nov 1, 2024
1 parent a7adb0d commit a4bd0ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 7 additions & 2 deletions lib/src/core/definitions/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Form implements Serializable {
/// An [href] has to be provided. A [contentType] is optional.
Form(
this.href, {
this.contentType = "application/json",
this.contentType = _defaultContentType,
this.contentCoding,
this.subprotocol,
this.security,
Expand Down Expand Up @@ -86,6 +86,8 @@ class Form implements Serializable {
);
}

static const _defaultContentType = "application/json";

/// The [href] pointing to the resource.
///
/// Can be a relative or absolute URI.
Expand Down Expand Up @@ -134,7 +136,6 @@ class Form implements Serializable {
Map<String, dynamic> toJson() {
final result = {
"href": href.toString(),
"contentType": contentType,
...additionalFields,
};

Expand All @@ -148,6 +149,10 @@ class Form implements Serializable {
op.map((opValue) => opValue.toString()).toList(growable: false);
}

if (contentType != _defaultContentType) {
result["contentType"] = contentType;
}

if (contentCoding != null) {
result["contentCoding"] = contentCoding;
}
Expand Down
5 changes: 0 additions & 5 deletions test/core/definitions/serialization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ void main() {
"op": [
"readmultipleproperties",
],
// TODO: Should defaults actually be set?
"contentType": "application/json",
},
],
"properties": {},
Expand Down Expand Up @@ -103,7 +101,6 @@ void main() {
"href": "https://example.org",
"subprotocol": "foobar",
"contentCoding": "test",
"contentType": "application/json",
"security": ["test"],
"response": {
"contentType": "application/json",
Expand All @@ -123,7 +120,6 @@ void main() {
test("AugmentedForms", () async {
final formJson = {
"href": "https://example.org",
"contentType": "application/json",
};

final thingDescription = {
Expand Down Expand Up @@ -186,7 +182,6 @@ void main() {
"forms": [
{
"href": "https://example.org",
"contentType": "application/json",
}
],
};
Expand Down

0 comments on commit a4bd0ad

Please sign in to comment.