Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dutts opened this issue Dec 19, 2024 · 0 comments

Comments

@dutts
Copy link

dutts commented Dec 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant