Skip to content

[CSHARP] int64 being converted to long correctly but given a float default so won't compile #12506

@dutts

Description

@dutts
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 &#x60;\&quot;local\&quot;&#x60; volume driver. For volumes created with other volume drivers, this field is set to &#x60;-1&#x60; (\&quot;not available\&quot;)  (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
  1. Using the following docker swagger spec (which originally came from here)
    swagger.yaml.zip

  2. 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
  1. 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
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions