Best pattern for extending generated types
Is your feature request related to a problem? Please describe. We need a way to add methods to generated types/classes. I'm wondering what the best pattern for this is.
Describe the solution you'd like
One example is that we have a common File type that many of our API objects include, say:
{ release_type: 'property', file: File}
File being shaped like: {url: string, mime_type: string}
I'd like to add a method to File to truncate the url to just the actual filename, in a way that attaches to all instances of File across our api.
Describe alternatives you've considered I've considered using helper methods that consume File but this seems like it goes against the grain of having classes in the first pace.
I'm mainly using hooks so not a lot of classes. With this in mind, I do prefer simple helpers methods, easier to test, and since you can use the generated type as input, this will alert you if you have any API breaking changes.
This said, you can do what ever you like, I don't believe in the "best pattern" concept, to me, this more about communication in your team. If you find a solution that is working for your project and your team, you are good to go! And if you find a better solution later, just iterate! Usually, I will go for the "keep it simple" and iterate if necessary 😉
And, if you really want some custom functions in the generated classes, I think, the simpliest, is to fork the project and tweak the generator, everything is unit tested so this is safe to play with.