swagger-api / swagger-api/swagger-codegen

[Dart] Codegen fails with any type {}

Open
#8,627 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When an object is defined with a property with no type definition, the codegen reports, "Could not process model '{Object-Name}'. Please make sure that your schema is correct!"

Swagger-codegen version

Using 2.4.0-SNAPSHOT

Swagger declaration file content or url
"Notification":{
  "type":"object",
  "properties":{
    "id":{"type":"integer","format":"int64"},
    "message":{"type":"string"},
    "icon_url":{"type":"string"},
    "metadata":{},
    "read_status":{"type":"boolean"},
    "created_at":{"type":"string","format":"date-time"},
    "updated_at":{"type":"string","format":"date-time","x-nullable":true}
  },
  "additionalProperties":false,
  "required":[
    "id",
    "message",
    "icon_url",
    "metadata",
    "read_status",
    "created_at",
    "updated_at"
  ]
}

Note the metadata property is defined with any type.

Command line used for generation

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i ~/Downloads/medanswers_swagger.json -l dart -o ~/swagger-output/dart/

Steps to reproduce
  • Modify a property on an object in the pet store example to have any type {}.
  • Try to generate the code against the modified pet store example using the codegen CLI.
  • Codegen will fail with the stated error.
Related issues/PRs

This appears to have been introduced with the changes to the Dart codegen for compatibility with flutter. Codegen does not fail with version 2.3.1.

https://github.com/swagger-api/swagger-codegen/pull/7418

Suggest a fix/enhancement

I'm not familiar enough with Mustache syntax to suggest a fix, but I suspect it will require a modification to https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/dart/class.mustache

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 with the Dart generation path and the referenced modules/swagger-codegen/src/main/resources/dart/class.mustache template, then reproduce the failure using the modified pet store example and the CLI command shown. Done means Dart code generation succeeds when a model property is defined as an empty object, without regressing the existing example.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.