Skip to content

Commit 0a357a7

Browse files
authored
feat: Mark APIs that return operations with @discardableResult (#633)
refs:#628
1 parent bfd8281 commit 0a357a7

File tree

8 files changed

+41
-1
lines changed

8 files changed

+41
-1
lines changed

Amplify/Categories/API/ClientBehavior/APICategoryGraphQLBehavior.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public protocol APICategoryGraphQLBehavior: class {
1717
/// - request: The GraphQL request containing apiName, document, variables, and responseType
1818
/// - listener: The event listener for the operation
1919
/// - Returns: The AmplifyOperation being enqueued
20+
@discardableResult
2021
func query<R: Decodable>(request: GraphQLRequest<R>,
2122
listener: GraphQLOperation<R>.ResultListener?) -> GraphQLOperation<R>
2223

@@ -27,6 +28,7 @@ public protocol APICategoryGraphQLBehavior: class {
2728
/// - request: The GraphQL request containing apiName, document, variables, and responseType
2829
/// - listener: The event listener for the operation
2930
/// - Returns: The AmplifyOperation being enqueued
31+
@discardableResult
3032
func mutate<R: Decodable>(request: GraphQLRequest<R>,
3133
listener: GraphQLOperation<R>.ResultListener?) -> GraphQLOperation<R>
3234

Amplify/Categories/API/ClientBehavior/APICategoryRESTBehavior.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,41 @@ public protocol APICategoryRESTBehavior {
1414
///
1515
/// - Parameter request: Contains information such as path, query parameters, body.
1616
/// - Returns: An operation that can be observed for its value
17+
@discardableResult
1718
func get(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation
1819

1920
/// Perform an HTTP PUT operation
2021
///
2122
/// - Parameter request: Contains information such as path, query parameters, body.
2223
/// - Returns: An operation that can be observed for its value
24+
@discardableResult
2325
func put(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation
2426

2527
/// Perform an HTTP POST operation
2628
///
2729
/// - Parameter request: Contains information such as path, query parameters, body.
2830
/// - Returns: An operation that can be observed for its value
31+
@discardableResult
2932
func post(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation
3033

3134
/// Perform an HTTP DELETE operation
3235
///
3336
/// - Parameter request: Contains information such as path, query parameters, body.
3437
/// - Returns: An operation that can be observed for its value
38+
@discardableResult
3539
func delete(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation
3640

3741
/// Perform an HTTP HEAD operation
3842
///
3943
/// - Parameter request: Contains information such as path, query parameters, body.
4044
/// - Returns: An operation that can be observed for its value
45+
@discardableResult
4146
func head(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation
4247

4348
/// Perform an HTTP PATCH operation
4449
///
4550
/// - Parameter request: Contains information such as path, query parameters, body.
4651
/// - Returns: An operation that can be observed for its value
52+
@discardableResult
4753
func patch(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation
4854
}

Amplify/Categories/Auth/AuthCategoryBehavior.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
2424
/// - password: password as per the password policy of the provider
2525
/// - options: Parameters specific to plugin behavior
2626
/// - listener: Triggered when the operation completes.
27+
@discardableResult
2728
func signUp(username: String,
2829
password: String?,
2930
options: AuthSignUpOperation.Request.Options?,
@@ -39,6 +40,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
3940
/// - confirmationCode: Confirmation code received to the user.
4041
/// - options: Parameters specific to plugin behavior
4142
/// - listener: Triggered when the operation completes.
43+
@discardableResult
4244
func confirmSignUp(for username: String,
4345
confirmationCode: String,
4446
options: AuthConfirmSignUpOperation.Request.Options?,
@@ -50,6 +52,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
5052
/// - username: Username of the user to be confirmed.
5153
/// - options: Parameters specific to plugin behavior.
5254
/// - listener: Triggered when the operation completes.
55+
@discardableResult
5356
func resendSignUpCode(for username: String,
5457
options: AuthResendSignUpCodeOperation.Request.Options?,
5558
listener: AuthResendSignUpCodeOperation.ResultListener?) -> AuthResendSignUpCodeOperation
@@ -64,6 +67,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
6467
/// - password: Password to signIn the user
6568
/// - options: Parameters specific to plugin behavior
6669
/// - listener: Triggered when the operation completes.
70+
@discardableResult
6771
func signIn(username: String?,
6872
password: String?,
6973
options: AuthSignInOperation.Request.Options?,
@@ -77,6 +81,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
7781
/// - presentationAnchor: Anchor on which the UI is presented.
7882
/// - options: Parameters specific to plugin behavior.
7983
/// - listener: Triggered when the operation completes.
84+
@discardableResult
8085
func signInWithWebUI(presentationAnchor: AuthUIPresentationAnchor,
8186
options: AuthWebUISignInOperation.Request.Options?,
8287
listener: AuthWebUISignInOperation.ResultListener?) -> AuthWebUISignInOperation
@@ -92,6 +97,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
9297
/// - presentationAnchor: Anchor on which the UI is presented.
9398
/// - options: Parameters specific to plugin behavior.
9499
/// - listener: Triggered when the operation completes.
100+
@discardableResult
95101
func signInWithWebUI(for authProvider: AuthProvider,
96102
presentationAnchor: AuthUIPresentationAnchor,
97103
options: AuthSocialWebUISignInOperation.Request.Options?,
@@ -103,10 +109,12 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
103109
/// - challengeResponse: Challenge response required to confirm the next step in signIn flow
104110
/// - options: Parameters specific to plugin behavior.
105111
/// - listener: Triggered when the operation completes.
112+
@discardableResult
106113
func confirmSignIn(challengeResponse: String,
107114
options: AuthConfirmSignInOperation.Request.Options?,
108115
listener: AuthConfirmSignInOperation.ResultListener?) -> AuthConfirmSignInOperation
109116

117+
@discardableResult
110118
func signOut(options: AuthSignOutOperation.Request.Options?,
111119
listener: AuthSignOutOperation.ResultListener?) -> AuthSignOutOperation
112120

@@ -115,6 +123,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
115123
/// - Parameters:
116124
/// - options: Parameters specific to plugin behavior
117125
/// - listener: Triggered when the operation completes.
126+
@discardableResult
118127
func fetchAuthSession(options: AuthFetchSessionOperation.Request.Options?,
119128
listener: AuthFetchSessionOperation.ResultListener?) -> AuthFetchSessionOperation
120129

@@ -124,6 +133,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
124133
/// - username: username whose password need to reset
125134
/// - options: Parameters specific to plugin behavior
126135
/// - listener: Triggered when the operation completes
136+
@discardableResult
127137
func resetPassword(for username: String,
128138
options: AuthResetPasswordOperation.Request.Options?,
129139
listener: AuthResetPasswordOperation.ResultListener?) -> AuthResetPasswordOperation
@@ -136,6 +146,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
136146
/// - confirmationCode: Received confirmation code
137147
/// - options: Parameters specific to plugin behavior
138148
/// - listener: Triggered when the operation completes
149+
@discardableResult
139150
func confirmResetPassword(for username: String,
140151
with newPassword: String,
141152
confirmationCode: String,

Amplify/Categories/Auth/AuthCategoryDeviceBehavior.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public protocol AuthCategoryDeviceBehavior: class {
1313
/// - Parameters:
1414
/// - options: Parameters specific to plugin behavior.
1515
/// - listener: Triggered when the operation completes.
16+
@discardableResult
1617
func fetchDevices(
1718
options: AuthFetchDevicesOperation.Request.Options?,
1819
listener: AuthFetchDevicesOperation.ResultListener?) -> AuthFetchDevicesOperation
@@ -23,6 +24,7 @@ public protocol AuthCategoryDeviceBehavior: class {
2324
/// - authDevice: Device to be forgotten
2425
/// - options: Parameters specific to plugin behavior.
2526
/// - listener: Triggered when the operation completes.
27+
@discardableResult
2628
func forgetDevice(
2729
_ device: AuthDevice?,
2830
options: AuthForgetDeviceOperation.Request.Options?,
@@ -33,6 +35,7 @@ public protocol AuthCategoryDeviceBehavior: class {
3335
/// - Parameters:
3436
/// - options: Parameters specific to plugin behavior.
3537
/// - listener: Triggered when the operation completes.
38+
@discardableResult
3639
func rememberDevice(
3740
options: AuthRememberDeviceOperation.Request.Options?,
3841
listener: AuthRememberDeviceOperation.ResultListener?) -> AuthRememberDeviceOperation

Amplify/Categories/Auth/AuthCategoryUserBehavior.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public protocol AuthCategoryUserBehavior: class {
1818
/// - Parameters:
1919
/// - options: Parameters specific to plugin behavior
2020
/// - listener: Triggered when the operation completes.
21+
@discardableResult
2122
func fetchUserAttributes(options: AuthFetchUserAttributeOperation.Request.Options?,
2223
listener: AuthFetchUserAttributeOperation.ResultListener?)
2324
-> AuthFetchUserAttributeOperation
@@ -28,6 +29,7 @@ public protocol AuthCategoryUserBehavior: class {
2829
/// - userAttribute: Attribute that need to be updated
2930
/// - options: Parameters specific to plugin behavior
3031
/// - listener: Triggered when the operation completes.
32+
@discardableResult
3133
func update(userAttribute: AuthUserAttribute,
3234
options: AuthUpdateUserAttributeOperation.Request.Options?,
3335
listener: AuthUpdateUserAttributeOperation.ResultListener?) -> AuthUpdateUserAttributeOperation
@@ -38,6 +40,7 @@ public protocol AuthCategoryUserBehavior: class {
3840
/// - userAttributes: List of attribtues that need ot be updated
3941
/// - options: Parameters specific to plugin behavior
4042
/// - listener: Triggered when the operation completes.
43+
@discardableResult
4144
func update(userAttributes: [AuthUserAttribute],
4245
options: AuthUpdateUserAttributesOperation.Request.Options?,
4346
listener: AuthUpdateUserAttributesOperation.ResultListener?) -> AuthUpdateUserAttributesOperation
@@ -48,6 +51,7 @@ public protocol AuthCategoryUserBehavior: class {
4851
/// - attributeKey: Attribute to be verified
4952
/// - options: Parameters specific to plugin behavior
5053
/// - listener: Triggered when the operation completes.
54+
@discardableResult
5155
func resendConfirmationCode(for attributeKey: AuthUserAttributeKey,
5256
options: AuthAttributeResendConfirmationCodeOperation.Request.Options?,
5357
listener: AuthAttributeResendConfirmationCodeOperation.ResultListener?)
@@ -60,6 +64,7 @@ public protocol AuthCategoryUserBehavior: class {
6064
/// - confirmationCode: Confirmation code received
6165
/// - options: Parameters specific to plugin behavior
6266
/// - listener: Triggered when the operation completes.
67+
@discardableResult
6368
func confirm(userAttribute: AuthUserAttributeKey,
6469
confirmationCode: String,
6570
options: AuthConfirmUserAttributeOperation.Request.Options?,
@@ -73,6 +78,7 @@ public protocol AuthCategoryUserBehavior: class {
7378
/// - newPassword: New password to be updated
7479
/// - options: Parameters specific to plugin behavior
7580
/// - listener: Triggered when the operation completes.
81+
@discardableResult
7682
func update(oldPassword: String,
7783
to newPassword: String,
7884
options: AuthChangePasswordOperation.Request.Options?,

Amplify/Categories/Predictions/PredictionsCategoryBehavior.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public protocol PredictionsCategoryBehavior {
1616
/// - Parameter targetLanguage: The language to which the text should be translated
1717
/// - Parameter options: Parameters to specific plugin behavior
1818
/// - Parameter listener: Triggered when the event occurs
19+
@discardableResult
1920
func convert(textToTranslate: String,
2021
language: LanguageType?,
2122
targetLanguage: LanguageType?,
@@ -25,13 +26,15 @@ public protocol PredictionsCategoryBehavior {
2526
/// - Parameter textToSpeech: The text to be synthesized to audio
2627
/// - Parameter listener: Triggered when the event occurs
2728
/// - Parameter options: Parameters to specific plugin behavior
29+
@discardableResult
2830
func convert(textToSpeech: String,
2931
options: PredictionsTextToSpeechRequest.Options?,
3032
listener: PredictionsTextToSpeechOperation.ResultListener?) -> PredictionsTextToSpeechOperation
3133

3234
/// - Parameter speechToText: The url of the audio to be transcribed
3335
/// - Parameter listener: Triggered when the event occurs
3436
/// - Parameter options: Parameters to specific plugin behavior
37+
@discardableResult
3538
func convert(speechToText: URL,
3639
options: PredictionsSpeechToTextRequest.Options?,
3740
listener: PredictionsSpeechToTextOperation.ResultListener?) -> PredictionsSpeechToTextOperation
@@ -41,6 +44,7 @@ public protocol PredictionsCategoryBehavior {
4144
/// - Parameter image: The image you are sending
4245
/// - Parameter options: Parameters to specific plugin behavior
4346
/// - Parameter listener: Triggered when the event occurs
47+
@discardableResult
4448
func identify(type: IdentifyAction,
4549
image: URL,
4650
options: PredictionsIdentifyRequest.Options?,
@@ -51,6 +55,7 @@ public protocol PredictionsCategoryBehavior {
5155
/// - Parameter text: Text to interpret
5256
/// - Parameter options:Parameters to specific plugin behavior
5357
/// - Parameter options:Parameters to specific plugin behavior
58+
@discardableResult
5459
func interpret(text: String,
5560
options: PredictionsInterpretRequest.Options?,
5661
listener: PredictionsInterpretOperation.ResultListener?) -> PredictionsInterpretOperation

Amplify/Categories/Storage/StorageCategoryBehavior.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public protocol StorageCategoryBehavior {
1616
/// - options: Parameters to specific plugin behavior
1717
/// - resultListener: Triggered when the operation is complete
1818
/// - Returns: An operation object that provides notifications and actions related to the execution of the work
19+
@discardableResult
1920
func getURL(key: String,
2021
options: StorageGetURLOperation.Request.Options?,
2122
resultListener: StorageGetURLOperation.ResultListener?) -> StorageGetURLOperation
@@ -28,6 +29,7 @@ public protocol StorageCategoryBehavior {
2829
/// - progressListener: Triggered intermittently to represent the ongoing progress of this operation
2930
/// - resultListener: Triggered when the download is complete
3031
/// - Returns: An operation object that provides notifications and actions related to the execution of the work
32+
@discardableResult
3133
func downloadData(key: String,
3234
options: StorageDownloadDataOperation.Request.Options?,
3335
progressListener: ProgressListener?,
@@ -42,6 +44,7 @@ public protocol StorageCategoryBehavior {
4244
/// - progressListener: Triggered intermittently to represent the ongoing progress of this operation
4345
/// - resultListener: Triggered when the download is complete
4446
/// - Returns: An operation object that provides notifications and actions related to the execution of the work
47+
@discardableResult
4548
func downloadFile(key: String,
4649
local: URL,
4750
options: StorageDownloadFileOperation.Request.Options?,
@@ -57,6 +60,7 @@ public protocol StorageCategoryBehavior {
5760
/// - progressListener: Triggered intermittently to represent the ongoing progress of this operation
5861
/// - resultListener: Triggered when the upload is complete
5962
/// - Returns: An operation object that provides notifications and actions related to the execution of the work
63+
@discardableResult
6064
func uploadData(key: String,
6165
data: Data,
6266
options: StorageUploadDataOperation.Request.Options?,
@@ -72,6 +76,7 @@ public protocol StorageCategoryBehavior {
7276
/// - progressListener: Triggered intermittently to represent the ongoing progress of this operation
7377
/// - resultListener: Triggered when the upload is complete
7478
/// - Returns: An operation object that provides notifications and actions related to the execution of the work
79+
@discardableResult
7580
func uploadFile(key: String,
7681
local: URL,
7782
options: StorageUploadFileOperation.Request.Options?,
@@ -85,6 +90,7 @@ public protocol StorageCategoryBehavior {
8590
/// - options: Parameters to specific plugin behavior
8691
/// - resultListener: Triggered when the remove is complete
8792
/// - Returns: An operation object that provides notifications and actions related to the execution of the work
93+
@discardableResult
8894
func remove(key: String,
8995
options: StorageRemoveOperation.Request.Options?,
9096
resultListener: StorageRemoveOperation.ResultListener?) -> StorageRemoveOperation
@@ -95,6 +101,7 @@ public protocol StorageCategoryBehavior {
95101
/// - options: Parameters to specific plugin behavior
96102
/// - resultListener: Triggered when the list is complete
97103
/// - Returns: An operation object that provides notifications and actions related to the execution of the work
104+
@discardableResult
98105
func list(options: StorageListOperation.Request.Options?,
99106
resultListener: StorageListOperation.ResultListener?) -> StorageListOperation
100107
}

AmplifyTests/CategoryTests/API/APICategoryClientRESTTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class APICategoryClientRESTTests: XCTestCase {
3434
}
3535
}
3636

37-
_ = Amplify.API.get(request: RESTRequest()) { _ in }
37+
Amplify.API.get(request: RESTRequest()) { _ in }
3838

3939
waitForExpectations(timeout: 0.5)
4040
}

0 commit comments

Comments
 (0)