Skip to content

Commit

Permalink
Resolved compiler warings and formatted the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees-Schotanus committed Oct 28, 2024
1 parent 6ebe465 commit 5270a7c
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 61 deletions.
4 changes: 2 additions & 2 deletions packages/kiota_abstractions/lib/src/case_insensitive_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ class CaseInsensitiveMap<K extends String, V> implements Map<K, V> {
final normalizedKey = normalizeKey(key);

return _contents.putIfAbsent(normalizedKey, () {
_originalKeys[normalizedKey] = key;
_originalKeys[normalizedKey] = key;

return ifAbsent();
return ifAbsent();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ extension RequestInformationExtensions on RequestInformation {
}

void configure<T extends AbstractQueryParameters>(
void Function(RequestConfiguration<T>)? configurator,
T Function()? createParameters) {
void Function(RequestConfiguration<T>)? configurator,
T Function()? createParameters,
) {
if (configurator == null || createParameters == null) {
return;
}
Expand Down
41 changes: 21 additions & 20 deletions packages/kiota_abstractions/lib/src/serialization/untyped_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ part of '../../kiota_abstractions.dart';

/// Base class for untyped node.
class UntypedNode implements Parsable {
const UntypedNode();
const UntypedNode();

/// Creates a new [UntypedNode] instance.
factory UntypedNode.createFromDiscriminatorValue(ParseNode _) {
return const UntypedNode();
}
/// The deserialization information for the current model.
/// Returns a map of serializer methods for this object.
@override
Map<String, void Function(ParseNode)> getFieldDeserializers() {
return {};
}
/// Creates a new [UntypedNode] instance.
factory UntypedNode.createFromDiscriminatorValue(ParseNode _) {
return const UntypedNode();
}

/// Serializes the current object
@override
void serialize(SerializationWriter writer) {
// no properties to serialize. This is handled by custom serialization logic.
}
/// The deserialization information for the current model.
/// Returns a map of serializer methods for this object.
@override
Map<String, void Function(ParseNode)> getFieldDeserializers() {
return {};
}

/// Gets the value assigned to untyped node.
Object? getValue() {
throw Exception('getValue is implemented for derived types of UntypedNode');
}
/// Serializes the current object
@override
void serialize(SerializationWriter writer) {
// no properties to serialize. This is handled by custom serialization logic.
}

/// Gets the value assigned to untyped node.
Object? getValue() {
throw Exception('getValue is implemented for derived types of UntypedNode');
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
part of '../../kiota_abstractions.dart';

class UntypedString extends UntypedNode {

const UntypedString(this.value);

final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ void main() {
test('VendorSpecificContentType', () {
const contentType = 'application/json';
final mockFactory = MockParseNodeFactory();
final jsonStream= utf8.encode('{"test": "input"}');
final jsonStream = utf8.encode('{"test": "input"}');
final mockParseNode = MockParseNode();
when(mockFactory.getRootParseNode(contentType, jsonStream)).thenReturn(mockParseNode);
ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.putIfAbsent(contentType, ()=>mockFactory);
final rootParseNode = ParseNodeFactoryRegistry.defaultInstance.getRootParseNode('application/vnd+json', jsonStream);
when(mockFactory.getRootParseNode(contentType, jsonStream))
.thenReturn(mockParseNode);
ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories
.putIfAbsent(contentType, () => mockFactory);
final rootParseNode = ParseNodeFactoryRegistry.defaultInstance
.getRootParseNode('application/vnd+json', jsonStream);
expect(rootParseNode, isNotNull);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ void main() {
const contentType = 'application/text';
final mockWriter = MockSerializationWriter();
final mockFactory = MockSerializationWriterFactory();
when(mockFactory.getSerializationWriter(contentType)).thenReturn(mockWriter);
SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.putIfAbsent(contentType, () => mockFactory);
final serializationWriter = SerializationWriterFactoryRegistry.defaultInstance.getSerializationWriter('application/vnd+text');
when(mockFactory.getSerializationWriter(contentType))
.thenReturn(mockWriter);
SerializationWriterFactoryRegistry
.defaultInstance.contentTypeAssociatedFactories
.putIfAbsent(contentType, () => mockFactory);
final serializationWriter = SerializationWriterFactoryRegistry
.defaultInstance
.getSerializationWriter('application/vnd+text');
expect(serializationWriter, isNotNull);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class FormSerializationWriter implements SerializationWriter {

if (additionalValuesToMerge != null) {
for (final additionalValue in additionalValuesToMerge) {
if(additionalValue != null){
if (additionalValue != null) {
onBeforeObjectSerialization?.call(additionalValue);
onStartObjectSerialization?.call(additionalValue, this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void main() {

expect(
node.getGuidValue(),
equals(UuidValue.nil),
equals(UuidValue.fromString('00000000-0000-0000-0000-000000000000')),
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class JsonParseNode implements ParseNode {

UntypedNode? getUntypedValue(dynamic node) {
if (node == null) {
return UntypedNull();
return const UntypedNull();
}

if (node is List) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ void main() {
..serialize(writer);
final content = writer.getSerializedContent();
final result = utf8.decode(content);
expect(result,
'{"id":"opaque","officeLocation":"Montreal","displayName":"McGill"}');
expect(
result,
'{"id":"opaque","officeLocation":"Montreal","displayName":"McGill"}',
);
});

test('SerializeIntersectionTypeComplexProperty2', () {
Expand Down Expand Up @@ -132,8 +134,10 @@ void main() {
..serialize(writer);
final content = writer.getSerializedContent();
final result = utf8.decode(content);
expect(result,
'[{"id":"10","namingEnum":"Item2:SubItem1","officeLocation":"Montreal"},{"id":"11","namingEnum":"Item3:SubItem1","officeLocation":"Ottawa"}]');
expect(
result,
'[{"id":"10","namingEnum":"Item2:SubItem1","officeLocation":"Montreal"},{"id":"11","namingEnum":"Item3:SubItem1","officeLocation":"Ottawa"}]',
);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ void main() {
test('getParseNodeForJsonContentType', () {
final json = utf8.encode('{"key":"value"}');
final factory = JsonParseNodeFactory();
final JsonParseNode =
final jsonParseNode =
factory.getRootParseNode(factory.validContentType, json);
expect(JsonParseNode, isNotNull);
expect(jsonParseNode, isNotNull);
});

test('testThrowsExceptionForInvalidContentType', () {
const streamContentType = 'application/octet-stream';
final json = utf8.encode('{"key":"value"}');
final factory = JsonParseNodeFactory();
expect(() => factory.getRootParseNode(streamContentType, json),
throwsArgumentError);
expect(
() => factory.getRootParseNode(streamContentType, json),
throwsArgumentError,
);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ void main() {
test('Get enumcollection from json', () {
final jsonParseNode =
JsonParseNode(jsonDecode(_testCollectionOfEnumsJson));
final testCollection = jsonParseNode.getCollectionOfEnumValues((value) =>
NamingEnum.values.where((ne) => ne.value == value).firstOrNull);
final testCollection = jsonParseNode.getCollectionOfEnumValues(
(value) =>
NamingEnum.values.where((ne) => ne.value == value).firstOrNull,
);

expect(testCollection, isNotNull);
expect(testCollection.length, 2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:kiota_abstractions/kiota_abstractions.dart';
import 'package:kiota_serialization_json/kiota_serialization_json.dart';
import 'package:test/test.dart';

Expand All @@ -15,8 +13,10 @@ void main() {
test('testThrowsExceptionForInvalidContentType', () {
const streamContentType = 'application/octet-stream';
final factory = JsonSerializationWriterFactory();
expect(() => factory.getSerializationWriter(streamContentType),
throwsArgumentError);
expect(
() => factory.getSerializationWriter(streamContentType),
throwsArgumentError,
);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void main() {
expect(
utf8.decode(writer.getSerializedContent()),
equals(
'{"id":"abc","createdDateTime":"2023-12-01T15:15:00.000","officeLocation":"at the desk","workDuration":"40:00:00.000000","birthDay":"2024-10-01","heightInMetres":1.7,"startWorkTime":"06:00:00","active":true,"numbers":[2,3,5],"a":"some value","b":12,"c":false}'),
'{"id":"abc","createdDateTime":"2023-12-01T15:15:00.000","officeLocation":"at the desk","workDuration":"40:00:00.000000","birthDay":"2024-10-01","heightInMetres":1.7,"startWorkTime":"06:00:00","active":true,"numbers":[2,3,5],"a":"some value","b":12,"c":false}',
),
);
});

Expand Down Expand Up @@ -88,7 +89,8 @@ void main() {
expect(
utf8.decode(writer.getSerializedContent()),
equals(
'{"name":"a group","leader":{"heightInMetres":1.9,"endWorkTime":"17:00:00"},"members":[{"officeLocation":"on a chair","workDuration":"2:00:00.000000","a":"#1 coworker"},{"workDuration":"12:00:00.000000","active":true}]}'),
'{"name":"a group","leader":{"heightInMetres":1.9,"endWorkTime":"17:00:00"},"members":[{"officeLocation":"on a chair","workDuration":"2:00:00.000000","a":"#1 coworker"},{"workDuration":"12:00:00.000000","active":true}]}',
),
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class MicrosoftGraphGroup extends Parsable implements AdditionalDataHolder {
'leader': (node) => leader =
node.getObjectValue(MicrosoftGraphUser.createFromDiscriminator),
'members': (node) => members = node.getCollectionOfObjectValues(
MicrosoftGraphUser.createFromDiscriminator),
MicrosoftGraphUser.createFromDiscriminator,
),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:kiota_abstractions/kiota_abstractions.dart';
class SecondTestEntity extends Parsable implements AdditionalDataHolder {
SecondTestEntity();

factory SecondTestEntity.createFromDiscriminatorValue(ParseNode parseNode) {
factory SecondTestEntity.createFromDiscriminatorValue(ParseNode _) {
return SecondTestEntity();
}

Expand All @@ -25,9 +25,9 @@ class SecondTestEntity extends Parsable implements AdditionalDataHolder {
@override
void serialize(SerializationWriter writer) {
writer
..writeStringValue("displayName", displayName)
..writeIntValue("id", id)
..writeIntValue("failureRate", failureRate)
..writeStringValue('displayName', displayName)
..writeIntValue('id', id)
..writeIntValue('failureRate', failureRate)
..writeAdditionalData(additionalData);
}
}
6 changes: 4 additions & 2 deletions packages/kiota_serialization_json/test/union_type_mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class UnionTypeMock extends Parsable implements AdditionalDataHolder {
result.stringValue = parseNode.getStringValue();
} else if (parseNode
.getCollectionOfObjectValues<MicrosoftGraphUser>(
MicrosoftGraphUser.createFromDiscriminator)
MicrosoftGraphUser.createFromDiscriminator,
)
.isNotEmpty) {
result.composedType3 =
parseNode.getCollectionOfObjectValues<MicrosoftGraphUser>(
MicrosoftGraphUser.createFromDiscriminator);
MicrosoftGraphUser.createFromDiscriminator,
);
}
return result;
}
Expand Down
6 changes: 4 additions & 2 deletions packages/kiota_serialization_json/test/union_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ void main() {
..serialize(writer);
final content = writer.getSerializedContent();
final result = utf8.decode(content);
expect(result,
'[{"id":"10","officeLocation":"Montreal"},{"id":"11","officeLocation":"Ottawa"}]');
expect(
result,
'[{"id":"10","officeLocation":"Montreal"},{"id":"11","officeLocation":"Ottawa"}]',
);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void main() {

expect(
node.getGuidValue(),
equals(UuidValue.nil),
equals(UuidValue.fromString('00000000-0000-0000-0000-000000000000')),
);
});

Expand Down

0 comments on commit 5270a7c

Please sign in to comment.