Open jnovick opened 5 years ago
You can override the template: https://github.com/RSuter/NSwag/wiki/Templates
Or we add a setting for that
The template is probably in NJsonSchema
I do think this should be a more easily customizable field though.
I was able to resolve our issue by including a changed DateFormatConverter.liquid file and setting templateDirectory to point at it. Thank you for your help. Having this be configurable would probably benefit others so I don't think this issue should be closed, but I no longer require this change so no need to rush to help me.
I've just run into the issue of a platform providing null dates as "0000-00-00" which will not deserialise cleanly with this converter.
I see two fairly clean solutions that would solve this one
SwaggerToCSharpClientGeneratorSettings.CSharpGeneratorSettings.JsonConverters
to be used in it's place) You can override/implement your own converter by override the DateFormatConverter.liquid template
Yeah I realise that, and i've done that for now although it feels a bit messy since I need some global type converters anyway and it would have been nice to include them all the same way.
You could leave the template file empty and define a converter somewhere else with the name and add the using with AdditionalNamespaceUsages
But yes, changing the tpl feels messy but so does adding a new setting for every scenario... each setting adds new complexity for everyone and increases maintenance cost. Also the generated clients should be self contained, ie should just work correctly for the spec and should not require any external changes/implementations.
Maybe we should just change the date converter to convert 0000-00-00 to null if the target type is DateTime? ? Dont see why everyone would want the actual year 0 in a nullable datetime?
DateFormatConverter always generates with
The
yyyy-MM-dd
should be customizable for interacting with APIs that use other formats.