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

Error in generated code: The getter 'field' isn't defined for the type 'List<MultipartFile>' #81

Open
Kahoulam opened this issue Feb 3, 2023 · 2 comments

Comments

@Kahoulam
Copy link

Kahoulam commented Feb 3, 2023

Generated code error in file

Error message:

The getter 'field' isn't defined for the type 'List<MultipartFile>'.
Try importing the library that defines 'field', correcting the name to the name of an existing getter, or defining a getter or field named 'field'.

Error file Path: /lib/api/uploader_api.dart > UploaderApi > uploaderUploadWithHttpInfo

  Future<Response> uploaderUploadWithHttpInfo(List<MultipartFile> images,) async {
    // ignore: prefer_const_declarations
    final path = r'/upload';

    // ignore: prefer_final_locals
    Object? postBody;

    final queryParams = <QueryParam>[];
    final headerParams = <String, String>{};
    final formParams = <String, String>{};

    const contentTypes = <String>['multipart/form-data'];

    bool hasFields = false;
    final mp = MultipartRequest('POST', Uri.parse(path));
    if (images != null) {
      hasFields = true;
      
      // Error:
      // The getter 'field' isn't defined for the type 'List<MultipartFile>'.
      // Try importing the library that defines 'field', correcting the name to the name of an existing getter, or defining a getter or field named 'field'.
      mp.fields[r'images'] = images.field;
      
      // Error:
      // The argument type 'List<MultipartFile>' can't be assigned to the parameter type 'MultipartFile'
      mp.files.add(images);
    }
    if (hasFields) {
      postBody = mp;
    }

    return apiClient.invokeAPI(
      path,
      'POST',
      queryParams,
      postBody,
      headerParams,
      formParams,
      contentTypes.isEmpty ? null : contentTypes.first,
    );
  }

Annotation

@Openapi(
    alwaysRun: true,
    additionalProperties: AdditionalProperties(pubName: 'my_api'),
    inputSpecFile: 'openapi3.yaml',
    generatorName: Generator.dart,
    outputDirectory: 'api/')
class Example {}

Input spec file

openapi: 3.0.3
info:
    title: API Test
    version: 1.0.0
servers:
    - url: http://localhost:80
paths:
    /upload:
        post:
            tags:
                - Uploader
            summary: Upload Uploader
            operationId: Uploader#Upload
            requestBody:
                required: true
                content:
                    multipart/form-data:
                        schema:
                            $ref: '#/components/schemas/UploadRequestBody'
            responses:
                "200":
                    description: OK
components:
    schemas:
        UploadRequestBody:
            type: object
            properties:
                images:
                    type: array
                    items:
                        type: string
                        format: binary
                    minItems: 1
            required:
                - images
tags:
    - name: Uploader
@zirg41
Copy link

zirg41 commented Aug 15, 2023

@Kahoulam is there any solution? im facing the same problem

@gibahjoe
Copy link
Owner

Hi, unfortunately, file upload is something that breaks from time to time.

To work around this, I suggest you fix the bad code and then add the file to .openapi-generator to prevent it from being overwritten the next time the geenrator runs.

Let me know if you need further assistance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants