microsoft / kiota-typescript

TypeScript libraries for Kiota-generated API clients.
https://aka.ms/kiota/docs
MIT License
32 stars 25 forks source link

[Bug] Parse duration #1169

Closed X2Style closed 1 month ago

X2Style commented 2 months ago

Response of the GET booking business has duration stored as P365D (schedulingPolicy.maximumAdvance) It is parsed by tinyduration as {days: 365} Then it fails with the error - https://github.com/microsoft/kiota-typescript/blob/main/packages/abstractions/src/duration.ts#L41

baywet commented 2 months ago

Hi @X2Style Thanks for using the Microsoft Graph SDK, and for reporting this.

I'm not sure why we have this validation rule here since the RFC3339 duration format is specified as following:

   dur-second        = 1*DIGIT "S"
   dur-minute        = 1*DIGIT "M" [dur-second]
   dur-hour          = 1*DIGIT "H" [dur-minute]
   dur-time          = "T" (dur-hour / dur-minute / dur-second)
   dur-day           = 1*DIGIT "D"
   dur-week          = 1*DIGIT "W"
   dur-month         = 1*DIGIT "M" [dur-day]
   dur-year          = 1*DIGIT "Y" [dur-month]
   dur-date          = (dur-day / dur-month / dur-year) [dur-time]

   duration          = "P" (dur-date / dur-time / dur-week)

Which in human language would read "one or more digit", nothing limits the day element to 7, especially when you consider you can't use it in combination with the week element.

So this rule should be removed IMHO, so should be the ones limiting the values of years, months, hours, and seconds. Additionally, rules limiting the combined use of day-week, week-hour/second/minute should be added.

Is this something you'd be interested in submitting a pull request for?

X2Style commented 2 months ago

Hi @baywet I've created PR, could you please take a look? https://github.com/microsoft/kiota-typescript/pull/1180