Skip to content

New generator: kotlin-retrofit (lightweight, Android, coroutines) #3195

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

Closed
wants to merge 15 commits into from

Conversation

kroegerama
Copy link
Contributor

See #3135

* KotlinRetrofitCodegen no more uses AbstractKotlinCodegen (has wrong reserved word list)
* support for default values for Api parameters
@auto-labeler
Copy link

auto-labeler bot commented Jun 21, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Member

wing328 commented Jun 24, 2019

@kroegerama thanks for contributing a new generator.

Have you considered incorporating the retrofit support via a --library option to the existing kotlin client generator?

The current java client generator supports many HTTP libraries via the --library option.

@wing328
Copy link
Member

wing328 commented Jun 24, 2019

cc Kotlin tech committe: @jimschubert (2017/09) , @dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04)

@wing328 wing328 modified the milestones: 4.0.3, 4.1.0 Jul 9, 2019

import static org.openapitools.codegen.utils.StringUtils.*;

public class KotlinRetrofitCodegen extends DefaultCodegen implements CodegenConfig {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess AbstractKotlinCodegen should be used here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. AbstractKotlinCodegen has some wrong implementations. See my explanation here which is just one error I found in the abstract class.
We could merge the corrections in my Codegen into AbstractKotlinCodegen, though.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix found error in AbstractKotlinCodegen is the right option. Plus, it can be done in separate PR to make contributions smaller -> get reviews easier -> merge faster.

BTW it's a nice contribution, looking forward to it 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with @MatkovIvan to fix the bug in AbstractKotlinCodegen instead.

@snackycracky
Copy link

hey, thanks for the effort. Would be awesome if any kind of authenticationScheme is supported :)

@wing328 wing328 modified the milestones: 4.1.0, 4.1.1 Aug 9, 2019
@wing328 wing328 modified the milestones: 4.1.1, 4.1.2 Aug 26, 2019
@jakoss
Copy link

jakoss commented Sep 6, 2019

Hey. Great idea you have there. Do you have any ETA on release? Maybe i could somehow help push this further?

@wing328 wing328 modified the milestones: 4.1.2, 4.1.3 Sep 11, 2019
@craigmurray1120
Copy link

Would love to see this generator gets merged into master.

Thank you @kroegerama for his awesome work.

merge from OpenAPITools/openapi-generator master
@wing328 wing328 modified the milestones: 4.1.3, 4.2.0 Oct 4, 2019
@wing328 wing328 removed this from the 4.2.0 milestone Oct 30, 2019
* add retrofit scalars converter for simple types
* only add HttpLoggingInterceptor in Debug builds
* initialize OkHttpClient lazy on non-main thread (see https://www.zacsweers.dev/dagger-party-tricks-deferred-okhttp-init/)
setCollectionType(additionalProperties.get(COLLECTION_TYPE).toString());
}

if (CollectionType.LIST.value.equals(collectionType)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a warning that we're modifying typeMappings at this point, because it'll beak user's ability to define type mappings when using generator defaults.

import retrofit2.create
import retrofit2.http.*
import okhttp3.*
import retrofit2.http.Headers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary with the glob import above?

supportingFiles.add(new SupportingFile("proguard-rules.pro.mustache", "", "proguard-rules.pro"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));

supportingFiles.add(new SupportingFile("AndroidManifest.xml.mustache", "src/main", "AndroidManifest.xml"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we may want to put Android options behind a CLI option. I scanned and didn't see any Android specific code in client files.

@jimschubert
Copy link
Member

I agree that this would make more sense as a library option to the existing client generator. It seems that one of the major reasons it wasn't was because some keywords (like data) are set as reserved but disallowed for variables. Many of these aren't allowed elsewhere (can't recall exactly, but I think as Enums), so I think any special casing logic makes the most sense in the base class to benefit all Kotlin generators.

What might you need from the core team to get this into master? Maybe we could do it as a separate Beta generator and move to a library option later?

@wing328
Copy link
Member

wing328 commented Dec 14, 2019

Here is another PR to add retrofit2 as a library option to the Kotlin client generator: #4518

@wing328
Copy link
Member

wing328 commented Dec 22, 2019

#4518 has been merged into master.

Please give it a try. Closing this one for the time being.

@wing328 wing328 closed this Dec 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants