Skip to content

The method 'listFromJson' isn't defined for the type 'MultipartFile'. #180

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

Open
sawongam opened this issue Mar 13, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@sawongam
Copy link

sawongam commented Mar 13, 2025

Description of the bug

The OpenAPI Generator for Dart is generating code that includes a call to MultipartFile.listFromJson(json[r'photos']), but the MultipartFile class (from the http package) does not have a listFromJson method. This results in a compilation error:

The method 'listFromJson' isn't defined for the type 'MultipartFile'.

Steps to reproduce

  1. Use the OpenAPI Generator for Dart to generate models and API code from an OpenAPI specification that includes a field expecting a list of MultipartFile objects (e.g., photos).
  2. The generated code will include a line like this:
    photos: MultipartFile.listFromJson(json[r'photos']),
  3. Attempt to compile the generated code. The compilation will fail with the error mentioned above.

Minimal openapi specification

Here’s a minimal OpenAPI specification that reproduces the issue:

openapi: 3.0.0
info:
  title: Sample API
  version: 1.0.0
paths:
  /upload:
    post:
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                photos:
                  type: array
                  items:
                    type: string
                    format: binary
      responses:
        '200':
          description: Success
components:
  schemas:
    AddIncomeExpenseRequestDTO:
      type: object
      properties:
        photos:
          type: array
          items:
            type: string
            format: binary

Annotation used

Here’s the @openapi annotation I used:

@Openapi(
  inputSpec: InputSpec(
    path: 'bin/restrox-swagger.json',
  ),
  generatorName: Generator.dart,
  outputDirectory: 'lib/data/generated',
  cleanSubOutputDirectory: ['lib/data/generated'],
)
class ApiClient {}

### Expected behavior

The generated code should handle the photos field correctly, either by:

Providing a valid method to deserialize a list of MultipartFile objects, or

Generating code that uses a supported method for handling file uploads (e.g., MultipartFile.fromFileSync or similar).

### Logs

```text
No specific logs are available as this is a compilation error. 
The error message is:

The method 'listFromJson' isn't defined for the type 'MultipartFile'.

Screenshots

No response

Platform

Linux

Library version

6.1.0

Flutter version

3.27.3

Flutter channel

stable

Additional context

The issue arises because the MultipartFile class from the http package does not have a listFromJson method. The OpenAPI Generator is not correctly handling the mapping of file lists to MultipartFile objects. This requires either a template modification or a built in feature to correctly handle the multipart file generation.


@sawongam sawongam added the bug Something isn't working label Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant