Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Kotlin generator? #539

Open
michaelcarrano opened this issue Jun 17, 2019 · 2 comments
Open

Add new Kotlin generator? #539

michaelcarrano opened this issue Jun 17, 2019 · 2 comments

Comments

@michaelcarrano
Copy link

I am looking into adopting ApiBuilder and to leverage the generators in client side apps. I mainly deal with Android.

Our Android stack makes use of:
Kotlin
RxJava2
Retrofit2
Moshi

I noticed the Kotlin generator that currently exists uses most of the same stack but uses Jackson instead for de/serializing of Json.

Any advice if I want to create a new client to use Moshi instead? What about being able to configure the generator so that the client can use Moshi, Gson, or Jackson?

@gheine
Copy link
Collaborator

gheine commented Jun 18, 2019

Hi, the preference would definitely be to extend the existing generator and make it flexible to use different json serialization libraries. The config which code to generate can be passed in via attributes on the invocation_form, see https://app.apibuilder.io/apicollective/apibuilder-generator/0.14.85#model-invocation_form

For example the scala generators make use of this to be able to choose between play-json and circe and between joda and java-time libraries for date and datetime types. See https://github.com/apicollective/apibuilder-generator/blob/master/scala-generator/src/main/scala/models/Config.scala

@EDLuke
Copy link
Collaborator

EDLuke commented Aug 20, 2019

To create a new generator under apibuilder-generator, take a look at #558

To create a new Kotlin generator, I can think of a few ways:

  1. Rename the existing KotlinGenerator to be KotlinJacksonGenerator and create a new KotlinMoshiGenerator that is similar to the jackson one.
  2. Refactor the KotlinGenerator to take some config. The majority of the generated code still can be used (Retrofit2, RxJava2).

As for the difference between Jackson and Moshi, the generator itself doesn't really use Jackson but rather generates stuff like com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME which can be swapped (I think?) to use the Moshi equivalent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants