https://kotlinlang.org logo
Title
h

Horv

03/14/2019, 8:58 AM
Sorry, I'm not sure which channels is appropriate for this question, please redirect if there's a better place. We're building a backend webservices using Spring Boot + Kotlin and consumes different artifacts with domain models (mixed Java and Kotlin sources). I'd like to make it as easy as possible for our frontend development to consume the API and is looking into putting out a TypeScript-klient as part of the project or at least TypeScript-definitions. Has anyone done something similar and can give any pointers to good tools to use to convert Java/Kotlin-classes to TypeScript-definitions? Only thing I've found so far is https://github.com/ntrrgc/ts-generator
t

tapchicoma

03/14/2019, 12:26 PM
this is you best choice so far. Also see https://youtrack.jetbrains.com/issue/KT-16604
h

Horv

03/14/2019, 12:41 PM
Alrighty, I'll test out ts-generator than and see how it works.
m

Mike

03/14/2019, 12:43 PM
Have you considered producing an OpenAPI spec? Then there are several model/client/server generators that any client could use.
h

Horv

03/14/2019, 12:47 PM
Yes, we do utilize Springfox to produce swagger (i.e OpenAPI) in our other services. But it leaves quite a few things to be desired. The result often loses information or we have to tweak a lot of both Springfox/Swagger-configuration on how to interpret things, especially with generics and clashing names of classes that exists in different packages. In essence, stuff get's lost in translation. And when you then add a generator on the OpenAPI-spec there's another transformation and information-loss layer. I was hoping to find a way with one less layer. We've been using https://github.com/swagger-api/swagger-codegen for the client generation, but that as well is far from perfect. Maybe there's some better TS-alternatives out there?
m

Mike

03/14/2019, 1:11 PM
We develop our services API first, so we use that to generate code rather than our code generating the API. Pros and cons to both of course. Part of the reason is I don’t like having Springfox in the dependency tree. Bloats the Jar file AND memory usage for each instance of the Service. I’d strongly suggest dropping swagger-codegen and moving to https://github.com/OpenAPITools/openapi-generator. Quick backstory. Most of the contributors to openapi-generator worked on swagger-codegen but didn’t like the direction SmartBear was taking with the generator when they took over. So it started as a fork, and is now much better. Supports both V2 and V3 specs with one generator for starters. But if you’re working with a generated API, then it doesn’t really help with your original problem.
h

Horv

03/14/2019, 4:07 PM
Ah, cool. I did not know about OpenAPITools. I'll look into it. It could probably help our other projects with improving generation of Typescript etc if nothing else.