raphaeljolivet / java2typescript

A bridge between a Java model, REST services and Typescript definition
Apache License 2.0
129 stars 47 forks source link

support gradle plugin #15

Open raDiesle opened 8 years ago

raDiesle commented 8 years ago

supporting gradle plugin would be great

dhasilin commented 8 years ago

Vote for that :+1:

atsu85 commented 8 years ago

Hi, @raDiesle and @Kravs, what would be the requirements for this plugin? What would be Your use-case? I'm afraid that my use-case for this plugin might differ very much from Yours.

Pull requests are really welcome here, but I'm afraid that neither me nor the creator of this library (@raphaeljolivet) has personal use-case for it (and therefor lack of interest in personally developing that plugin).

I've done a lot of development in this repository to fulfill my own project needs, but most of them are related to java2typescript-jackson subproject, as i'm not using JAX-RS or maven plugin. So while I'm using Gradle, i'm not interested in Gradle plugin, that works the same way as java2typescript-maven-plugin.

dhasilin commented 8 years ago

For me it would be nice to simply transpile my POJO Java objects form some specific package to TS and put them in UI app folder on every build, so I could use them on UI...

Is that sounds realistic ? :)

atsu85 commented 8 years ago

@Kravs, so basically You just need a wrapper around java2typescript-jackson.

I'm writing down some initial thoughts about this feature, that could become basis for configuration options.

Main inputs:

Java2typescript-jackson has several configuration options:

Some of the configuration options are not just a matter of choosing smth out of given options, but setting an implementation for smth, for example naming strategy.

Also one might want to prepend smth to the beginning of generated file (for example some comments to disable tslint rules for this file, instead of excluding the whole file) - probably plugin doesn't need to handle it.

dhasilin commented 8 years ago

@atsu85 Well I'm not familiar with such deep details, but I'm open to provide help if needed. Unfortunately I'm not quite expert in it :( But it would be really nice to have such scenariao:

  1. Add gradle plugin
  2. Configure package to transpile and output folder (all other options could have some defaults)
  3. get those file generated on each builds...

I can see that "java2typescript-jackson" is in java so I suppose I could help. but I'm not sure why it is called Jackson ?:) Also I'm not sure about "Java classes are converted to TypeScript interfaces." - implementation is ignored ? :(

UPDATE:

Sorry for confusing :) Now I'm walked through the code, and understand that this project generates only Data objects and enums (with different approaches) so that is useful for Client - service communication.... Also now I'm understand how to create gradle plugin for it (tests are the best documentation) ....

I'm thinking if it is really needed for me, because I'd like to have methods implementation... maybe you have any suggestion for me, where to look for possibilities to parse implementation code ?

atsu85 commented 8 years ago

@Kravs, I'm not sure, if after Your updates in comments You got the answers to Your questions or not, but I'll try to answer/comment some of them:

but I'm not sure why it is called Jackson

That is because Jackson is used to create to model that contains information about classes (fields, methods and even constants, if configured so) and enums.

Also I'm not sure about "Java classes are converted to TypeScript interfaces." - implementation is ignored ? :(

That is because the classes, that You should feed into the "TypeScript declarations generator", should be POJOs - there is no room for the implementation, just the structure. TypeScript interfaces perfectly describe the structure of Java POJOs. I don't really understand where could You benefit from the implementation for generated TypeScript declarations?

I'm thinking if it is really needed for me, because I'd like to have methods implementation...

Could You explain, what would be the use-case where You'll need the method implementations?

raDiesle commented 8 years ago

Hi you,

my use case is, that instead of using the mvn plugin (https://github.com/raphaeljolivet/java2typescript/tree/master/java2typescript-maven-plugin), i'd like to use it as a gradle plugin, because current project is a gradle project. The same kind of configurations then in the mvn plugin are required, so that we can run it as task in ci build easily. http://gradle.org/migrating-a-maven-build-to-gradle/

dhasilin commented 8 years ago

@atsu85 I got answers, but thank you for explaining in details :)

Use case for method implementation: 1) load domain object from DB (called aggregate in Domain Driven Design) 2) pass it to front end 3) User manipulates it (business rules ("hows") are in methods) 4)user send result object to Back End, and it saved after validation. Does it make sense ?

atsu85 commented 8 years ago

@raDiesle, do I understand correctly, that You are using JAX-RS to implement backend-api endpoints/controllers?

atsu85 commented 8 years ago

@Kravs, I'm quoting You

For me it would be nice to simply transpile my POJO Java objects form some specific package to TS and put them in UI app folder on every build, so I could use them on UI...

This is exactly what java2typescript-jackson subproject does - creates TypeScript types based on POJOs (Java classes that don't serve any other special role nor implement interfaces of any of the Java frameworks, nothing related to implementation).

I'm not sure about "Java classes are converted to TypeScript interfaces." - implementation is ignored ? :(

POJOs have nothing to do with implementation (except getting/setting the field value, and You don't need implementation for that when converting class to TypeScript - just structure of the Java class represented as TypeScript interface with fields).

Use case for method implementation: 1) load domain object from DB (called aggregate in Domain Driven Design) 2) pass it to front end 3) User manipulates it (business rules ("hows") are in methods) 4) user send result object to Back End, and it saved after validation. Does it make sense ?

This only makes sense, if You say, that in addition to what You said previously, You also want to generate JavaScript or TypeScript for api-client, that sends http requests to Your backend API. If this is the case, then You really want smth quite similar to java2typescript-maven-plugin, that uses both java2typescript-jackson and java2typescript-jaxrs (expects You have written Your backend API endpoints/controllers with JAX-RS).

I hope I was able to clear some misunderstanding generated here meanwhile.

So what do You actually need?