-
-
Notifications
You must be signed in to change notification settings - Fork 178
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
feat: add serde preset #1027
feat: add serde preset #1027
Conversation
Kudos, SonarCloud Quality Gate passed! |
👋 Before getting into a more detailed review, I'm curious about the motivation for this change. Was there an ask to support a different serializer, like
|
The main driver is that presets are used for adding extra functionality to the core models, cause not everyone will use the models for Deserialization/Serialization of them. This is the same setup we have for all other generators 🙂 And even so, it's completely up to the individual how they want to customize their models, which functionality they should support etc. This PR adds that customization. So yea, it's nothing more then keeping it consistent across generators and keeping the core models (default) as minimalistic as possible🙂 |
Gotcha, this revision is oriented towards encapsulating all "extra behavior" in Modelina into presets? I'm struggling to understand the value added here, but I do see significant added complexity (e.g. 2x the number of test snapshots to maintain). I could see the value if someone was looking to implement an alternate serialization library, but without that need, it strikes me as unnecessary. Can you help me understand the value added, and why it's worth the time/energy to maintain? |
You can downcast a type that implements Here's an example of handling I wouldn't want to ship Also, implementing runtime checks for undefined behavior would make the code hella slow. A better approach is to rely on the Each serde implementation usually provides a JSON: YAML: Avro: Notably, Rust's binary data serde implementations cannot implement a |
Yes!
While one strong use-case is adding serializing and deserializing functionality, Modelina's primary use-case is in its diversity, in order to become part of your toolbox and be useful as soon as you want to generate models in any use-case. The models come in the most basic form and you as a user will have to add the layers of functionality you need through the presets. Making you in control of what fits into your use-case. It does not assume that you need to serialize and deserialize the models, or even that you are using a particular library (even though it sounds like for Rust, there is JUST one 😆) Might have misunderstood you in our discussion in your first PR then as I read it as there were multiple libraries for serializing models in Rust 😄 In an AsyncAPI world, would you ever generate the models without serialize and deserialize capabilities? In general probably not. But we have gotten feature requests such as #982, where there would be no need for it, and there are others in a similar fashion. Modelina is not meant as a "client" generator for MQTT, NATS, REST, or any other protocol, it's only a tool for generating models and if it's in the context of protocols, of course, serialization and deserialization are a huge part. Hence why I suggested we have At least three ways to serialize models. But that's just a single feature within Modelina 🙂 Maybe these goals of Modelina need to be well described somewhere instead of indirectly 🤔
I want to point something out here, just because there exists a preset within Rust, does mean YOU have to provide the time to maintain it. Always keep that in mind, that presets can have dedicated maintainers as well as you are for the core Rust generator 🙂 Hence why I suggested we pursue 2 code owners per area of responsibility. There are many parts to Modelina that we need to figure out how are maintained, and what their compatibility is. But that is a thing for the future I think 🙂 Hope that clarified my intentions with this PR, otherwise do let me know 😄 I just wanted to make this change before we released version 1, as this change would have to wait for another major version if it was to be fixed later. Do you think we should create a mission statement somewhere so this is clear? 🤔 |
Hmmmmm, yea that does pose a problem 🤔 What to do 🤔 Would it make sense we render our own |
@jonaslagoni Is there a funding commitment to staff 2 maintainers per Modelina language? Apologies if this sounds harsh, but I depend on this code in production and thus have a pragmatic approach to maintenance costs. The Modelina implementation is already 2-3 orders of magnitude more time-intensive than maintaining my OpenAPI schemas + generator, so from a business PoV, I'm already having a hard time justifying time investment.
|
Can you help me understand the problem with using If you need a different serialization library (YAML, Avro, etc), then the equivalent would be |
Closing as I have misunderstood what Serde enables 😄 |
Description
This PR introduces a few changes to the Rust generator:
#[derive(Deserialize, Serialize)
attributes.Some things I could not figure out @leigh-johnson that I need your help with:
serde_json::Value
? 🤔