swagger-api / swagger-api/swagger-codegen-generators

Dart Generator: JSON Array of Files

Open
#768 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

Hiya! Thanks for the great packages for code gen. I have a bug with the Dart generator.

Since this is a commercial project, I cannot share the entire openAPI spec, but I will attempt to share the relevant parts. We have an Order object that looks like this:

    Order:
      type: object
      properties:
        id:
          type: string
        state:
          $ref: "#/components/schemas/OrderState"
        accepted:
          type: string
          format: date
        files:
          type: array
          items:
            $ref: "#/components/schemas/File"
    File:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string

It defines an Order object that can contain a list of File. We define our own File, but when I generate the Code, our definition isn't used, and the Files array is instead transformed into an array of MultipartFile.

Two problems:

  1. The code that is generated does not compile. It attempts to call a MultipartFile.listFromJson constructor from inside the Order.fromJson method, which does not exist on the MultipartFile class.
  2. This isn't what we expected to happen, but is this intentional? This is my first time generating code from a Swagger spec, but this doesn't seem intuitive. If we wanted a multipart file, I assumed we'd change the spec to look like this: https://swagger.io/docs/specification/describing-request-body/file-upload/

Happy to help address this issue, but would appreciate a bit more info from your side on whether this is "working as intended" but needs a fix for the constructor, or if it shouldn't be coerced into a different type at all.

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 in the Dart generator by locating how schema array items are mapped and how MultipartFile is selected, then compare that behavior with the Order.fromJson output described here. Done means the generated code compiles and the File schema is handled consistently with the intended OpenAPI definition, including a clear decision about multipart coercion.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.