-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Swift5] Add an async execute
API to RequestBuilder<T>
#14416
[Swift5] Add an async execute
API to RequestBuilder<T>
#14416
Conversation
Run `./bin/generate-samples.sh`
I forgot to add it
Hi, could you please elaborate on the use case where you need this? Thanks |
@@ -65,6 +65,32 @@ import Vapor | |||
return requestTask | |||
} | |||
|
|||
{{#useAsyncAwait}} | |||
@discardableResult | |||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func execute() async throws -> Response<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we should have an @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
before the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it!
Ok @4brunu . I'd like to use the API in a situation where making a builder object is better than using high-level async API (like An example of the usecase is computing onetime values and passing them into header fields, such as a signature or crypt things. I suppose using a builder instance and calling Currently, I can't find a way of passing the builder as a high-level API's parameter, or executing it with My Concrete UsecaseI use openapi-gen swift5 client with an OAuth client library, like bellow: let oauthClient = OAuthSwiftClient(
consumerKey: "xxx",
consumerSecret: "xxx",
oauthToken: "xxx",
oauthTokenSecret: "xxx",
version: .oauth1
)
// Because oauth_signature needs a complete URL, I make a builder object in advance.
let tweetAPIRequestBuilder = TweetsAPI.usersIdTimelineWithRequestBuilder(id: "xxx")
// Get computed oauth authorization header fields
guard let computedHTTPHeaderFields = oauthClient.makeRequest(.init(url: URL(string: tweetAPIRequestBuilder.URLString)!)).config.urlRequest.allHTTPHeaderFields else {
return
}
// Set onetime oauth values into the builder object's headers
tweetAPIRequestBuilder.addHeaders(computedHTTPHeaderFields)
// I can write like this, but...
// OpenAPIClientAPI.customHeaders = computedHTTPHeaderFields
// Task { let response = try? await TweetsAPI.usersIdTimeline(id: "xxx") }
// Call `try await builder.execute()` is simple
Task {
do {
let response = try await tweetAPIRequestBuilder.execute()
let tweets = response.body.data
} catch {
print(error)
}
} |
Thanks for explaining the use case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
Thanks for creating this PR.
Thank you for the code review! |
Add a new async API interface to
RequestBuilder<T>
. I changedAPIs.mustache
, then updated petstore samples by running./bin/generate-samples.sh ./bin/configs/swift5*
.Issue: #14415
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(6.3.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)Mentions
@4brunu