-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timestamps have wrong type #487
Comments
I don't think this is a bug. 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? |
let pod: V1Pod;
console.log(pod.metadata?.creationTimestamp, typeof pod.metadata?.creationTimestamp); outputs the type of Possible solutions are converting the string to an actual Date object or change the typing to be a string. |
@brendanburns We are also experiencing problems because of this. The spec also defines the type as |
There is another scenario where the Date is broken: This what i have trying to post an event with eventTime set as a
|
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
@brendanburns could you please re-evaluate this? |
Yep. The type declaration in typescript is wrong - it declares 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:
|
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 |
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:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
Would be nice if this gets fixed eventually... |
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:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
/remove-lifecycle rotten |
Would a PR that changes the types of any Dates to be strings be accepted? |
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:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
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:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
/lifecycle frozen |
We'd like to contribute to fix this issue. Would a PR that changes the types of any Dates to be strings be accepted? |
@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. |
@brendandburns I think it should be possible to change this in the generator by adding the setting 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 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. |
@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 |
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. diff --git a/openapi/typescript.xml b/openapi/typescript.xml
index b33e5c9..8507e13 100644
--- a/openapi/typescript.xml
+++ b/openapi/typescript.xml
@@ -36,7 +36,7 @@
<npmVersion>${generator.client.version}</npmVersion>
<modelPropertyNaming>original</modelPropertyNaming>
</configOptions>
- <typeMappings>int-or-string=IntOrString,date-time-micro=V1MicroTime</typeMappings>
+ <typeMappings>int-or-string=IntOrString,Date=string</typeMappings>
</configuration>
</execution>
</executions> Removing 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) |
This seems to still be an issue. Are there any plans to fix this or workarounds? |
The timestamps have incorrect typescript types.
For example
https://github.com/kubernetes-client/javascript/blob/master/src/gen/model/v1ObjectMeta.ts#L32
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.
The text was updated successfully, but these errors were encountered: