swagger-api/swagger-codegen

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

Open

#4 709 ouverte le 4 févr. 2017

Voir sur GitHub
 (9 commentaires) (0 réactions) (0 assignés)HTML (5 474 forks)batch import
Client: AndroidIssue: Bughelp wanted

Métriques du dépôt

Stars
 (12 701 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

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.

Guide contributeur