-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
493 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
api/src/main/java/com/example/openapigenerationtestapi/infrastructure/ApiClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.example.openapigenerationtestapi.infrastructure | ||
|
||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.scalars.ScalarsConverterFactory | ||
import retrofit2.converter.moshi.MoshiConverterFactory | ||
|
||
class ApiClient( | ||
private var baseUrl: String = defaultBasePath, | ||
private var okHttpClient: OkHttpClient | ||
) { | ||
companion object { | ||
@JvmStatic | ||
val defaultBasePath: String by lazy { | ||
System.getProperties().getProperty("com.example.openapigenerationtestapi.baseUrl", "https://qiita.com/api/v2") | ||
} | ||
} | ||
|
||
init { | ||
normalizeBaseUrl() | ||
} | ||
|
||
val retrofitBuilder: Retrofit.Builder by lazy { | ||
|
||
Retrofit.Builder() | ||
.baseUrl(baseUrl) | ||
.addConverterFactory(ScalarsConverterFactory.create()) | ||
.addConverterFactory(MoshiConverterFactory.create(Serializer.moshi)) | ||
} | ||
|
||
fun <S> createService(serviceClass: Class<S>): S { | ||
return retrofitBuilder.client(okHttpClient).build().create(serviceClass) | ||
} | ||
|
||
private fun normalizeBaseUrl() { | ||
if (!baseUrl.endsWith("/")) { | ||
baseUrl += "/" | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
api/src/main/java/com/example/openapigenerationtestapi/infrastructure/ByteArrayAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.openapigenerationtestapi.infrastructure | ||
|
||
import com.squareup.moshi.FromJson | ||
import com.squareup.moshi.ToJson | ||
|
||
class ByteArrayAdapter { | ||
@ToJson | ||
fun toJson(data: ByteArray): String = String(data) | ||
|
||
@FromJson | ||
fun fromJson(data: String): ByteArray = data.toByteArray() | ||
} |
56 changes: 56 additions & 0 deletions
56
api/src/main/java/com/example/openapigenerationtestapi/infrastructure/CollectionFormats.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.example.openapigenerationtestapi.infrastructure | ||
|
||
class CollectionFormats { | ||
|
||
open class CSVParams { | ||
|
||
var params: List<String> | ||
|
||
constructor(params: List<String>) { | ||
this.params = params | ||
} | ||
|
||
constructor(vararg params: String) { | ||
this.params = listOf(*params) | ||
} | ||
|
||
override fun toString(): String { | ||
return params.joinToString(",") | ||
} | ||
} | ||
|
||
open class SSVParams : CSVParams { | ||
|
||
constructor(params: List<String>) : super(params) | ||
|
||
constructor(vararg params: String) : super(*params) | ||
|
||
override fun toString(): String { | ||
return params.joinToString(" ") | ||
} | ||
} | ||
|
||
class TSVParams : CSVParams { | ||
|
||
constructor(params: List<String>) : super(params) | ||
|
||
constructor(vararg params: String) : super(*params) | ||
|
||
override fun toString(): String { | ||
return params.joinToString("\t") | ||
} | ||
} | ||
|
||
class PIPESParams : CSVParams { | ||
|
||
constructor(params: List<String>) : super(params) | ||
|
||
constructor(vararg params: String) : super(*params) | ||
|
||
override fun toString(): String { | ||
return params.joinToString("|") | ||
} | ||
} | ||
|
||
class SPACEParams : SSVParams() | ||
} |
19 changes: 19 additions & 0 deletions
19
api/src/main/java/com/example/openapigenerationtestapi/infrastructure/LocalDateAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.openapigenerationtestapi.infrastructure | ||
|
||
import com.squareup.moshi.FromJson | ||
import com.squareup.moshi.ToJson | ||
import java.time.LocalDate | ||
import java.time.format.DateTimeFormatter | ||
|
||
class LocalDateAdapter { | ||
@ToJson | ||
fun toJson(value: LocalDate): String { | ||
return DateTimeFormatter.ISO_LOCAL_DATE.format(value) | ||
} | ||
|
||
@FromJson | ||
fun fromJson(value: String): LocalDate { | ||
return LocalDate.parse(value, DateTimeFormatter.ISO_LOCAL_DATE) | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...src/main/java/com/example/openapigenerationtestapi/infrastructure/LocalDateTimeAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.openapigenerationtestapi.infrastructure | ||
|
||
import com.squareup.moshi.FromJson | ||
import com.squareup.moshi.ToJson | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
class LocalDateTimeAdapter { | ||
@ToJson | ||
fun toJson(value: LocalDateTime): String { | ||
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value) | ||
} | ||
|
||
@FromJson | ||
fun fromJson(value: String): LocalDateTime { | ||
return LocalDateTime.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME) | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...rc/main/java/com/example/openapigenerationtestapi/infrastructure/OffsetDateTimeAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.openapigenerationtestapi.infrastructure | ||
|
||
import com.squareup.moshi.FromJson | ||
import com.squareup.moshi.ToJson | ||
import java.time.OffsetDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
class OffsetDateTimeAdapter { | ||
@ToJson | ||
fun toJson(value: OffsetDateTime): String { | ||
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value) | ||
} | ||
|
||
@FromJson | ||
fun fromJson(value: String): OffsetDateTime { | ||
return OffsetDateTime.parse(value, DateTimeFormatter.ISO_OFFSET_DATE_TIME) | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
api/src/main/java/com/example/openapigenerationtestapi/infrastructure/Serializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.openapigenerationtestapi.infrastructure | ||
|
||
import com.squareup.moshi.Moshi | ||
import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter | ||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory | ||
import java.util.Date | ||
|
||
object Serializer { | ||
@JvmStatic | ||
val moshiBuilder: Moshi.Builder = Moshi.Builder() | ||
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe()) | ||
.add(OffsetDateTimeAdapter()) | ||
.add(LocalDateTimeAdapter()) | ||
.add(LocalDateAdapter()) | ||
.add(UUIDAdapter()) | ||
.add(ByteArrayAdapter()) | ||
.add(KotlinJsonAdapterFactory()) | ||
|
||
@JvmStatic | ||
val moshi: Moshi by lazy { | ||
moshiBuilder.build() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
api/src/main/java/com/example/openapigenerationtestapi/infrastructure/UUIDAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.openapigenerationtestapi.infrastructure | ||
|
||
import com.squareup.moshi.FromJson | ||
import com.squareup.moshi.ToJson | ||
import java.util.UUID | ||
|
||
class UUIDAdapter { | ||
@ToJson | ||
fun toJson(uuid: UUID) = uuid.toString() | ||
|
||
@FromJson | ||
fun fromJson(s: String) = UUID.fromString(s) | ||
} |
16 changes: 16 additions & 0 deletions
16
api/src/main/java/com/example/openapigenerationtestapi/sp/api/ItemApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.example.openapigenerationtestapi.sp.api | ||
|
||
import com.example.openapigenerationtestapi.infrastructure.CollectionFormats.* | ||
import retrofit2.http.* | ||
import retrofit2.Call | ||
import okhttp3.RequestBody | ||
import okhttp3.ResponseBody | ||
import okhttp3.MultipartBody | ||
|
||
import com.example.openapigenerationtestapi.sp.model.Item | ||
|
||
interface ItemApi { | ||
@GET("/api/v2/items") | ||
fun getAllItems(@Query("page") page: kotlin.String, @Query("per_page") perPage: kotlin.String, @Query("query") query: kotlin.String): Call<kotlin.Array<Item>> | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
api/src/main/java/com/example/openapigenerationtestapi/sp/api/UserApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.openapigenerationtestapi.sp.api | ||
|
||
import com.example.openapigenerationtestapi.infrastructure.CollectionFormats.* | ||
import retrofit2.http.* | ||
import retrofit2.Call | ||
import okhttp3.RequestBody | ||
import okhttp3.ResponseBody | ||
import okhttp3.MultipartBody | ||
|
||
import com.example.openapigenerationtestapi.sp.model.User | ||
|
||
interface UserApi { | ||
@GET("/api/v2/users") | ||
fun getAllUser(@Query("page") page: kotlin.String, @Query("per_page") perPage: kotlin.String): Call<kotlin.Array<User>> | ||
|
||
@GET("/api/v2/users/{user_id}") | ||
fun getUser(@Path("user_id") userId: kotlin.String): Call<User> | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
api/src/main/java/com/example/openapigenerationtestapi/sp/model/Group.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* OpenAPI Generator test with Qiita API | ||
* Qiita API を用いたOpenAPI Generator のテストです。 | ||
* | ||
* The version of the OpenAPI document: 0.0.0 | ||
* | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
package com.example.openapigenerationtestapi.sp.model | ||
|
||
|
||
import com.squareup.moshi.Json | ||
/** | ||
* Qiita Teamのグループを表します。 | ||
* @param createdAt データが作成された日時 | ||
* @param id グループの一意なIDを表します。 | ||
* @param name グループに付けられた表示用の名前を表します。 | ||
* @param private 非公開グループかどうかを表します。 | ||
* @param updatedAt データが最後に更新された日時 | ||
* @param urlName グループのチーム上での一意な名前を表します。 | ||
*/ | ||
|
||
data class Group ( | ||
/* データが作成された日時 */ | ||
@Json(name = "created_at") | ||
val createdAt: java.time.OffsetDateTime? = null, | ||
/* グループの一意なIDを表します。 */ | ||
@Json(name = "id") | ||
val id: kotlin.Int? = null, | ||
/* グループに付けられた表示用の名前を表します。 */ | ||
@Json(name = "name") | ||
val name: kotlin.String? = null, | ||
/* 非公開グループかどうかを表します。 */ | ||
@Json(name = "private") | ||
val private: kotlin.Boolean? = null, | ||
/* データが最後に更新された日時 */ | ||
@Json(name = "updated_at") | ||
val updatedAt: java.time.OffsetDateTime? = null, | ||
/* グループのチーム上での一意な名前を表します。 */ | ||
@Json(name = "url_name") | ||
val urlName: kotlin.String? = null | ||
) | ||
|
87 changes: 87 additions & 0 deletions
87
api/src/main/java/com/example/openapigenerationtestapi/sp/model/Item.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* OpenAPI Generator test with Qiita API | ||
* Qiita API を用いたOpenAPI Generator のテストです。 | ||
* | ||
* The version of the OpenAPI document: 0.0.0 | ||
* | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
package com.example.openapigenerationtestapi.sp.model | ||
|
||
import com.example.openapigenerationtestapi.sp.model.Group | ||
import com.example.openapigenerationtestapi.sp.model.Tag | ||
import com.example.openapigenerationtestapi.sp.model.User | ||
|
||
import com.squareup.moshi.Json | ||
/** | ||
* ユーザからの投稿を表します。 | ||
* @param renderedBody HTML形式の本文 | ||
* @param body Markdown形式の本文 | ||
* @param coediting この記事が共同更新状態かどうか (Qiita Teamでのみ有効) | ||
* @param commentsCount この記事へのコメントの数 | ||
* @param createdAt データが作成された日時 | ||
* @param group | ||
* @param id 記事の一意なID | ||
* @param likesCount この記事への「LGTM!」の数(Qiitaでのみ有効) | ||
* @param private 限定共有状態かどうかを表すフラグ (Qiita Teamでは無効) | ||
* @param reactionsCount 絵文字リアクションの数(Qiita Teamでのみ有効) | ||
* @param tags 記事に付いたタグ一覧 | ||
* @param title 記事のタイトル | ||
* @param updatedAt データが最後に更新された日時 | ||
* @param url 記事のURL | ||
* @param user | ||
* @param pageViewsCount 閲覧数 | ||
*/ | ||
|
||
data class Item ( | ||
/* HTML形式の本文 */ | ||
@Json(name = "rendered_body") | ||
val renderedBody: kotlin.String? = null, | ||
/* Markdown形式の本文 */ | ||
@Json(name = "body") | ||
val body: kotlin.String? = null, | ||
/* この記事が共同更新状態かどうか (Qiita Teamでのみ有効) */ | ||
@Json(name = "coediting") | ||
val coediting: kotlin.Boolean? = null, | ||
/* この記事へのコメントの数 */ | ||
@Json(name = "comments_count") | ||
val commentsCount: kotlin.Int? = null, | ||
/* データが作成された日時 */ | ||
@Json(name = "created_at") | ||
val createdAt: java.time.OffsetDateTime? = null, | ||
@Json(name = "group") | ||
val group: Group? = null, | ||
/* 記事の一意なID */ | ||
@Json(name = "id") | ||
val id: kotlin.String? = null, | ||
/* この記事への「LGTM!」の数(Qiitaでのみ有効) */ | ||
@Json(name = "likes_count") | ||
val likesCount: kotlin.Int? = null, | ||
/* 限定共有状態かどうかを表すフラグ (Qiita Teamでは無効) */ | ||
@Json(name = "private") | ||
val private: kotlin.Boolean? = null, | ||
/* 絵文字リアクションの数(Qiita Teamでのみ有効) */ | ||
@Json(name = "reactions_count") | ||
val reactionsCount: kotlin.Int? = null, | ||
/* 記事に付いたタグ一覧 */ | ||
@Json(name = "tags") | ||
val tags: kotlin.Array<Tag>? = null, | ||
/* 記事のタイトル */ | ||
@Json(name = "title") | ||
val title: kotlin.String? = null, | ||
/* データが最後に更新された日時 */ | ||
@Json(name = "updated_at") | ||
val updatedAt: java.time.OffsetDateTime? = null, | ||
/* 記事のURL */ | ||
@Json(name = "url") | ||
val url: kotlin.String? = null, | ||
@Json(name = "user") | ||
val user: User? = null, | ||
/* 閲覧数 */ | ||
@Json(name = "page_views_count") | ||
val pageViewsCount: kotlin.Int? = null | ||
) | ||
|
Oops, something went wrong.