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

When request nullable file requests cannot use because MultipartFile.fromFileSync is not allowed nullable #272

Open
manabu0926 opened this issue Oct 26, 2024 · 0 comments

Comments

@manabu0926
Copy link

manabu0926 commented Oct 26, 2024

Steps to reproduce

1: define nullable and required File column.
2: dart run swagger_parser && dart run build_runner build -d
3: export error output

Expected results

if nullable: true column, define like not required column

    if (carRegistration != null) {
      _data.files.add(MapEntry(
        'carRegistration',
        MultipartFile.fromFileSync(
          carRegistration.path,
          filename: carRegistration.path.split(Platform.pathSeparator).last,
        ),
      ));
    }

Actual results

define

 _data.files.add(MapEntry(
      'carRegistration',
      // The property 'path' can't be unconditionally accessed because the receiver can be 'null'.
         Try making the access conditional (using '?.') or adding a null check to the target ('!').
      MultipartFile.fromFileSync(
        carRegistration.path,
        filename: carRegistration.path.split(Platform.pathSeparator).last,
      ),
    ));

Your OpenApi snippet

openapi: 3.0.0
info:
  description: Api definitions
  title: API
  version: v1
servers:
- url: http://localhost:8082/
paths:
  /api/driver_api/submitted_documents:
    put:
      operationId: putSubmittedDocuments
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/submitted_documents_update_request'
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ok'
          description: OK
        "400":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/bad_request'
          description: Bad Request
        "401":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/unauthorized'
          description: Unauthorized
        "422":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/unprocessable_entity_error'
          description: Unprocessable Entity
        "500":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/internal_server_error'
          description: Internal Server Error
      security:
      - bearerAuth: []
      summary: put Document File
      tags:
      - DriverApi::SubmittedDocuments
components:
  schemas:
    submitted_documents_update_request:
      properties:
        carRegistration:
          format: binary
          nullable: true
          type: string
      required:
      - carRegistration
      type: object
    ok:
      example:
        message: 登録しました。
        error:
          errorDetails:
          - propertyName: name
            propertyMessage: 入力値が不正です。
          - propertyName: name
            propertyMessage: 入力値が不正です。
      properties:
        message:
          example: 登録しました。
          type: string
        error:
          $ref: '#/components/schemas/error'
      type: object
    message:
      example: 登録しました。
      type: string
    error:
      example:
        errorDetails:
        - propertyName: name
          propertyMessage: 入力値が不正です。
        - propertyName: name
          propertyMessage: 入力値が不正です。
      properties:
        errorDetails:
          items:
            $ref: '#/components/schemas/error_detail'
          type: array
      type: object
    error_detail:
      example:
        propertyName: name
        propertyMessage: 入力値が不正です。
      properties:
        propertyName:
          description: エラーになったプロパティ
          example: name
          type: string
        propertyMessage:
          description: エラーメッセージ
          example: 入力値が不正です。
          type: string
      required:
      - propertyMessage
      - propertyName
      type: object
    bad_request:
      example:
        message: 登録しました。
        error:
          errorDetails:
          - propertyName: name
            propertyMessage: 入力値が不正です。
          - propertyName: name
            propertyMessage: 入力値が不正です。
      properties:
        message:
          example: 登録しました。
          type: string
        error:
          $ref: '#/components/schemas/error'
      type: object
    unauthorized:
      example:
        message: 登録しました。
        error:
          errorDetails:
          - propertyName: name
            propertyMessage: 入力値が不正です。
          - propertyName: name
            propertyMessage: 入力値が不正です。
      properties:
        message:
          example: 登録しました。
          type: string
        error:
          $ref: '#/components/schemas/error'
      type: object
    unprocessable_entity_error:
      example:
        message: 登録しました。
        error:
          errorDetails:
          - propertyName: name
            propertyMessage: 入力値が不正です。
          - propertyName: name
            propertyMessage: 入力値が不正です。
      properties:
        message:
          example: 登録しました。
          type: string
        error:
          $ref: '#/components/schemas/error'
      type: object
    internal_server_error:
      example:
        message: 登録しました。
        error:
          errorDetails:
          - propertyName: name
            propertyMessage: 入力値が不正です。
          - propertyName: name
            propertyMessage: 入力値が不正です。
      properties:
        message:
          example: 登録しました。
          type: string
        error:
          $ref: '#/components/schemas/error'
      type: object
  securitySchemes:
    bearerAuth:
      bearerFormat: JWT
      scheme: bearer
      type: http

Code sample

No response

Logs

Logs
[Paste your logs here]

Dart version and used packages versions

retrofit 4.4.1
carapacik_lints: ^1.9.1
dart_mappable_builder: ^4.3.0
freezed: ^2.5.7
json_serializable: ^6.8.0
retrofit_generator: ^9.1.3
swagger_parser: ^1.19.2

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

1 participant