Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ android {
lintOptions {
abortOnError false
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}

sourceSets {
Expand Down Expand Up @@ -62,6 +67,8 @@ dependencies {
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"

//implementation 'io.github.openfeign:feign-core:10.2.3'

implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
4 changes: 3 additions & 1 deletion generator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ dependencies {

compile 'com.squareup:kotlinpoet:1.3.0'
compile "io.reactivex.rxjava2:rxjava:2.2.10"
compile 'com.squareup.retrofit2:retrofit:2.6.0'

compileOnly 'com.squareup.retrofit2:retrofit:2.6.0'
compileOnly 'io.github.openfeign:feign-core:10.2.3'

def jacksonVersion = '2.8.4'
compile "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package com.schibsted.spain.retroswagger

import com.google.auto.service.AutoService
import com.schibsted.spain.retroswagger.annotation.Retroswagger
import com.schibsted.spain.retroswagger.lib.FeignApiBuilder
import com.schibsted.spain.retroswagger.lib.RetroswaggerErrorTracking
import com.schibsted.spain.retroswagger.lib.RetroswaggerApiBuilder
import com.schibsted.spain.retroswagger.lib.RetrofitApiBuilder
import com.schibsted.spain.retroswagger.lib.RetroswaggerApiConfiguration
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.TypeSpec
Expand Down Expand Up @@ -150,7 +151,33 @@ class RetroswaggerGenerator : AbstractProcessor() {
overrideInterfaceSlash
)

val kotlinApiBuilder = RetroswaggerApiBuilder(
val isRetrofitAvailable = try {
Class.forName("retrofit2.Retrofit")
true
} catch (exception: ClassNotFoundException) {
false
}

val isFeignAvailable = try {
Class.forName("feign.Param")
true
} catch (exception: ClassNotFoundException) {
false
}

if (isRetrofitAvailable) {
generateRetrofitCode(configuration, className, pack)
} else if (isFeignAvailable) {
generateFeignCode(configuration, className, pack)
}
}

private fun generateRetrofitCode(
configuration: RetroswaggerApiConfiguration,
className: String,
pack: String
) {
val kotlinApiBuilder = RetrofitApiBuilder(
configuration,
DummyRetroswaggerErrorTracking()
)
Expand All @@ -165,6 +192,27 @@ class RetroswaggerGenerator : AbstractProcessor() {
}
}

private fun generateFeignCode(
configuration: RetroswaggerApiConfiguration,
className: String,
pack: String
) {
val feignApiBuilder = FeignApiBuilder(
configuration,
DummyRetroswaggerErrorTracking()
)
feignApiBuilder.build()

generateClass(className, pack, feignApiBuilder.getGeneratedApiInterfaceTypeSpec())
for (typeSpec in feignApiBuilder.getGeneratedModelListTypeSpec()) {
generateClass(className, pack, typeSpec)
}
for (typeSpec in feignApiBuilder.getGeneratedEnumListTypeSpec()) {
generateClass(className, pack, typeSpec)
}
}


private fun generateClass(
className: String,
pack: String,
Expand Down
Loading