forked from loafle/openapi-generator-original
[csharp] date proper format (#5734)
* [csharp] Honor Swagger/OpenAPI 'date' format Per spec (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types), DateTime instances defined as 'date' datatype need to be serialized as defined by full-date - RFC3339, which has the format: full-date = date-fullyear "-" date-month "-" date-mday ref: https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14 see #5513 see #5531 * [csharp] Regenerate sample * [csharp] Include date format test
This commit is contained in:
@@ -312,6 +312,8 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
clientPackageDir, "ApiResponse.cs"));
|
||||
supportingFiles.add(new SupportingFile("ExceptionFactory.mustache",
|
||||
clientPackageDir, "ExceptionFactory.cs"));
|
||||
supportingFiles.add(new SupportingFile("SwaggerDateConverter.mustache",
|
||||
clientPackageDir, "SwaggerDateConverter.cs"));
|
||||
if(Boolean.FALSE.equals(this.netStandard) && Boolean.FALSE.equals(this.netCoreProjectFileFlag)) {
|
||||
supportingFiles.add(new SupportingFile("compile.mustache", "", "build.bat"));
|
||||
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "build.sh"));
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
{{>partial_header}}
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace {{packageName}}.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Formatter for 'date' swagger formats ss defined by full-date - RFC3339
|
||||
/// see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
|
||||
/// </summary>
|
||||
public class SwaggerDateConverter : IsoDateTimeConverter
|
||||
{
|
||||
public SwaggerDateConverter()
|
||||
{
|
||||
// full-date = date-fullyear "-" date-month "-" date-mday
|
||||
DateTimeFormat = "yyyy-MM-dd";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ using System.ComponentModel;
|
||||
{{/generatePropertyChanged}}
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
{{/netStandard}}
|
||||
using SwaggerDateConverter = {{packageName}}.Client.SwaggerDateConverter;
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
|
||||
@@ -91,9 +91,11 @@ this.{{name}} = {{name}};
|
||||
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
|
||||
/// </summary>{{#description}}
|
||||
/// <value>{{description}}</value>{{/description}}
|
||||
[DataMember(Name="{{baseName}}", EmitDefaultValue={{emitDefaultValue}})]
|
||||
[DataMember(Name="{{baseName}}", EmitDefaultValue={{emitDefaultValue}})]{{#isDate}}
|
||||
[JsonConverter(typeof(SwaggerDateConverter))]{{/isDate}}
|
||||
public {{{datatype}}} {{name}} { get; {{#isReadOnly}}private {{/isReadOnly}}set; }
|
||||
{{/isEnum}}
|
||||
|
||||
{{/vars}}
|
||||
/// <summary>
|
||||
/// Returns the string presentation of the object
|
||||
|
||||
Reference in New Issue
Block a user