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
{{ message }}
Repository navigation
Type Error. ObjectSerializer expects a date but I want to pass it a string #2189
Describe the bug
Type Error. ObjectSerializer expects a date but gets a string.
TypeError: data.toISOString is not a function
at ObjectSerializer.serialize (file:///Users/bensaxon/Documents/code/monorepo/src/private/console/node_modules/.pnpm/@kubernetes+client-node@1.0.0/node_modules/@kubernetes/client-node/dist/gen/models/ObjectSerializer.js:2024:29)
The code expects data to be a Date object with a toISOString method.
Instead, when I log the result, I actually get a string, already in ISO format, such as:
2025-01-30T09:58:20.000Z
This is because the resource that I pass into the client has a metadata.creationTimestamp field that is a string. I would rather not have to convert it into a Date. Since I receive it as a string from API requests. I like it as a string. I know it's "supposed" to be a Date according to the type, but it's just impractical. I think it's a bad developer experience. Also, this error does not occur in v0.
Client Version 1.0.0
To Reproduce
Steps to reproduce the behaviour:
The error is thrown when trying to make a PUT request.
Ensure that resource.metadata.creationTimestamp is a string, not a date object.
I expect the error not to throw. I suggest putting a conditional inside the serialize function that checks if data is of type string before assuming it's a Date object. If data is a string, then return it as is, else return data.toISOstring().
We rely on code generation because the surface area of the Kubernetes API is too large to have hand-written code maintained by a small number of maintainers.
If you want to raise a PR on that repo to modify the generator so that it can handle both strings or Date objects, I bet they will accept it, but that's where the change needs to be made.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
This fix targets the TypeScript/TypeScript-Fetch generators and allows date fields during serialization to accept both Date instances and ISO strings, avoiding the “data.toISOString is not a function” error (as seen in the ObjectSerializer.serialize scenario described here).
Would you consider upgrading the OpenAPI Generator used by this project to a version that includes this fix and regenerating the client? If that sounds acceptable, I’d be happy to open a PR to handle the upgrade and regeneration.
@0x5457 as soon as there are no breaking changes we should be fine with upgrading and regenerating all the time.
As mentioned here: #2582 we will probably release a new version with the new k8s version.
However, I've tried to update the generator and did a simple smoke test on my cluster just to see if the client still works and it works.
There is one error though: I can not seem to be able to import the AbortController from node-fetch/externals.
I've updated node-fetch as well as the types for the package.
I've looked into the node_modules and it's present in the types declaration but I still get this error when running npm run build-with-tests.
EDIT: Just got reminded by a notification that this is in flight: #2583
Activity
brendandburns commentedon Jan 31, 2025
The decision about how to handle this is part of the code generator, specifically the files here:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache
We rely on code generation because the surface area of the Kubernetes API is too large to have hand-written code maintained by a small number of maintainers.
If you want to raise a PR on that repo to modify the generator so that it can handle both strings or Date objects, I bet they will accept it, but that's where the change needs to be made.
k8s-triage-robot commentedon May 4, 2025
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle stale/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
k8s-triage-robot commentedon Jun 3, 2025
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle rotten/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
k8s-triage-robot commentedon Jul 3, 2025
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/reopen/remove-lifecycle rottenPlease send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
k8s-ci-robot commentedon Jul 3, 2025
@k8s-triage-robot: Closing this issue, marking it as "Not Planned".
Details
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
0x5457 commentedon Aug 13, 2025
Hi @brendandburns , I’ve submitted and merged a related fix in openapi-generator: OpenAPITools/openapi-generator#21722
This fix targets the TypeScript/TypeScript-Fetch generators and allows date fields during serialization to accept both Date instances and ISO strings, avoiding the “data.toISOString is not a function” error (as seen in the ObjectSerializer.serialize scenario described here).
Would you consider upgrading the OpenAPI Generator used by this project to a version that includes this fix and regenerating the client? If that sounds acceptable, I’d be happy to open a PR to handle the upgrade and regeneration.
mstruebing commentedon Aug 13, 2025
@0x5457 as soon as there are no breaking changes we should be fine with upgrading and regenerating all the time.
As mentioned here: #2582 we will probably release a new version with the new k8s version.
However, I've tried to update the generator and did a simple smoke test on my cluster just to see if the client still works and it works.
There is one error though: I can not seem to be able to import the
AbortControllerfromnode-fetch/externals.I've updated
node-fetchas well as the types for the package.I've looked into the node_modules and it's present in the types declaration but I still get this error when running
npm run build-with-tests.EDIT: Just got reminded by a notification that this is in flight: #2583