swagger-api / swagger-api/swagger-codegen

[Java] codegen with parcelableMode fails to build if using arrays in swagger

Open
#4,709 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Android help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Java codegen with parcelableMode enabled causing build errors if the swagger file has arrays.

Swagger-codegen version

snapshot 2.2.2

Swagger declaration file content or url

This is an example of how I create the array:

    {
    "WeatherValueTypes": {
        "type": "array",
        "items": {
        "type": "string",
         "enum": [
              "airTemp"
          ]
       }
    }
Command line used for generation

java -jar swagger-codegen-cli.jar generate -i swagger.json -l java -c config.json -o data

{
"artifactId": "Data",
  "artifactVersion": "1.0.0",
  "library": "retrofit2",
  "parcelableModel": true,
  "hideGenerationTimestamp": true
}
Steps to reproduce

command line generation works fine. It fails when you try to build from gradle.

Error Output

/git/swagger/data/src/main/java/com/test/data/model/WeatherValueTypes.java:66: error: cannot find symbol
     super.writeToParcel(out, flags);    }
          ^
  symbol: method writeToParcel(Parcel,int)
/git/swagger/data/src/main/java/com/test/data/model/WeatherValueTypes.java:73: error: no suitable constructor found for ArrayList(Parcel)
     super(in); 
     ^
    constructor ArrayList.ArrayList(int) is not applicable
      (argument mismatch; Parcel cannot be converted to int)
    constructor ArrayList.ArrayList(Collection<? extends String>) is not applicable
      (argument mismatch; Parcel cannot be converted to Collection<? extends String>)
Related issues
Suggest a Fix

This is the PR that added parcelable support:

https://github.com/swagger-api/swagger-codegen/pull/3320/files

{{#parent}} super(in); {{/parent}} and {{#parent}} super.writeToParcel(out, flags); {{/parent}} seem to be the primary issues when dealing with arrays.

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 parcelable support changes in PR #3320 and inspect the generated WeatherValueTypes.java model produced by the shown command and configuration. Reproduce the Gradle build failure with the array schema, then verify that the generated array model builds successfully with parcelableMode enabled.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.