-
Notifications
You must be signed in to change notification settings - Fork 12
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
Consider generating types from the OpenAPI spec #4
Comments
Hey. Apologies for the delay. I've been very slow at getting back into my OSS stuff post-holiday. YES! I'd absolutely love to see all the resources generated via codegen. Skimming your repo, it looks like a pretty straight-forward drop-in replacement. We could incorporate the codegen into this crate, but I think I'd actually lean toward making this crate depend on and re-export your generated resource types if you intend to manage it as a crate (which alternate clients or other tools could also use). I'd happily accept a PR for this, or I might try and carve out some time in the next couple weeks to make it happen. I haven't dug in enough to grok client generation using the |
My initial feeling was that the codegen would be manually fixed up a bit first instead of being used directly. You can see it in the example in the OP as well - it converts the dotted definition names into Rust modules so the generated types are very nested. For example your crate has So I initially had this process in mind:
Pros:
Cons:
But now that I think about it, all the definitions do start with What do you think? If you're okay with Re: generating the client using
I think it's best to keep manually-generated clients for now. |
Perhaps the biggest downfall I see of using codegen resources from an external crate is exemplified by the Being focused on ergonomics,
I'm not 100% decided, so definitely open to opinions here, but I lean slightly to starting with the 3rd approach (which is probably the quickest to implement), and consider the other approaches once I have a better feel for integrating the codegen types. In all cases, this will help fill out a lot of incomplete definitions! |
I think option 2 will make it error-prone to use. Options 1 and 3 can both work. I agree that option 3 is probably better. I'll drop the codegen into its own GH repo over the next few days so you can pull it as a git crate dependency and play around with it. |
awesome and thanks! |
Done. # Cargo.toml
[dependencies]
k8s-openapi = { git = "https://github.com/Arnavion/k8s-openapi-codegen", branch = "master" } // main.rs
extern crate k8s_openapi;
fn main() {
let pod_spec: k8s_openapi::api::core::v1::PodSpec = Default::default();
println!("{:#?}", pod_spec);
}
|
@Arnavion In your example, the default value for EDIT: Sorry, I just saw that |
This is based on the conversion in Issue #4
Master now uses several generated types from your repo. I'm definitely open to further ideas around codegen, and eventually, we should sync up about publishing these crates, but for now, I have a project that should give me a chance to get some more experience with this client and its codegen'd internals. |
Any plans to progress on this or it's an abandoned track? |
@maximih It's not abandoned [yet?], but definitely sidelined at the moment. I started an ncurses-based tool for using this (think |
https://crates.io/crates/k8s-openapi/ is now published, with multiple supported versions of Kubernetes (version-specific modules gated by features) and a client API based on the |
I've made a tool k8s-openapi-codegen that generates Rust types from the Kubernetes OpenAPI spec. For example this is what the generated
PodSpec
looks like:I've tested that the generated code compiles but I haven't used it against actual apiserver responses. It might make sense to also generate clients using the
paths
part of the OpenAPI spec.You can run it yourself to check out all the generated types. Are you interested in incorporating the generated types into kubeclient?
The text was updated successfully, but these errors were encountered: