Skip to content
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] Remove optional from body #10938

Merged
merged 5 commits into from
Nov 23, 2021

Conversation

funzin
Copy link
Contributor

@funzin funzin commented Nov 23, 2021

Remove optional from body
When using getNonDecodableBuilder, Response body type is Void only so we don't need to have body as optional.

  • Remove unused switch case code
  • Change from body: T? to body: T

we won't have to do any unnecessary unwrapping when using api response.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    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.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@funzin
Copy link
Contributor Author

funzin commented Nov 23, 2021

@4brunu
Please review it when you have time.

@@ -160,100 +160,20 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>()
let validatedRequest = request.validate()

switch T.self {
case is String.Type:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When response type is void, getNonDecodableBuilder is used

  • let localVariableRequestBuilder: RequestBuilder<{{{returnType}}}{{^returnType}}Void{{/returnType}}>.Type = {{projectName}}API.requestBuilderFactory.{{#returnType}}getBuilder(){{/returnType}}{{^returnType}}getNonDecodableBuilder(){{/returnType}}
  • {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func {{operationId}}({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}apiResponseQueue: DispatchQueue = {{projectName}}API.apiResponseQueue) -> AnyPublisher<{{{returnType}}}{{^returnType}}Void{{/returnType}}, Error> {

@funzin funzin changed the title [swift5]Remove optional from body [swift5] Remove optional from body Nov 23, 2021
@4brunu
Copy link
Contributor

4brunu commented Nov 23, 2021

Hi @funzin, thanks for creating this PR.
CI is failing because there are places where the optional body was being unwrapped, but now since it's not optional anymore, it can't be unwrapped.
Could you please check for the other places that need to be updated?
For example the file api.mustache and i'm not sure if there are other places.
Thanks

@funzin
Copy link
Contributor Author

funzin commented Nov 23, 2021

OK, I will check these places:+1:

@@ -167,7 +167,7 @@ extension {{projectName}}API {
switch result {
{{#returnType}}
case let .success(response):
promise(.success(response.body!))
promise(.success(response.body))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@funzin please search and replace all occurrences of response.body! with response.body in this class, to fix all the cases. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already checked response.body! in swift5
dbdc585

Maybe, CI will be succeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@4brunu
CI ✅

@funzin funzin force-pushed the swift5/unwrap-body branch from a1a8d2c to a802030 Compare November 23, 2021 11:42
@funzin funzin force-pushed the swift5/unwrap-body branch from a802030 to dbdc585 Compare November 23, 2021 11:44
Copy link
Contributor

@4brunu 4brunu left a 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 this PR

@wing328 wing328 merged commit 64a478a into OpenAPITools:master Nov 23, 2021
@funzin funzin deleted the swift5/unwrap-body branch November 24, 2021 03:52
@wing328 wing328 added this to the 5.3.1 milestone Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants