Skip to content

Commit

Permalink
refactor(dynamite): do not generate Clients when not needed
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolas Rimikis <[email protected]>
  • Loading branch information
Leptopoda committed Dec 19, 2023
1 parent 297766f commit 3e45cc2
Show file tree
Hide file tree
Showing 16 changed files with 9 additions and 266 deletions.
4 changes: 4 additions & 0 deletions packages/dynamite/dynamite/lib/src/builder/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Iterable<Class> generateClients(
final openapi.OpenAPI spec,
final State state,
) sync* {
if (spec.paths == null || spec.paths!.isEmpty) {
return;
}

final tags = generateTags(spec);
yield buildRootClient(spec, state, tags);

Expand Down
20 changes: 0 additions & 20 deletions packages/dynamite/dynamite_end_to_end_test/lib/all_of.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,10 @@ import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:meta/meta.dart';

part 'all_of.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

@BuiltValue(instantiable: false)
abstract interface class $ObjectAllOf_0Interface {
@BuiltValueField(wireName: 'attribute1-allOf')
Expand Down
20 changes: 0 additions & 20 deletions packages/dynamite/dynamite_end_to_end_test/lib/any_of.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,11 @@ import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:dynamite_runtime/utils.dart' as dynamite_utils;
import 'package:meta/meta.dart';

part 'any_of.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

typedef OneObjectAnyOf = OneObjectAnyOf0;

typedef OneValueAnyOf = String;
Expand Down
20 changes: 0 additions & 20 deletions packages/dynamite/dynamite_end_to_end_test/lib/enum.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,10 @@ import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:meta/meta.dart';

part 'enum.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

class EnumString extends EnumClass {
const EnumString._(super.name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,10 @@ import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:meta/meta.dart';

part 'interfaces.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

@BuiltValue(instantiable: false)
abstract interface class $BaseInterface {
String? get attribute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,11 @@ import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:dynamite_runtime/utils.dart' as dynamite_utils;
import 'package:meta/meta.dart';

part 'nested_ofs.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

@BuiltValue(instantiable: false)
abstract interface class $BaseAllOf_1Interface {
@BuiltValueField(wireName: 'attribute-allOf')
Expand Down
20 changes: 0 additions & 20 deletions packages/dynamite/dynamite_end_to_end_test/lib/one_of.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,11 @@ import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:dynamite_runtime/utils.dart' as dynamite_utils;
import 'package:meta/meta.dart';

part 'one_of.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

typedef OneObjectOneOf = OneObjectOneOf0;

typedef OneValueOneOf = String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,11 @@ import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:dynamite_runtime/utils.dart' as dynamite_utils;
import 'package:meta/meta.dart';

part 'pattern_check.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

@BuiltValue(instantiable: false)
abstract interface class $TestObjectInterface {
@BuiltValueField(wireName: 'only-numbers')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,11 @@ import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:dynamite_runtime/utils.dart' as dynamite_utils;
import 'package:meta/meta.dart';

part 'some_of.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

@BuiltValue(instantiable: false)
abstract interface class $OneValueSomeOfInObjectInterface {
@BuiltValueField(wireName: 'OneValue')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,11 @@ import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:dynamite_runtime/utils.dart' as dynamite_utils;
import 'package:meta/meta.dart';

part 'type_defs.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

typedef TypeResultBase = int;

typedef EmptySchema = dynamic;
Expand Down
20 changes: 0 additions & 20 deletions packages/dynamite/dynamite_end_to_end_test/lib/types.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,11 @@ import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:dynamite_runtime/models.dart';
import 'package:meta/meta.dart';

part 'types.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

typedef $Object = dynamic;

typedef $String = dynamic;
Expand Down
5 changes: 5 additions & 0 deletions packages/nextcloud/bin/generate_exports.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ void main() {
exports.add("export 'src/helpers/$id.dart';");
}

if (!file.readAsStringSync().contains('class Client extends DynamiteClient {')) {
File('lib/$id.dart').writeAsStringSync(exports.join('\n'));
continue;
}

File('lib/$id.dart').writeAsStringSync('''
// coverage:ignore-file
import 'package:nextcloud/src/api/$id.openapi.dart';
Expand Down
12 changes: 0 additions & 12 deletions packages/nextcloud/lib/comments.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
// coverage:ignore-file
import 'package:nextcloud/src/api/comments.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/comments.openapi.dart';

// ignore: public_member_api_docs
extension CommentsExtension on NextcloudClient {
static final _comments = Expando<Client>();

/// Client for the comments APIs
Client get comments => _comments[this] ??= Client.fromClient(this);
}
12 changes: 0 additions & 12 deletions packages/nextcloud/lib/sharebymail.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
// coverage:ignore-file
import 'package:nextcloud/src/api/sharebymail.openapi.dart';
import 'package:nextcloud/src/client.dart';

export 'src/api/sharebymail.openapi.dart';

// ignore: public_member_api_docs
extension SharebymailExtension on NextcloudClient {
static final _sharebymail = Expando<Client>();

/// Client for the sharebymail APIs
Client get sharebymail => _sharebymail[this] ??= Client.fromClient(this);
}
21 changes: 0 additions & 21 deletions packages/nextcloud/lib/src/api/comments.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,10 @@ import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';
import 'package:meta/meta.dart';

part 'comments.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
super.authentications,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

@BuiltValue(instantiable: false)
abstract interface class $Capabilities_FilesInterface {
bool get comments;
Expand Down
Loading

0 comments on commit 3e45cc2

Please sign in to comment.