Skip to content
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

Add copyWith methods to data models #4

Open
pattobrien opened this issue Dec 4, 2023 · 3 comments
Open

Add copyWith methods to data models #4

pattobrien opened this issue Dec 4, 2023 · 3 comments

Comments

@pattobrien
Copy link

Hey there! Very impressed by the collection of k8s models, thanks a lot for your work on them so far.

Would you be willing to add "copyWith" functionality to each of the generated schemas, or accept a PR for doing so? I didn't see where the automation script was located, but if you'd like to share that I could take a look at implementing this myself.

Thanks in advance, and I'm looking forward to contributing how I can!

@xclud
Copy link
Owner

xclud commented Dec 4, 2023

Hi @pattobrien

This is a great addition to have. The generation code is written in C# and is extremely dirty. I don't even think about sharing it unless i clean up and refactor the code.

@pattobrien
Copy link
Author

Haha I totally get that, but no judgment here - as long as it works, thats what's most important 😉

I'm vaguely familiar with C#, but have a good amount of expertise in Dart generation tools, the analyzer packages, etc.. Have you considered porting the tooling over to Dart? If that makes sense for you and the project, then I can definitely help out.

I'm not sure how complex such a tool might be, but I assume the implementation looks something like this:

  • create Dart models from official k8s resource definitions (e.g. k8s OpenAPI spec)
  • generate directories based on API structure, and create top-level libraries with exports of individual model files as part files
  • create a k8s REST api client (e.g. using OpenAPI spec)
  • support for first-class k8s resources, plus Istio (not sure where to find the Istio spec)

If you'd be up for sharing some related info with me, I'd be more than happy to do the heavy lifting for the code gen tool. The features we could add for each model would be:

  • fromJson
  • toJson
  • copyWith (possibly with deep-copy support, like Freezed package offers)
  • anything else?

Let me know your thoughts and I might be able to get started with this sometime over the next couple of weeks.

@xclud
Copy link
Owner

xclud commented Dec 7, 2023

The process is exactly like you wrote. for k8s i generated the code from OpenAPI spec, but for other projects like Istio i used the yaml definition files. So basically it is two code generators coupled with each other and made the code dirty.

I started to port everything to dart a while ago. But since i didn't have free time, i didn't continue working on it.

So why not, let's begin. I will share with some code in the coming days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants