OpenAPITools / OpenAPITools/openapi-generator

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

Open
#9,978 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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
  • Create a Java Spring project with OAS generator
  • Add OAS spec attached above
  • Add build.gradle file with openApiGenerate task as pasted above
  • Call CLI command above: gradle :openApiGenerate
  • Inspect the bug in generate RestAssured Api class (method name: filesMultiPart)
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;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the Gradle openApiGenerate task with the supplied OpenAPI spec and inspect the generated RestAssured API method filesMultiPart. Compare its handling of List with RequestSpecBuilder.addMultiPart(File), then verify that the generated client compiles and adds each file individually.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.