Skip to content

Commit

Permalink
Merge pull request #1420 from nextcloud/perf/dynamite/tagged-clients
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin authored Jan 3, 2024
2 parents 922a6e2 + 1c8f0b5 commit a5002e6
Show file tree
Hide file tree
Showing 21 changed files with 281 additions and 82 deletions.
12 changes: 6 additions & 6 deletions packages/dynamite/dynamite/lib/src/builder/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ super(
for (final tag in tags) {
final client = clientName(tag.name);

b.methods.add(
Method(
b.fields.add(
Field(
(b) => b
..docs.addAll(tag.formattedDescription)
..name = toDartName(tag.name)
..lambda = true
..type = MethodType.getter
..returns = refer(client)
..body = Code('$client(this)'),
..late = true
..modifier = FieldModifier.final$
..type = refer(client)
..assignment = Code('$client(this)'),
),
);
}
Expand Down
162 changes: 162 additions & 0 deletions packages/dynamite/dynamite_end_to_end_test/lib/tags.openapi.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// OpenAPI client generated by Dynamite. Do not manually edit this file.

// ignore_for_file: camel_case_extensions, camel_case_types, discarded_futures
// ignore_for_file: no_leading_underscores_for_local_identifiers
// ignore_for_file: public_member_api_docs, unreachable_switch_case
// ignore_for_file: unused_element

// ignore_for_file: no_leading_underscores_for_library_prefixes

import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart' as _i4;
import 'package:dynamite_runtime/built_value.dart' as _i3;
import 'package:dynamite_runtime/http_client.dart' as _i1;
import 'package:meta/meta.dart' as _i2;

class $Client extends _i1.DynamiteClient {
/// Creates a new `DynamiteClient` for untagged requests.
$Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

/// Creates a new [$Client] from another [client].
$Client.fromClient(_i1.DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);

late final $FirstClient first = $FirstClient(this);

late final $SecondClient second = $SecondClient(this);
}

class $FirstClient {
/// Creates a new `DynamiteClient` for first requests.
$FirstClient(this._rootClient);

final $Client _rootClient;

/// Returns a [Future] containing a `DynamiteResponse` with the status code, deserialized body and headers.
/// Throws a `DynamiteApiException` if the API call does not return an expected status code.
///
/// Status codes:
/// * default
///
/// See:
/// * [$getRaw] for an experimental operation that returns a `DynamiteRawResponse` that can be serialized.
Future<_i1.DynamiteResponse<void, void>> $get() async {
final rawResponse = $getRaw();

return rawResponse.future;
}

/// This method and the response it returns is experimental. The API might change without a major version bump.
///
/// Returns a [Future] containing a `DynamiteRawResponse` with the raw `HttpClientResponse` and serialization helpers.
/// Throws a `DynamiteApiException` if the API call does not return an expected status code.
///
/// Status codes:
/// * default
///
/// See:
/// * [$get] for an operation that returns a `DynamiteResponse` with a stable API.
@_i2.experimental
_i1.DynamiteRawResponse<void, void> $getRaw() {
final _headers = <String, String>{};

const _path = '/';
return _i1.DynamiteRawResponse<void, void>(
response: _rootClient.executeRequest(
'get',
_path,
_headers,
null,
null,
),
bodyType: null,
headersType: null,
serializers: _$jsonSerializers,
);
}
}

class $SecondClient {
/// Creates a new `DynamiteClient` for second requests.
$SecondClient(this._rootClient);

final $Client _rootClient;

/// Returns a [Future] containing a `DynamiteResponse` with the status code, deserialized body and headers.
/// Throws a `DynamiteApiException` if the API call does not return an expected status code.
///
/// Status codes:
/// * default
///
/// See:
/// * [$getRaw] for an experimental operation that returns a `DynamiteRawResponse` that can be serialized.
Future<_i1.DynamiteResponse<void, void>> $get() async {
final rawResponse = $getRaw();

return rawResponse.future;
}

/// This method and the response it returns is experimental. The API might change without a major version bump.
///
/// Returns a [Future] containing a `DynamiteRawResponse` with the raw `HttpClientResponse` and serialization helpers.
/// Throws a `DynamiteApiException` if the API call does not return an expected status code.
///
/// Status codes:
/// * default
///
/// See:
/// * [$get] for an operation that returns a `DynamiteResponse` with a stable API.
@_i2.experimental
_i1.DynamiteRawResponse<void, void> $getRaw() {
final _headers = <String, String>{};

const _path = '/';
return _i1.DynamiteRawResponse<void, void>(
response: _rootClient.executeRequest(
'get',
_path,
_headers,
null,
null,
),
bodyType: null,
headersType: null,
serializers: _$jsonSerializers,
);
}
}

// coverage:ignore-start
/// Serializer for all values in this library.
///
/// Serializes values into the `built_value` wire format.
/// See: [$jsonSerializers] for serializing into json.
@_i2.visibleForTesting
final Serializers $serializers = _$serializers;
final Serializers _$serializers = Serializers();

/// Serializer for all values in this library.
///
/// Serializes values into the json. Json serialization is more expensive than the built_value wire format.
/// See: [$serializers] for serializing into the `built_value` wire format.
@_i2.visibleForTesting
final Serializers $jsonSerializers = _$jsonSerializers;
final Serializers _$jsonSerializers = (_$serializers.toBuilder()
..add(_i3.DynamiteDoubleSerializer())
..addPlugin(_i4.StandardJsonPlugin())
..addPlugin(const _i3.HeaderPlugin())
..addPlugin(const _i3.ContentStringPlugin()))
.build();
// coverage:ignore-end
22 changes: 22 additions & 0 deletions packages/dynamite/dynamite_end_to_end_test/lib/tags.openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"openapi": "3.1.0",
"info": {
"title": "Tags test",
"version": "0.0.1"
},
"paths": {
"/": {
"get": {
"tags": [
"first",
"second"
],
"responses": {
"default": {
"description": ""
}
}
}
}
}
}
15 changes: 15 additions & 0 deletions packages/dynamite/dynamite_end_to_end_test/test/tags_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:dynamite_end_to_end_test/tags.openapi.dart';
import 'package:test/expect.dart';
import 'package:test/scaffolding.dart';

void main() {
test('Nested clients', () {
final client = $Client(Uri());

expect(client.first, isA<$FirstClient>());
expect(identical(client.first, client.first), isTrue);

expect(client.second, isA<$SecondClient>());
expect(identical(client.second, client.second), isTrue);
});
}
40 changes: 20 additions & 20 deletions packages/nextcloud/lib/src/api/core.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,48 +43,48 @@ class $Client extends _i1.DynamiteClient {
authentications: client.authentications,
);

$AppPasswordClient get appPassword => $AppPasswordClient(this);
late final $AppPasswordClient appPassword = $AppPasswordClient(this);

$AutoCompleteClient get autoComplete => $AutoCompleteClient(this);
late final $AutoCompleteClient autoComplete = $AutoCompleteClient(this);

/// Class AvatarController.
$AvatarClient get avatar => $AvatarClient(this);
late final $AvatarClient avatar = $AvatarClient(this);

$ClientFlowLoginV2Client get clientFlowLoginV2 => $ClientFlowLoginV2Client(this);
late final $ClientFlowLoginV2Client clientFlowLoginV2 = $ClientFlowLoginV2Client(this);

$CollaborationResourcesClient get collaborationResources => $CollaborationResourcesClient(this);
late final $CollaborationResourcesClient collaborationResources = $CollaborationResourcesClient(this);

/// This controller handles guest avatar requests.
$GuestAvatarClient get guestAvatar => $GuestAvatarClient(this);
late final $GuestAvatarClient guestAvatar = $GuestAvatarClient(this);

$HoverCardClient get hoverCard => $HoverCardClient(this);
late final $HoverCardClient hoverCard = $HoverCardClient(this);

$NavigationClient get navigation => $NavigationClient(this);
late final $NavigationClient navigation = $NavigationClient(this);

/// Controller about the endpoint /ocm-provider/.
$OcmClient get ocm => $OcmClient(this);
late final $OcmClient ocm = $OcmClient(this);

$OcsClient get ocs => $OcsClient(this);
late final $OcsClient ocs = $OcsClient(this);

$PreviewClient get preview => $PreviewClient(this);
late final $PreviewClient preview = $PreviewClient(this);

$ProfileApiClient get profileApi => $ProfileApiClient(this);
late final $ProfileApiClient profileApi = $ProfileApiClient(this);

$ReferenceClient get reference => $ReferenceClient(this);
late final $ReferenceClient reference = $ReferenceClient(this);

$ReferenceApiClient get referenceApi => $ReferenceApiClient(this);
late final $ReferenceApiClient referenceApi = $ReferenceApiClient(this);

$TextProcessingApiClient get textProcessingApi => $TextProcessingApiClient(this);
late final $TextProcessingApiClient textProcessingApi = $TextProcessingApiClient(this);

$TextToImageApiClient get textToImageApi => $TextToImageApiClient(this);
late final $TextToImageApiClient textToImageApi = $TextToImageApiClient(this);

$TranslationApiClient get translationApi => $TranslationApiClient(this);
late final $TranslationApiClient translationApi = $TranslationApiClient(this);

$UnifiedSearchClient get unifiedSearch => $UnifiedSearchClient(this);
late final $UnifiedSearchClient unifiedSearch = $UnifiedSearchClient(this);

$WhatsNewClient get whatsNew => $WhatsNewClient(this);
late final $WhatsNewClient whatsNew = $WhatsNewClient(this);

$WipeClient get wipe => $WipeClient(this);
late final $WipeClient wipe = $WipeClient(this);

/// Returns a [Future] containing a `DynamiteResponse` with the status code, deserialized body and headers.
/// Throws a `DynamiteApiException` if the API call does not return an expected status code.
Expand Down
2 changes: 1 addition & 1 deletion packages/nextcloud/lib/src/api/dashboard.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class $Client extends _i1.DynamiteClient {
authentications: client.authentications,
);

$DashboardApiClient get dashboardApi => $DashboardApiClient(this);
late final $DashboardApiClient dashboardApi = $DashboardApiClient(this);
}

class $DashboardApiClient {
Expand Down
4 changes: 2 additions & 2 deletions packages/nextcloud/lib/src/api/dav.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class $Client extends _i1.DynamiteClient {
authentications: client.authentications,
);

$DirectClient get direct => $DirectClient(this);
late final $DirectClient direct = $DirectClient(this);

$OutOfOfficeClient get outOfOffice => $OutOfOfficeClient(this);
late final $OutOfOfficeClient outOfOffice = $OutOfOfficeClient(this);
}

class $DirectClient {
Expand Down
10 changes: 5 additions & 5 deletions packages/nextcloud/lib/src/api/files.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class $Client extends _i1.DynamiteClient {
authentications: client.authentications,
);

$ApiClient get api => $ApiClient(this);
late final $ApiClient api = $ApiClient(this);

$DirectEditingClient get directEditing => $DirectEditingClient(this);
late final $DirectEditingClient directEditing = $DirectEditingClient(this);

$OpenLocalEditorClient get openLocalEditor => $OpenLocalEditorClient(this);
late final $OpenLocalEditorClient openLocalEditor = $OpenLocalEditorClient(this);

$TemplateClient get template => $TemplateClient(this);
late final $TemplateClient template = $TemplateClient(this);

$TransferOwnershipClient get transferOwnership => $TransferOwnershipClient(this);
late final $TransferOwnershipClient transferOwnership = $TransferOwnershipClient(this);
}

class $ApiClient {
Expand Down
2 changes: 1 addition & 1 deletion packages/nextcloud/lib/src/api/files_external.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class $Client extends _i1.DynamiteClient {
authentications: client.authentications,
);

$ApiClient get api => $ApiClient(this);
late final $ApiClient api = $ApiClient(this);
}

class $ApiClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class $Client extends _i1.DynamiteClient {
authentications: client.authentications,
);

$ApiClient get api => $ApiClient(this);
late final $ApiClient api = $ApiClient(this);
}

class $ApiClient {
Expand Down
12 changes: 6 additions & 6 deletions packages/nextcloud/lib/src/api/files_sharing.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ class $Client extends _i1.DynamiteClient {
authentications: client.authentications,
);

$DeletedShareapiClient get deletedShareapi => $DeletedShareapiClient(this);
late final $DeletedShareapiClient deletedShareapi = $DeletedShareapiClient(this);

$PublicPreviewClient get publicPreview => $PublicPreviewClient(this);
late final $PublicPreviewClient publicPreview = $PublicPreviewClient(this);

$RemoteClient get remote => $RemoteClient(this);
late final $RemoteClient remote = $RemoteClient(this);

$ShareInfoClient get shareInfo => $ShareInfoClient(this);
late final $ShareInfoClient shareInfo = $ShareInfoClient(this);

$ShareapiClient get shareapi => $ShareapiClient(this);
late final $ShareapiClient shareapi = $ShareapiClient(this);

$ShareesapiClient get shareesapi => $ShareesapiClient(this);
late final $ShareesapiClient shareesapi = $ShareesapiClient(this);
}

class $DeletedShareapiClient {
Expand Down
2 changes: 1 addition & 1 deletion packages/nextcloud/lib/src/api/files_trashbin.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class $Client extends _i1.DynamiteClient {
authentications: client.authentications,
);

$PreviewClient get preview => $PreviewClient(this);
late final $PreviewClient preview = $PreviewClient(this);
}

class $PreviewClient {
Expand Down
2 changes: 1 addition & 1 deletion packages/nextcloud/lib/src/api/files_versions.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class $Client extends _i1.DynamiteClient {
authentications: client.authentications,
);

$PreviewClient get preview => $PreviewClient(this);
late final $PreviewClient preview = $PreviewClient(this);
}

class $PreviewClient {
Expand Down
Loading

0 comments on commit a5002e6

Please sign in to comment.