OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.23k stars 6.43k forks source link

[BUG][CSHARP-NETCORE] uint32 type is generating int types, which is out of range #5888

Open joshhunt opened 4 years ago

joshhunt commented 4 years ago

Bug Report Checklist

Description

Attempting to generate C# models for the Bungie API, using their openapi spec. Once generated and I deserialize the JSON, I get the following error: JSON integer 3612906877 is too large or small for an Int32

Screenshot_30

Upon investigation, the openapi file defines seasonHashes as

"seasonHashes": {
  "description": "...",
  "type": "array",
  "items": {
    "format": "uint32",
    "type": "integer"
  },
  "x-mapped-definition": {
    "$ref": "#/definitions/Destiny.Definitions.Seasons.DestinySeasonDefinition"
  }
}

Note the uint32. The generated code however, defines SeasonHashes as int, which is a smaller range of values, which does not fit the value coming from the API

// BungieNetApi\Model\DestinyEntitiesProfilesDestinyProfileComponent.cs
[DataMember(Name="seasonHashes", EmitDefaultValue=false)]
public List<int> SeasonHashes { get; set; }

If I manually change, in the generated C# code, these types to longs, everything works.

It appears the generator incorrectly generates uint32 types as int.

openapi-generator version

4.3.0

OpenAPI declaration file content or url

https://raw.githubusercontent.com/Bungie-net/api/master/openapi-2.json

Command line used for generation

openapi-generator generate -i https://raw.githubusercontent.com/Bungie-net/api/master/openapi-2.json -g csharp-netcore -o ./csharp-netcore --skip-validate-spec -c ./config.json

// ./config.json
{
  "packageName": "BungieNetApi"
}
Steps to reproduce
Related issues/PRs
Suggest a fix
FaFre commented 4 years ago

From what I've seen, unsigned data types of any kind are not supported yet in general by openapi-generator. It only knows signed values.