swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.03k stars 6.03k forks source link

[CSharp] Issue with double numbers if local is not US #6785

Open lunat opened 7 years ago

lunat commented 7 years ago

Hi,

I am using codegen 2.3.0.

In file ApiClient, the Method public string ParameterToString(object obj) contains an error at row: https://github.com/swagger-api/swagger-codegen/blob/c6b6249f1c792be804b2fb991cd0e104ce169536/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache#L311

If I use a localization different from "US" and I have a double value this row returns a number with a comma "," instead dot "."

I think it should be better to return always the "dotted" number adding another "else if" condition:

    else if (obj is double || obj is decimal)
    {
        return Convert.ToString(obj, new CultureInfo("en-US"));
    }

Thanks,

lunat

jimschubert commented 7 years ago

@lunat this sounds like a reasonable fix to me. Are you able to submit a PR and verify that it has resolved your issue?

wing328 commented 6 years ago

@lunat @jimschubert should the users change the localization setting instead in his/her PC?

jimschubert commented 6 years ago

@wing328 It's not really reasonable to expect every client consumer to change their machine locale to en-US. Ideally, the format would be a configurable option in the spec, but the spec doesn't support that, as far as I'm aware.

I would think the best approach for now is to the input/output format for the API is a known format.

We may want to consider supporting global formatting configurations (number, currency, date) and then supporting per-operation formatting. What are your thoughts with that approach?