You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
creationTimestamp is of type Date | undefined, but the documentation says it's an RFC3339 formatted date aka a string.
Since this is generated code I'm not sure of where to fix this. Either the type has to change to string | undefined, or the string has to be parsed and passed on as a date object.
Reacted by Daniel Huth, Lukáš Doležal and Gustav Bylund
This what i have trying to post an event with eventTime set as a new Date() then converted into data.toISOString by models.js serialize method
message: 'Event in version "v1" cannot be handled as a Event: v1.Event.InvolvedObject: v1.ObjectReference.EventTime: unmarshalerDecoder: parsing time "2020-12-09T23:44:10.443Z" as "2006-01-02T15:04:05.000000Z07:00": cannot parse ".443Z" as ".000000", error found in #10 byte of ...|4:10.443Z","involved|..., bigger context ...|{"eventTime":"2020-12-09T23:44:10.443Z","involvedObject":{"kind":"Game","name":"monkey-is|...',
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
Yep. The type declaration in typescript is wrong - it declares Date | undefined but the actual value (in runtime) is string | undefined...
It is difficult to work with, and caused a bug for us (we were expecting it to be Date, all tests pass, typescript checks pass, but in runtime it blows up, because it is string)
Either:
Change the typescript declaration to string | undefined
Or parse the date in the client and return actual Date object
What reported @paolomainardi seems to be related to kubernetes/kubernetes#89156: K8S could parse without problems Dates sent from the JavaScript client, but the format currently used to parse MicroTime is too strict.
@brendandburns I think it should be possible to change this in the generator by adding the setting date-time=string,date=string in the typeMappings section in the typescript.xml file?
I think this should also affect the existing type mapping from date-time-micro to V1MicroTime (as that is most likely also a string), but I haven't verified that.
It seems like this might be (partially?) fixed in the newer typescript generator, but until that has been implemented using a typeMapping should resolve the issue.
Hey again @brendandburns, sorry for taking ages on this 😓
I did some testing tonight and changing the generator configuration like this results in dates being generated as strings instead, which is correct with how the data is actually sent from the API.
Removing date-time-micro=V1MicroTime is also needed since that's also sent as strings, and aren't deserialised into custom V1MicroTime objects. I'm not sure how that would factor into serialization.
Would you like me to open a pull request against the generator config repository with that change?
(I tested this on both the release-1.x branch and the master branch, both seems to yield correct results)
Activity
brendandburns commentedon Aug 17, 2020
I don't think this is a bug.
creationTimestampis av1.Timewhich is marked with openapiformat: date-timein the spec here:https://github.com/kubernetes/kubernetes/tree/master/api/openapi-spec
The swagger spec says: "Tools can use the format to validate the input or to map the value to a specific type in the chosen programming language." (https://swagger.io/docs/specification/data-models/data-types/)
So I think that this is a legit code generation given the openapi spec.
Is this causing problems for you?
simhnna commentedon Aug 19, 2020
outputs
2020-07-23T06:01:17Z stringthe type of
V1Pod.metadata.creationTimestamphowever isDate | undefinedand notstring | undefinedPossible solutions are converting the string to an actual Date object or change the typing to be a string.
Agreon commentedon Oct 13, 2020
@brendanburns We are also experiencing problems because of this. The spec also defines the type as
stringeven if the format isdate-timepaolomainardi commentedon Dec 9, 2020
There is another scenario where the Date is broken:
CoreV1Event.eventTimewhich is defined as aDatehere, but the api server expects ametav1.MicroTimehttps://github.com/kubernetes/api/blob/master/events/v1beta1/types.go#L41This what i have trying to post an event with eventTime set as a
new Date()then converted intodata.toISOStringbymodels.jsserialize methodfejta-bot commentedon Mar 10, 2021
Issues go stale after 90d of inactivity.
Mark the issue as fresh with
/remove-lifecycle stale.Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with
/close.Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
simhnna commentedon Mar 18, 2021
@brendanburns could you please re-evaluate this?
/remove-lifecycle stale
DocX commentedon Mar 29, 2021
Yep. The type declaration in typescript is wrong - it declares
Date | undefinedbut the actual value (in runtime) isstring | undefined...It is difficult to work with, and caused a bug for us (we were expecting it to be Date, all tests pass, typescript checks pass, but in runtime it blows up, because it is string)
Either:
string | undefinedDateobjectmichelle-laurenti commentedon May 22, 2021
What reported @paolomainardi seems to be related to kubernetes/kubernetes#89156: K8S could parse without problems Dates sent from the JavaScript client, but the format currently used to parse
MicroTimeis too strict.k8s-triage-robot commentedon Aug 20, 2021
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.
This bot triages issues and PRs according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle stale/lifecycle rotten/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
simhnna commentedon Aug 30, 2021
Would be nice if this gets fixed eventually...
/remove-lifecycle stale
k8s-triage-robot commentedon Nov 28, 2021
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.
This bot triages issues and PRs according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle stale/lifecycle rotten/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
8 remaining items
Maistho commentedon Jun 26, 2022
/remove-lifecycle stale
k8s-triage-robot commentedon Sep 24, 2022
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.
This bot triages issues and PRs according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle stale/lifecycle rotten/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
Maistho commentedon Sep 24, 2022
/remove-lifecycle stale
brendandburns commentedon Dec 16, 2022
/lifecycle frozen
Maistho commentedon Dec 26, 2022
We'd like to contribute to fix this issue. Would a PR that changes the types of any Dates to be strings be accepted?
brendandburns commentedon Dec 30, 2022
@Maistho unfortunately all of that code is generated. So you need to either change the openapi that Kubernetes generates, or you need to change the upstream openapi code generator (https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/typescript)
If you successfully modify the upstream code generator, then we can regenerate with the new type.
Maistho commentedon Dec 30, 2022
@brendandburns I think it should be possible to change this in the generator by adding the setting
date-time=string,date=stringin thetypeMappingssection in thetypescript.xmlfile?https://github.com/kubernetes-client/gen/blob/ea5af85f5bb75934bf7f3eb1edab1643e8caab47/openapi/typescript.xml#L39
As suggested in the issue on the openapi-generator repo: OpenAPITools/openapi-generator#926 (comment)
I think this should also affect the existing type mapping from
date-time-microtoV1MicroTime(as that is most likely also a string), but I haven't verified that.It seems like this might be (partially?) fixed in the newer typescript generator, but until that has been implemented using a typeMapping should resolve the issue.
brendandburns commentedon Dec 30, 2022
@Maistho thanks for digging in.
If you want to try changing that and regenerating locally to validate that it works, we can see about getting it into the
0.19.0release.Maistho commentedon Jun 2, 2023
Hey again @brendandburns, sorry for taking ages on this 😓
I did some testing tonight and changing the generator configuration like this results in dates being generated as strings instead, which is correct with how the data is actually sent from the API.
Removing
date-time-micro=V1MicroTimeis also needed since that's also sent as strings, and aren't deserialised into custom V1MicroTime objects. I'm not sure how that would factor into serialization.Would you like me to open a pull request against the generator config repository with that change?
(I tested this on both the release-1.x branch and the master branch, both seems to yield correct results)
bilalshaikh42 commentedon Mar 30, 2024
This seems to still be an issue. Are there any plans to fix this or workarounds?