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][typescript-axios] When Multiple File Uploaded, it does not work as isCollectionFormatMulti #7247

Closed
5 of 6 tasks
shrkw opened this issue Aug 19, 2020 · 2 comments · Fixed by #7814
Closed
5 of 6 tasks

Comments

@shrkw
Copy link

shrkw commented Aug 19, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I want to define api for 'Multiple File Upload' which refer the part in swagger document File Upload.
But the generated script deals with binaries as simple string.

localVarFormParams.append('files', files.join(COLLECTION_FORMATS.csv));

openapi-generator version

v4.3.1

OpenAPI declaration file content or url

I added encoding parameter to force form style but not works well.

openapi: 3.0.3
info:
  title: test
  version: '0.1'
tags:
  - name: test
    description: test
servers:
  - url: 'http://localhost:3000'
paths:
  /api/upload:
    post:
      tags: []
      operationId: upload files
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                message:
                  type: string
                files:
                  type: array
                  items:
                    type: string
                    format: binary
              required:
                - message
            encoding:
              files:
                style: form
                explode: true
      responses:
        '200':
          description: ok
Generation Details

use this command.

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v4.3.1 generate \
    -p supportsES6=true \
    -p modelPropertyNaming=camelCase \
    -i /local/doc/test.yaml \
    -g typescript-axios \
    -o /local/app/javascript --verbose
Steps to reproduce

just run by above command, then it generate following script.

                if (files) {
                       localVarFormParams.append('files', files.join(COLLECTION_FORMATS.csv));
            }

here is verbose output https://gist.github.com/shrkw/5002c71e33177b99c0529f1506d6ff22

and api.ts https://gist.github.com/shrkw/5002c71e33177b99c0529f1506d6ff22#file-api-ts-L77

Related issues/PRs

Not sure but may be same issue.

BUG multi file upload not implemented fully · Issue #6752 · OpenAPITools/openapi-generator · GitHub

Same issue is facing to this guy.
BUGJavaSpring multiple files upload · Issue #4803 · OpenAPITools/openapi-generator · GitHub

Suggest a fix

I want to set isCollectionFormatMulti attribute, but not sure how to do it.

openapi-generator/apiInner.mustache at f752f29af202885e6b817e5ec002facee1ef0c33 · OpenAPITools/openapi-generator · GitHub

            {{#isCollectionFormatMulti}}
                {{paramName}}.forEach((element) => {
                    localVarFormParams.append('{{baseName}}', element as any);
                })
            {{/isCollectionFormatMulti}}
@shrkw shrkw changed the title [BUG] Description [Bug][typescript-axios] When Multiple File Uploaded, it does not work as isCollectionFormatMulti Aug 20, 2020
@imcloudf
Copy link

imcloudf commented Sep 5, 2020

having the same issue with version 5.0.0-beta

@imcloudf
Copy link

imcloudf commented Sep 6, 2020

I read some code and found that isCollectionFormatMulti currently is not support for form params.

//TODO collectionFormat for form parameter not yet supported
at DefaultCodegen.java Line 5832
and

String collectionFormat = null;
// ... some lines do not assign other value to collectionFormat
//TODO fix collectformat for form parameters
//collectionFormat = getCollectionFormat(s);
// default to csv:
codegenParameter.collectionFormat = StringUtils.isEmpty(collectionFormat) ? "csv" : collectionFormat;

at DefaultCodegen.java Line 5712

But, how do we specify a collectionFormat for Request Body Object ? I can only see collectionFormat for Parameter Object in OpenApi Specification (using style property) and this merge did not check collectionFormat.

Should we just remove the isCollectionFormatMulti check and some other lines?

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