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

Invalid Swift code for multipart POST with query parameters #2557

Closed
tomekc opened this issue Apr 11, 2016 · 6 comments
Closed

Invalid Swift code for multipart POST with query parameters #2557

tomekc opened this issue Apr 11, 2016 · 6 comments

Comments

@tomekc
Copy link
Contributor

tomekc commented Apr 11, 2016

When endpoint is multipart/form-data and contains both form params and query params, like this one

/profile/{id}/photo:
    post:
      operationId: addProfilePhoto
      consumes:
        - multipart/form-data
      parameters:
        - name: id
          in: path
          required: true
          type: string
        - name: file
          in: formData
          required: true
          type: file
          minLength: 1
          maxLength: 10000000  # ~10MB
        - name: attachmentType
          in: query
          type: string
          required: true
        - name: utf8FileName
          in: query
          type: string
          required: true

Resulting code has double "falsefalse" argument in

        return requestBuilder.init(method: "POST", URLString: URLString, parameters: parameters, isBody: falsefalse)

I have found mustache template for this:

isBody: {{^queryParams}}{{^formParams}}true{{/formParams}}{{/queryParams}}{{#queryParams}}{{^secondaryParam}}false{{/secondaryParam}}{{/queryParams}}{{#formParams}}{{^secondaryParam}}false{{/secondaryParam}}{{/formParams}}

and probably end up with PR to fix :) Any suggestions are welcome, however :)

One thing I'd like to learn is what is "secondaryParam"?

@wing328
Copy link
Contributor

wing328 commented Apr 11, 2016

@tomekc thanks for reporting the issue. It's not a case we've tested before and of course we would appreciate your contribution to fix it.

For secondaryParam, please refer to the discussion in #2125. Basically it's for better naming of Swift & ObjC method name.

@tomekc
Copy link
Contributor Author

tomekc commented Apr 11, 2016

I see much room for simplification here. Just to make sure, in following snippet:

        return requestBuilder.init(method: "POST", URLString: URLString, parameters: parameters, isBody: **false**)

isBody is supposed to be true only in case of JSON encoded bodies, and false otherwise?

@wing328
Copy link
Contributor

wing328 commented Apr 13, 2016

@tomekc that's how I understand it.

@tomekc
Copy link
Contributor Author

tomekc commented Apr 15, 2016

I did the fix, but found more serious issue deeper below.
In case of POST request, query parameters are discarded (because iBody is "true" in that case).

Apparently, RequestBuilder is not designed to support that case. I will go on and submit PR.

@wing328
Copy link
Contributor

wing328 commented Apr 15, 2016

@tomekc thanks for the fix.

FYI. The query parameter issue with POST request has been reported before: #2483

@wing328 wing328 modified the milestones: v2.3.0, v2.2.0 Jul 7, 2016
@wing328 wing328 modified the milestones: v2.2.1, v2.2.2 Aug 8, 2016
@wing328
Copy link
Contributor

wing328 commented Jan 7, 2017

PR merged. Issue closed.

@wing328 wing328 closed this as completed Jan 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants