swagger-api/swagger-codegen

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

Open

#4709 aperta il 4 feb 2017

Vedi su GitHub
 (9 commenti) (0 reazioni) (0 assegnatari)HTML (5474 fork)batch import
Client: AndroidIssue: Bughelp wanted

Metriche repository

Star
 (12.701 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor