Skip to content

[BUG] [Spring] Generated API interface treats multipart arrays as a single file #3139

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

Closed
5 of 6 tasks
galleog opened this issue Jun 11, 2019 · 1 comment · Fixed by #4616
Closed
5 of 6 tasks

[BUG] [Spring] Generated API interface treats multipart arrays as a single file #3139

galleog opened this issue Jun 11, 2019 · 1 comment · Fixed by #4616

Comments

@galleog
Copy link

galleog commented Jun 11, 2019

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

Generated API interface for multipart arrays contains a single MultipartFile instead of a list. Besides any MultipartFile argument should have @RequestPart annotation instead of @RequestParam.

openapi-generator version

Tested with 4.0.0 version of https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin

OpenAPI declaration file content or url
openapi: '3.0.0'
info:
  version: 1.0.0
  title: MultipartFile test
paths:
  /multipart-array:
    post:
      tags:
        - multipart
      description: MultipartFile array test
      operationId: multipartArray
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                files:
                  type: array
                  items:
                    type: string
                    format: binary
      responses:
        '204':
          description: Successful operation
  /multipart-single:
    post:
      tags:
        - multipart
      description: Single MultipartFile test
      operationId: multipartSingle
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
      responses:
        '204':
          description: Successful operation
Command line used for generation

Maven plugin was used:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>${openapi-generator-maven-plugin.version}</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${basedir}/src/main/resources/multipart.yaml</inputSpec>
                <generatorName>spring</generatorName>
                <modelPackage>org.openapi.test.model</modelPackage>
                <apiPackage>org.openapi.test.api</apiPackage>
                <library>spring-cloud</library>
                <generateSupportingFiles>false</generateSupportingFiles>
                <generateApiTests>false</generateApiTests>
                <configOptions>
                    <interfaceOnly>true</interfaceOnly>
                    <dateLibrary>java8</dateLibrary>
                    <java8>true</java8>
                    <booleanGetterPrefix>is</booleanGetterPrefix>
                    <useBeanValidation>true</useBeanValidation>
                    <useTags>true</useTags>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
Steps to reproduce

Generate MultipartApi interface using the plugin configuration listed above. Both multipartArray and multipartSingle methods contains a single MultipartFile parameter with @RequestParam annotation.

Related issues/PRs
Suggest a fix

Looks like the mustache template formParams.mustache ignores arrays.

@ips219
Copy link

ips219 commented Aug 22, 2019

I am not sure if it is the best solution.... But for me this worked....

1-Download templates for JavaSpring to local project folder from github

2-Include the templateDirectory parameter in the plugin configuration

                            <templateDirectory>${project.basedir}/templates/JavaSpring</templateDirectory>
                            <configOptions>
                                <hideGenerationTimestamp>true</hideGenerationTimestamp>
                                <dateLibrary>java8</dateLibrary>
                                <sourceFolder>api</sourceFolder>
                                <library>spring-boot</library>
                                <delegatePattern>true</delegatePattern>
                            </configOptions>
                            <output>target/generated-sources</output>

3-Fix the related templates: api.mustache, apiDelegate.mustache, exampleReturnTypes.mustache, formParams.mustache, formParams.mustache by replacing all MultipartFile entries by {{#isListContainer}}List<{{/isListContainer}}MultipartFile{{#isListContainer}}>{{/isListContainer}}

rbrincke added a commit to rbrincke/openapi-generator that referenced this issue Nov 26, 2019
Multi-part binary array strings as outlined in OpenAPITools#3139 resulted in `MultipartFile` rather than `List<MultipartFile>`. This PR attempts to resolve this by adjusting the templates.

Two tests have been added: one for `spring-boot` and one for `spring-cloud`.

Resolve OpenAPITools#3139
sun9999 added a commit to sun9999/openapi-generator that referenced this issue Dec 4, 2019
* Fix multi-part binary array strings

Multi-part binary array strings as outlined in OpenAPITools#3139 resulted in `MultipartFile` rather than `List<MultipartFile>`. This PR attempts to resolve this by adjusting the templates.

Two tests have been added: one for `spring-boot` and one for `spring-cloud`.

Resolve OpenAPITools#3139

* Fix multipart file name and description

* Handle array of MultipartFile for delegate

* Update samples due to file description being picked up

* Upload result of bin/spring-stubs
wing328 pushed a commit that referenced this issue Dec 9, 2019
…g Cloud templates (#4616)

* Fix multi-part binary array strings

Multi-part binary array strings as outlined in #3139 resulted in `MultipartFile` rather than `List<MultipartFile>`. This PR attempts to resolve this by adjusting the templates.

Two tests have been added: one for `spring-boot` and one for `spring-cloud`.

Resolve #3139

* Fix multipart file name and description

* Handle array of MultipartFile for delegate

* Update samples due to file description being picked up

* Upload result of bin/spring-stubs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants