Nswag: Default c# type for "number" in Swagger Spec

Created on 14 Mar 2018  路  4Comments  路  Source: RicoSuter/NSwag

Apologies if this is covered elsewhere, but I cannot find if there is a setting to get NSwagStudio to create output using the Decimal type rather than Double. Our models are used by financial applications, so I want the properties that are defined as number to use Decimal. It's not a major, as I can just do a global replace in the generated code, but would be nice if there was a setting in the "Primitive types" section.
Thanks

help wanted NJsonSchema.CodeGeneration.CSharp enhancement

All 4 comments

This must be configured/customized in CSharpTypeResolver (NJsonSchema)

Apparently, fields with format: "decimal" in schema are converted to properties of type decimal in C#

https://github.com/RSuter/NJsonSchema/blob/7638a441c06226a6881f4930e582d748f99227d4/src/NJsonSchema.CodeGeneration.CSharp/CSharpTypeResolver.cs#L140

This is the default:
https://github.com/RSuter/NJsonSchema/blob/7638a441c06226a6881f4930e582d748f99227d4/src/NJsonSchema.CodeGeneration.CSharp/CSharpTypeResolver.cs#L143

We could add a new setting DefaultNumberType for the C# generator (+ TypeScript gen?) + a check for format "double" and use the defalut from the settings...

Would fix this too: https://github.com/RSuter/NSwag/issues/1122

Still in progress?

Was this page helpful?
0 / 5 - 0 ratings