Browse Source

migrate other classes to build_value

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/241/head
Nikolas Rimikis 2 years ago
parent
commit
bdcc43d560
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 102
      packages/dynamite/lib/src/openapi_builder.dart
  2. 6118
      packages/nextcloud/lib/src/nextcloud.openapi.dart
  3. 22040
      packages/nextcloud/lib/src/nextcloud.openapi.g.dart
  4. 7
      packages/nextcloud/test/notes.dart

102
packages/dynamite/lib/src/openapi_builder.dart

@ -1249,56 +1249,39 @@ TypeResult resolveObject(
b
..name = '${state.prefix}$identifier'
..docs.addAll(_descriptionToDocs(schema.description))
..annotations.add(
refer('JsonSerializable').call(
[],
{
if (schema.additionalProperties != null) ...{
'disallowUnrecognizedKeys': refer('false'),
},
if (extraJsonSerializableValues != null) ...{
for (final key in extraJsonSerializableValues.keys) ...{
key: refer(extraJsonSerializableValues[key]!),
},
},
},
..abstract = true
..implements.add(
refer(
'Built<${state.prefix}$identifier, ${state.prefix}${identifier}Builder>',
),
)
..constructors.addAll(
[
..constructors.addAll([
Constructor(
(final b) => b
..optionalParameters.addAll(
schema.properties!.keys.map(
(final propertyName) => Parameter(
(final b) {
final propertySchema = schema.properties![propertyName]!;
b
..name = _toDartName(propertyName)
..toThis = true
..named = true
..required =
(schema.required ?? []).contains(propertyName) && propertySchema.default_ == null;
if (propertySchema.default_ != null) {
final value = propertySchema.default_!.toString();
final result = resolveType(
spec,
state,
propertySchema.type!,
propertySchema,
);
b.defaultTo = Code(_valueToEscapedValue(result, value));
}
},
),
),
),
..name = '_'
..constant = true,
),
Constructor(
(final b) => b
..factory = true
..lambda = true
..optionalParameters.add(
Parameter(
(final b) => b
..name = 'b'
..type = refer('void Function(${state.prefix}${identifier}Builder)?'),
),
)
..redirect = refer('_\$${state.prefix}$identifier'),
),
])
..methods.addAll([
Method(
(final b) => b
..static = true
..name = 'fromJson'
..lambda = true
..returns = refer('${state.prefix}$identifier')
..requiredParameters.add(
Parameter(
(final b) => b
@ -1306,13 +1289,14 @@ TypeResult resolveObject(
..type = refer('Map<String, dynamic>'),
),
)
..body = Code('_\$${state.prefix}${identifier}FromJson(json)'),
..body = const Code('serializers.deserializeWith(serializer, json)!'),
),
Constructor(
Method(
(final b) => b
..factory = true
..static = true
..name = 'fromJsonString'
..lambda = true
..returns = refer('${state.prefix}$identifier')
..requiredParameters.add(
Parameter(
(final b) => b
@ -1320,17 +1304,14 @@ TypeResult resolveObject(
..type = refer('String'),
),
)
..body = Code('${state.prefix}$identifier.fromJson(json.decode(data) as Map<String, dynamic>)'),
..body = const Code('serializers.fromJson(serializer, data)!'),
),
],
)
..methods.addAll([
Method(
(final b) => b
..name = 'toJson'
..returns = refer('Map<String, dynamic>')
..lambda = true
..body = Code('_\$${state.prefix}${identifier}ToJson(this)'),
..body = const Code('serializers.serializeWith(serializer, this) as Map<String, dynamic>'),
),
Method(
(final b) => b
@ -1345,12 +1326,10 @@ TypeResult resolveObject(
..type = refer(_makeNullable('${state.prefix}$identifier', true)),
),
)
..body = const Code('data == null ? null : json.encode(data.toJson())'),
..body = const Code('data == null ? null : serializers.toJson(serializer, data)'),
),
])
..fields.addAll([
for (final propertyName in schema.properties!.keys) ...[
Field(
Method(
(final b) {
final propertySchema = schema.properties![propertyName]!;
final result = resolveType(
@ -1363,13 +1342,13 @@ TypeResult resolveObject(
b
..name = _toDartName(propertyName)
..type = refer(
..returns = refer(
_makeNullable(
result.name,
!(schema.required ?? []).contains(propertyName),
),
)
..modifier = FieldModifier.final$
..type = MethodType.getter
..docs.addAll(_descriptionToDocs(propertySchema.description));
final hasDifferentName = _toDartName(propertyName) != propertyName;
final isContentString = propertySchema.isContentString;
@ -1378,7 +1357,7 @@ TypeResult resolveObject(
final arguments = <String, Expression>{
if (hasDifferentName) ...{
'name': refer("'$propertyName'"),
'wireName': literalString(propertyName),
},
if (hasExtraJsonKeyValues) ...{
for (final key in extraJsonKeyValues[propertyName]!.keys) ...{
@ -1447,12 +1426,21 @@ TypeResult resolveObject(
if (arguments.isNotEmpty) {
b.annotations.add(
refer('JsonKey').call([], arguments),
refer('BuiltValueField').call([], arguments),
);
}
},
)
),
],
Method(
(final b) => b
..name = 'serializer'
..returns = refer('Serializer<${state.prefix}$identifier>')
..lambda = true
..static = true
..body = Code("_\$${_toCamelCase('${state.prefix}$identifier')}Serializer")
..type = MethodType.getter,
),
]);
},
),

6118
packages/nextcloud/lib/src/nextcloud.openapi.dart

File diff suppressed because it is too large Load Diff

22040
packages/nextcloud/lib/src/nextcloud.openapi.g.dart

File diff suppressed because it is too large Load Diff

7
packages/nextcloud/test/notes.dart

@ -122,9 +122,10 @@ Future run(final DockerImage image) async {
test('Update settings', () async {
var response = await client.notes.updateSettings(
notesSettings: NextcloudNotesSettings(
notesPath: 'Test Notes',
fileSuffix: '.txt',
noteMode: NextcloudNotesSettings_NoteMode.preview,
(final b) => b
..notesPath = 'Test Notes'
..fileSuffix = '.txt'
..noteMode = NextcloudNotesSettings_NoteMode.preview,
),
);
expect(response.notesPath, 'Test Notes');

Loading…
Cancel
Save