OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.59k stars 6.52k forks source link

[JAVA][SPRING] Bug generating multipart file array for RestAssured library #9978

Open ajware-uscis opened 3 years ago

ajware-uscis commented 3 years ago
Description

When generating the Api class for RestAssured and creating methods for composing and adding data to the RequestSpecBuilder, the generated method for adding a list of files (List<java.io.File>) to the reqSpec creates code that is unable to compile.

The generated code tries to pass the list directly to reqSpec.addMultiPart(java.io.File file) which only accepts a single file.

openapi-generator version

4.3.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: foo-api
  description: RESTful API exposing services used for foo
  version: 1.0.0
paths:
  /foo/upload:
    post:
      operationId: uploadFooFiles
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              properties:
                files:
                  type: array
                  items:
                    type: string
                    format: binary
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                  message:
                    type: string
Command line used for generation

Java version: 11.0.7-amzn Gradle version: 6.8.3

build.gradle:

plugins {
    id "org.openapi.generator" version "4.3.1"
    id "java"
}

dependencies {
    implementation "io.springfox:springfox-swagger2:2.9.0"
    implementation "org.openapitools:jackson-databind-nullable:0.2.1"
    implementation "io.rest-assured:rest-assured:3.1.0"
}

openApiGenerate {
    generatorName = "java"
    inputSpec = "$swaggerSourceFile"
    outputDir = "$swaggerOutputDir"
    configFile = "$swaggerConfigFile"
    configOptions = [
        dateLibrary: "java8"
    ]
    library = "rest-assured"
}

CLI: gradle :openApiGenerate or ./gradlew :openApiGenerate

Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

Generated method filesMultiPart should iterate over the list of files, adding each individually:

public UploadFooFilesOper filesMultiPart(List<File> files) {
    for (final File file : files) {
        reqSpec.addMultiPart(file);
    }
    return this;
}
aleksandar-stefanovic-tamedia commented 1 year ago