kiota icon indicating copy to clipboard operation
kiota copied to clipboard

Default date/time values generate invalid code

Open Clockwork-Muse opened this issue 10 months ago • 1 comments

When generating an API with default time values, the defaults are strings, which causes invalid code to be generated.

The following segment:

"time": {
    "type": "string",
    "description": "The end time in ISO8601 (HH:mm:ss) format.",
    "format": "time",
    "default": "24:00:00",
    "example": "13:00:00"
}

generates the following:

public Time? Time { get; set; }

public ScheduledTimeSpan_end()
{
    Time = "24:00:00";
}

... which is a compile error.

repro.zip

.... also, date values don't have any defaults written at all...

Clockwork-Muse avatar Mar 10 '25 23:03 Clockwork-Muse

Hi @Clockwork-Muse Thank you for using kiota and for reaching out.

The code responsible for emitting the default value is here.

https://github.com/microsoft/kiota/blob/0d7538e771e6ae38a456a6b2aed68718bb8146da/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs#L253

It's missing a special casing to call the parsing method.

A test case entry can be added here

https://github.com/microsoft/kiota/blob/0d7538e771e6ae38a456a6b2aed68718bb8146da/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs#L1506

Is this something you'd like to submit a pull request for provided some guidance?

Also, I'll be transferring this issue to the main repo.

baywet avatar Mar 11 '25 14:03 baywet