swagger-api / swagger-api/swagger-codegen
[CSHARP] int64 being converted to long correctly but given a float default so won't compile
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
As per title, I am trying to generate the model classes for the docker api swagger spec, this contains a number of nullable properties of format "integer" and format "int64". They are being generated as long? but then given a default value which indicates it is a float, e.g. long? size = -1F which causes a compiler error.
Swagger-codegen version
3.0.65
Swagger declaration file content or url
UsageData:
type: "object"
x-nullable: true
x-go-name: "UsageData"
required: [Size]
description: |
Usage details about the volume. This information is used by the
`GET /system/df` endpoint, and omitted in other endpoints.
properties:
Size:
type: "integer"
format: "int64"
default: -1
description: |
Amount of disk space used by the volume (in bytes). This information
is only available for volumes created with the `"local"` volume
driver. For volumes created with other volume drivers, this field
is set to `-1` ("not available")
x-nullable: false
produces
/// <summary>
/// Initializes a new instance of the <see cref="VolumeUsageData" /> class.
/// </summary>
/// <param name="size">Amount of disk space used by the volume (in bytes). This information is only available for volumes created with the `\"local\"` volume driver. For volumes created with other volume drivers, this field is set to `-1` (\"not available\") (required) (default to -1F).</param>
public VolumeUsageData(long? size = -1F)
Command line used for generation
docker run --rm --network=host -v ${PWD}:/local swaggerapi/swagger-codegen-cli-v3 generate \
-i http://localhost:3000/swagger.yaml \
-l csharp \
-Dmodels \
--additional-properties=resolveMethodConflicts=true \
-c /local/config.json \
-o /local/out/csharp
Steps to reproduce
-
Using the following docker swagger spec (which originally came from here)
swagger.yaml.zip -
Host the swagger-ui mounting this spec file in
docker run -p 3000:8080 -e SWAGGER_JSON=/swagger.yaml -v $(pwd)/swagger.yaml:/swagger.yaml swaggerapi/swagger-ui
- Generate the C# code with the following
docker run --rm --network=host -v ${PWD}:/local swaggerapi/swagger-codegen-cli-v3 generate \
-i http://localhost:3000/swagger.yaml \
-l csharp \
-Dmodels \
--additional-properties=resolveMethodConflicts=true \
-c /local/config.json \
-o /local/out/csharp
- Observe all the default float values being given for longs when you try to build it.
Related issues/PRs
None found
Suggest a fix/enhancement
Feels like somewhere along the way nullable int64 types are being treated as floats somewhere between the correct mapping into an actual C# type (a long?) and working out what default value to use.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the Docker-based csharp generation command and the supplied Swagger specification. Trace how nullable int64 properties are mapped to long? and how their default values are rendered in the generated constructor; done means the generated C# uses a valid long default and builds without compiler errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100