Skip to content

Commit 0c99594

Browse files
committed
fix(dynamite,nextcloud): fix nested ofs
Also generate interfaces for ofs so they can be used in other allOfs Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
1 parent 4fffe6d commit 0c99594

29 files changed

+885
-2287
lines changed

packages/dynamite/dynamite/lib/src/builder/ofs_builder.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,13 @@ TypeResult resolveAllOf(
5353
interfaces.add(interfaceClass);
5454
}
5555

56+
state.output.add(
57+
buildInterface(identifier, interfaces: interfaces),
58+
);
59+
5660
state.output.add(
5761
buildBuiltClass(
5862
identifier,
59-
interfaces: interfaces,
6063
),
6164
);
6265
}
@@ -99,7 +102,7 @@ TypeResult resolveOfs(
99102
}
100103

101104
state.output.addAll([
102-
buildBuiltClass(
105+
buildInterface(
103106
identifier,
104107
methods: BuiltList.build((final b) {
105108
b.add(
@@ -128,6 +131,9 @@ TypeResult resolveOfs(
128131
);
129132
}
130133
}),
134+
),
135+
buildBuiltClass(
136+
identifier,
131137
customSerializer: true,
132138
),
133139
Class(

packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:built_collection/built_collection.dart';
12
import 'package:code_builder/code_builder.dart';
23
import 'package:dynamite/src/builder/resolve_type.dart';
34
import 'package:dynamite/src/builder/state.dart';
@@ -18,18 +19,11 @@ TypeResultObject resolveInterface(
1819
);
1920

2021
if (state.resolvedInterfaces.add(result)) {
21-
final className = '$identifier$interfaceSuffix';
22-
23-
state.output.add(
24-
Class((final b) {
25-
b
26-
..abstract = true
27-
..modifier = ClassModifier.interface
28-
..name = className
29-
..annotations.add(refer('BuiltValue').call([], {'instantiable': literalFalse}));
30-
22+
final $interface = buildInterface(
23+
identifier,
24+
methods: BuiltList.build((final b) {
3125
for (final property in schema.properties!.entries) {
32-
b.methods.add(
26+
b.add(
3327
Method(
3428
(final b) {
3529
final propertyName = property.key;
@@ -62,29 +56,38 @@ TypeResultObject resolveInterface(
6256
),
6357
);
6458
}
65-
66-
b.methods.addAll([
67-
Method(
68-
(final b) => b
69-
..returns = refer(className)
70-
..name = 'rebuild'
71-
..requiredParameters.add(
72-
Parameter(
73-
(final b) => b
74-
..name = 'updates'
75-
..type = refer('void Function(${className}Builder)'),
76-
),
77-
),
78-
),
79-
Method(
80-
(final b) => b
81-
..returns = refer('${className}Builder')
82-
..name = 'toBuilder',
83-
),
84-
]);
8559
}),
8660
);
61+
62+
state.output.add($interface);
8763
}
8864

8965
return result;
9066
}
67+
68+
Spec buildInterface(
69+
final String identifier, {
70+
final BuiltList<Method>? methods,
71+
final Iterable<TypeResultObject>? interfaces,
72+
}) {
73+
assert((interfaces == null) != (methods == null), 'Either provide an interface or methods.');
74+
final className = '$identifier$interfaceSuffix';
75+
76+
return Class((final b) {
77+
b
78+
..abstract = true
79+
..modifier = ClassModifier.interface
80+
..name = className
81+
..annotations.add(refer('BuiltValue').call([], {'instantiable': literalFalse}));
82+
83+
if (interfaces != null) {
84+
b.implements.addAll(
85+
interfaces.map((final i) => refer('${i.name}$interfaceSuffix')),
86+
);
87+
}
88+
89+
if (methods != null) {
90+
b.methods.addAll(methods);
91+
}
92+
});
93+
}

packages/dynamite/dynamite/lib/src/builder/resolve_object.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,21 @@ TypeResultObject resolveObject(
3636
}
3737
}
3838

39-
final interfaceClass = resolveInterface(
39+
resolveInterface(
4040
spec,
4141
state,
4242
identifier,
4343
schema,
4444
);
4545

46-
state.output.addAll([
46+
state.output.add(
4747
buildBuiltClass(
4848
identifier,
4949
defaults: defaults,
5050
customSerializer: isHeader,
51-
interfaces: [
52-
interfaceClass,
53-
],
5451
),
55-
]);
52+
);
53+
5654
if (isHeader) {
5755
state.output.add(buildHeaderSerializer(state, identifier, spec, schema));
5856
}

packages/dynamite/dynamite/lib/src/helpers/built_value.dart

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,68 @@
1-
import 'package:built_collection/built_collection.dart';
21
import 'package:code_builder/code_builder.dart';
32
import 'package:dynamite/src/helpers/dart_helpers.dart';
4-
import 'package:dynamite/src/models/type_result.dart';
53

64
const interfaceSuffix = 'Interface';
75

6+
/// Builds a [Class] representing a built_value object.
7+
///
8+
/// Attributes must be defined in a separate interface called `$className$interfaceSuffix`.
89
Spec buildBuiltClass(
910
final String className, {
10-
final BuiltList<Method>? methods,
1111
final Iterable<String>? defaults,
12-
final Iterable<TypeResultObject>? interfaces,
1312
final bool customSerializer = false,
14-
}) {
15-
assert((interfaces == null) != (methods == null), 'Either provide an interface or methods.');
13+
}) =>
14+
Class(
15+
(final b) {
16+
b
17+
..name = className
18+
..abstract = true
19+
..implements.addAll([
20+
refer('$className$interfaceSuffix'),
21+
refer(
22+
'Built<$className, ${className}Builder>',
23+
),
24+
])
25+
..constructors.addAll([
26+
builtValueConstructor(className),
27+
hiddenConstructor,
28+
fromJsonConstructor,
29+
])
30+
..methods.addAll([
31+
toJsonMethod,
32+
buildSerializer(className, isCustom: customSerializer),
33+
]);
1634

17-
return Class(
18-
(final b) {
19-
b
20-
..name = className
21-
..abstract = true
22-
..implements.addAll([
23-
...?interfaces?.map((final i) => refer('${i.name}$interfaceSuffix')),
24-
refer(
25-
'Built<$className, ${className}Builder>',
26-
),
27-
])
28-
..constructors.addAll([
29-
builtValueConstructor(className),
30-
hiddenConstructor,
31-
fromJsonConstructor,
32-
])
33-
..methods.addAll([
34-
toJsonMethod,
35-
...?methods,
36-
buildSerializer(className, isCustom: customSerializer),
37-
]);
38-
39-
if (defaults != null && defaults.isNotEmpty) {
40-
b.methods.add(
41-
Method(
42-
(final b) => b
43-
..name = '_defaults'
44-
..returns = refer('void')
45-
..static = true
46-
..lambda = true
47-
..annotations.add(
48-
refer('BuiltValueHook').call([], {
49-
'initializeBuilder': literalTrue,
50-
}),
51-
)
52-
..requiredParameters.add(
53-
Parameter(
54-
(final b) => b
55-
..name = 'b'
56-
..type = refer('${className}Builder'),
35+
if (defaults != null && defaults.isNotEmpty) {
36+
b.methods.add(
37+
Method(
38+
(final b) => b
39+
..name = '_defaults'
40+
..returns = refer('void')
41+
..static = true
42+
..lambda = true
43+
..annotations.add(
44+
refer('BuiltValueHook').call([], {
45+
'initializeBuilder': literalTrue,
46+
}),
47+
)
48+
..requiredParameters.add(
49+
Parameter(
50+
(final b) => b
51+
..name = 'b'
52+
..type = refer('${className}Builder'),
53+
),
54+
)
55+
..body = Code(
56+
<String?>[
57+
'b',
58+
...defaults,
59+
].join(),
5760
),
58-
)
59-
..body = Code(
60-
<String?>[
61-
'b',
62-
...defaults,
63-
].join(),
64-
),
65-
),
66-
);
67-
}
68-
},
69-
);
70-
}
61+
),
62+
);
63+
}
64+
},
65+
);
7166

7267
Method get toJsonMethod => Method(
7368
(final b) => b

packages/nextcloud/lib/src/api/comments.openapi.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class Client extends DynamiteClient {
3434
@BuiltValue(instantiable: false)
3535
abstract interface class Capabilities_FilesInterface {
3636
bool get comments;
37-
Capabilities_FilesInterface rebuild(final void Function(Capabilities_FilesInterfaceBuilder) updates);
38-
Capabilities_FilesInterfaceBuilder toBuilder();
3937
}
4038

4139
abstract class Capabilities_Files
@@ -61,8 +59,6 @@ abstract class Capabilities_Files
6159
@BuiltValue(instantiable: false)
6260
abstract interface class CapabilitiesInterface {
6361
Capabilities_Files get files;
64-
CapabilitiesInterface rebuild(final void Function(CapabilitiesInterfaceBuilder) updates);
65-
CapabilitiesInterfaceBuilder toBuilder();
6662
}
6763

6864
abstract class Capabilities implements CapabilitiesInterface, Built<Capabilities, CapabilitiesBuilder> {

0 commit comments

Comments
 (0)