Swagger-codegen: Enums as ints

Created on 5 Apr 2016  路  8Comments  路  Source: swagger-api/swagger-codegen

Update: Enums as strings seem to work fine. Enums as ints used to work fine (they would generate as int?, I'm using csharp), but in master now, they throw the following error:

Exception in thread "main" java.lang.RuntimeException: Could not process model 'IncidentByLocationReportRequest'
    at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:244)
    at io.swagger.codegen.cmd.Generate.run(Generate.java:223)
    at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:36)
Caused by: java.lang.ArrayStoreException
    at java.lang.System.arraycopy(Native Method)
    at java.util.ArrayList.toArray(Unknown Source)
    at io.swagger.codegen.languages.CSharpClientCodegen.findCommonPrefixOfVars(CSharpClientCodegen.java:422)
    at io.swagger.codegen.languages.CSharpClientCodegen.postProcessModels(CSharpClientCodegen.java:317)
    at io.swagger.codegen.DefaultGenerator.processModels(DefaultGenerator.java:833)
    at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:237)
    ... 2 more

The spec for that particular type:

IncidentByLocationReportRequest:{  
  type:"object",
  properties:{  
    endDate:{  
      format:"date-time",
      type:"string"
    },
    startDate:{  
      format:"date-time",
      type:"string"
    },
    incidentCategoryId:{  
      format:"int32",
      type:"integer"
    },
    clientLocationIds:{  
      type:"array",
      items:{  
    format:"int32",
    type:"integer"
      }
    },
    reportType:{  
      format:"int32",
      enum:[  
    0,
    1,
    2,
    3
      ],
      type:"integer"
    },
    severityLevel:{  
      format:"int32",
      type:"integer"
    }
  }
},
C-Sharp Bug

All 8 comments

@langdonx I've something ready to address the issue and will submit the fix after the v2.1.6 stable relese due today/tomorrow.

@langdonx I've submitted https://github.com/swagger-api/swagger-codegen/pull/2508.

I wonder if you can give it a try to confirm it addresses the issue for your case.

Works again, thanks! It's back to doing int? which makes sense since the names aren't available in the spec.

@langdonx What was the fix for this? Did you generate against master?

@jimschubert yes, master. should be fixed in 2.2.0.

@jimschubert Oops, you know what, I actually pulled down wing's fork and branch from the pull request.

@langdonx sorry, when I commented yesterday @wing328's messages weren't visible. I guess github has a limit on how actively you can contribute and rate limited him ;)

@langdonx I've merged https://github.com/swagger-api/swagger-codegen/pull/2508 into master. I wonder if you can pull the latest master and give it a try.

Was this page helpful?
0 / 5 - 0 ratings