Skip to content

🚨 Issue: multipart/form-data request object inside form-data is not generating the model #444

@GODOM018

Description

@GODOM018

Steps to reproduce

  1. Use the following example request in the open api snippet which has this schema that won't generate the request model.
 "UploadMultipartRequest": {
        "type": "object",
        "required": ["file", "request"],
        "properties": {
          "file": {
            "type": "string",
            "format": "binary",
            "description": "File to upload"
          },
          "request": {
            "$ref": "#/components/schemas/UploadRequest"
          }
        }
      }

Generated client (problem)

The generated Retrofit client looks like this:

@MultiPart()
@POST('/v1/upload')
Future<UploadResponse> uploadFile({
  @Part(name: 'file') required MultipartFile file,
  @Part(name: 'request') required UploadRequest request,
});

However:

  • The generator does not correctly detect or generate UploadRequest
  • This results in:
    • unresolved imports
    • missing models
    • compilation errors

Example generated import:

import '../models/upload_request.dart';

BUT THE FILE IS NOT GENERATED.

Expected results

swagger_parser should:

  1. Detect that the request references an object schema
  2. Generate the corresponding Dart model (UploadRequest)
  3. Correctly wire the model into the generated Retrofit client

Alternatively, if nested objects inside multipart/form-data are not supported, the generator should:

  • emit a warning
  • or treat the field as Map<String, dynamic>.

Actual results

The generated client references a model that is either:

  • not generated
  • not resolved correctly
  • or imported incorrectly.

Your OpenApi snippet

{
  "components": {
    "schemas": {
      "UploadRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "id": {
            "type": "integer"
          },
          "anotherField": {
            "type": "integer"
          }
        },
        "required": ["name", "id"]
      },
      "UploadMultipartRequest": {
        "type": "object",
        "required": ["file", "request"],
        "properties": {
          "file": {
            "type": "string",
            "format": "binary",
            "description": "File to upload"
          },
          "request": {
            "$ref": "#/components/schemas/UploadRequest"
          }
        }
      }
    }
  }
}

And the endpoint:

{
  "/v1/upload": {
    "post": {
      "requestBody": {
        "content": {
          "multipart/form-data": {
            "schema": {
              "$ref": "#/components/schemas/UploadMultipartRequest"
            }
          }
        }
      }
    }
  }
}

Code sample

Code sample
[Paste your code here]

Logs

Logs
[Paste your logs here]

Dart version and used packages versions

Dart version
Flutter 3.38.6
Packages version
swagger_parser: ^1.42.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions