RedSeal-co / ts-java

Create TypeScript declaration files for Java packages.
MIT License
64 stars 15 forks source link

Using ts-java to generate .d.ts files for consuming REST APIs #35

Open joeskeen opened 8 years ago

joeskeen commented 8 years ago

I know that this project will generate .d.ts files that work well with node-java, but how well will this work to generate .d.ts files for consuming REST APIs? For my project at work, we use Java on the back end and JavaScript on the front end, and REST APIs (spring-boot based) to communicate between the server and the client. All of the requests and responses are using domain object classes on the Java side, and it would be nice to be able to generate TypeScript definition files for them.

One main difference I see with this use case is that when you are dealing with REST and JSON, you no longer care about the native Java types (String, boolean, integer, etc), and won't need any definitions describing any base Java framework classes or types. Here I would only be concerned about the domain object classes, and translate types to the type it would be in JSON (for example, any collection would just become an array in JSON, int just becomes number, etc.).

Is this a use case that this tool could accommodate, or how much work would be involved in allowing this? I would rather not start my own project for this as it seems that a lot of the work has already been completed with your tool. If you need any help with it, I would also be willing to contribute.

dan-madaket commented 8 years ago

I would be interested in the answer to this too... @joeskeen did you ever try it for that?

joeskeen commented 8 years ago

@dan-madaket I did actually get a solution to work for my project at work, although I didn't end up using this ts-java. I created a small package that used https://github.com/vojtechhabarta/typescript-generator and https://github.com/joeferner/node-java together to accomplish what I needed. It has worked very well for the use case I described previously. The code for this is currently closed source, but I could look into getting Intermountain Healthcare to open source it if there's community interest.