Skip to content

[BUG] C# CodeGen doesnt respect nullable value for custom mapping with timespan #14305

Open
@aswinfrancis91

Description

@aswinfrancis91
Description

I have below two properties

[Required]
public TimeSpan StartTime { get; set; }
public TimeSpan? EndTime { get; set; }

but since I can't generate SDK with same timespan field from the swagger json I added below line to startup class

c.MapType<TimeSpan>(() => new OpenApiSchema { Type = "string", Format = "time-span", Nullable = false });
c.MapType<TimeSpan?>(() => new OpenApiSchema { Type = "string", Format = "time-span", Nullable = true });

The json generated also looks good

"startTime": {
            "type": "string",
            "format": "time-span"
          },
 "endTime": {
            "type": "string",
            "format": "time-span",
            "nullable": true
          },

I then pass the below type mapping argument
--type-mappings time-span=TimeSpan

The problem here is that the non nullable fields comes fine in the SDK generated but the nullable field comes as non nullable itself. Below is the C# code that was generated

[DataMember(Name = "startTime", IsRequired = true, EmitDefaultValue = true)]
public TimeSpan StartTime { get; set; }

[DataMember(Name = "endTime", EmitDefaultValue = true)]
 public TimeSpan EndTime { get; set; }
openapi-generator version

6.2.1

Related issues/PRs

#4951

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions