OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.22k stars 6.43k forks source link

[REQ] Allow "extra" derives for Rust models #19193

Closed trombonehero closed 2 weeks ago

trombonehero commented 1 month ago

Is your feature request related to a problem? Please describe.

I have several models that I need to derive traits like yew::Properties or yewdux::Store. Currently, I have to re-add these traits to my models' #[derive(...)] every time I update them with openapi-generator.

Describe the solution you'd like

I'd like to pass additional properties like deriveTraits='Properties,Store' and use='yew::prelude::*',use='yewdux::prelude::*' via the CLI.

Describe alternatives you've considered

I've tried creating wrappers around the OpenAPI models, but that leads to awkward duplication and pass-through logic.

I can add non-derived functionality by writing impl X for ModelName elsewhere in the crate, but there are some traits that really want to be derived rather than hand-written.

Currently I use Git to track which derivations have been deleted by openapi-generator and, each time I regenerate from a new version of the API, undo these deletions.

Additional context

You can't anticipate every possible use case for these models, so adding extension points seems logical to me.

wing328 commented 1 month ago

Currently, I have to re-add these traits to my models' #[derive(...)] every time I update them with openapi-generator.

did you try using customized templates (e.g. -t via CLI)?

trombonehero commented 2 weeks ago

Hi @wing328, it looks like templates can indeed solve at least part of my issue... thanks!