vojtechhabarta / typescript-generator

Generates TypeScript from Java - JSON declarations, REST service client
MIT License
1.13k stars 236 forks source link

Add way to add typescript decorators to class properties #697

Open mojo2012 opened 3 years ago

mojo2012 commented 3 years ago

Hi,

first let me thank you for this awesome project!

Currently we generate typescript classes from our java DTO classes. Just recently we started to add swagger to our typescript application (nestjs), but unfortunately for the type to be working correctly with swagger, every property/method needs to be annotated with @ApiProperty (same as in java).

For various reasons the nestjs cli plugin to add this annotation to every class doesn't work at all.

It would be nice to have some kind of postprocessor for the emitted typescript classes to add annotations/decorators or do even other kinds of things. As I understand it, there is a way to add a custom TypeProcessor, maybe we could extend it to also support transformation of a type's properties?

Another way to make the nestjs plugin work would be (I think) to emit every class/interface into each own file.

Hope we can find a good solution for this problem.

Best regards, matthias

mojo2012 commented 3 years ago

I managed to write my own ClassDecoratorExtension that adds Reflect.metadata annotations to the class properties. But it feels this could be usedful to other people too. It would be nice to have this available by default. If needed I can share the source code.