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

[BUG] [angular-typescript] Incorrect JSON object in HTTP request multipart form data #2733

Closed
Beaurpi opened this issue Apr 24, 2019 · 3 comments · Fixed by #3738
Closed

Comments

@Beaurpi
Copy link

Beaurpi commented Apr 24, 2019

Hi there,

I've figured out that there is an issue with the code generated, when using a multipart/form-data object.
Declare a POST method with the following requestBody:

'/test/upload':
post:
requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                name:
                  type: string
                title:
                  type: object
                  properties:
                    en:
                      type: string
                    fr:
                      type: string
                fileName:
                  type: string
                  format: binary

It's related to the generated code in angular typescript.
in the generation command line i'm using the following:
-g typescript-angular

the generated service will have a good signature:
public uploadFile(id: string, name?: string, title?: UploadTitle, .....

But the HTTP post, will not pass a JSON for the parameter 'TITLE'.
It will actually encode the object as string.
As a result the 'title' parameter will be

-----------------------------8302951520691
Content-Disposition: form-data; name="title"

[object: Object]

Instead the parameter title should be

-----------------------------8302951520691
Content-Disposition: form-data; name="title"

{ en: 'sometext', fr: 'loren ipsum' }
@auto-labeler
Copy link

auto-labeler bot commented Apr 24, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@macjohnny
Copy link
Member

macjohnny commented Apr 29, 2019

I guess the problem is due to the following lines of code:

return this.httpClient.{{httpMethod}}{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}(`${this.configuration.basePath}{{{path}}}`,{{#isBodyAllowed}}
{{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}{{#hasFormParams}}convertFormParamsToString ? formParams.toString() : formParams{{/hasFormParams}}{{^hasFormParams}}null{{/hasFormParams}}{{/bodyParam}},{{/isBodyAllowed}}

@Beaurpi would you like to give it a try and implement a fix?

@Beaurpi
Copy link
Author

Beaurpi commented Apr 30, 2019

@macjohnny That would be a pleasure. I would be totally newbie in .moustache things and this project.
So I think it would be better that someone else is taking care of this. I am missing a bit of time to get deep inside the project though...

daniel-sc added a commit to daniel-sc/openapi-generator that referenced this issue Aug 23, 2019
jimschubert added a commit that referenced this issue Aug 25, 2019
* master: (45 commits)
  update python samples
  Two tiny fixes for Java Vertx client (#3683)
  Exclude "test" from packages so that it is not installed as top-level package when "pip installing" the generated sdk (#3731)
  [java-client] add unit test for JDK 11 HttpClient (#3735)
  [R] feat(r): handling error response for 3xx cases (#3571)
  [Dart] Avoid redundant null checking in fromJson (#3632)
  [core] Set isMultipart=true for multipart operations, fix possible NPE (#3750)
  reenable kotlin client tests in shippable ci (#3751)
  Fix null assignation to header/query param map (#3749)
  Mockito 3.0.0 (#3732)
  Update to swagger-parser to 2.0.14-OpenAPITools.org-1 (#3737)
  Add a link to a Qiita blog post (#3747)
  update csharp samples
  Simple spelling error in dotnet core comments (#3746)
  better support for multipart (#3736)
  [typescript-fetch] fix #1998: prefix req ifaces. (#3740)
  cpp-qt5-client: add valgrind memory test (#3663)
  [typescript-angular] Encode objects for multipart/form-data with json - fixes #2733 (#3738)
  [BUG] Https protocol schema is not handled correctly in java 11 native code #3729 (#3730)
  comment out kotlin client tests
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants