Skip to content

Commit

Permalink
fix isKtor, update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Dec 14, 2024
1 parent f766f44 commit afdc831
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,15 @@ public void processOpts() {

String gradleBuildFile = "build.gradle";

if (isJavalin() || isKtor()) {
if (isJavalin() || isKtor2Or3()) {
gradleBuildFile = "build.gradle.kts";
}

supportingFiles.add(new SupportingFile(gradleBuildFile + ".mustache", "", gradleBuildFile));
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
supportingFiles.add(new SupportingFile("gradle.properties", "", "gradle.properties"));

if (isKtor()) {
if (isKtor2Or3()) {
additionalProperties.put(Constants.IS_KTOR, true);

supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt"));
Expand Down Expand Up @@ -445,7 +445,20 @@ private boolean isJavalin() {
return Constants.JAVALIN5.equals(library) || Constants.JAVALIN6.equals(library);
}

private boolean isKtor() {
private boolean isKtor2Or3() {
return Constants.KTOR.equals(library) || Constants.KTOR2.equals(library);
}

/**
* Returns true if latest version of ktor is used.
*
* @return true if latest veresion of ktor is used.
*/
private boolean isKtor() {
return Constants.KTOR.equals(library);
}

private boolean isKtor2() {
return Constants.KTOR2.equals(library);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
package org.openapitools.client.infrastructure

import com.squareup.moshi.Moshi

object Serializer {
@JvmStatic
val moshiBuilder: Moshi.Builder = Moshi.Builder()
.add(OffsetDateTimeAdapter())
.add(LocalDateTimeAdapter())
.add(LocalDateAdapter())
.add(UUIDAdapter())
.add(ByteArrayAdapter())
.add(URIAdapter())
.add(BigDecimalAdapter())
.add(BigIntegerAdapter())

@JvmStatic
val moshi: Moshi by lazy {
moshiBuilder.build()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Dockerfile
README.md
build.gradle.kts
gradle.properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun Route.PetApi() {
authenticate("petstore_auth") {
post<Paths.addPet> {

val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
val principal = call.authentication.principal<OAuthAccessTokenResponse>()


val exampleContentType = "application/json"
Expand Down Expand Up @@ -70,7 +70,7 @@ fun Route.PetApi() {
authenticate("petstore_auth") {
delete<Paths.deletePet> {

val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
val principal = call.authentication.principal<OAuthAccessTokenResponse>()


call.respond(HttpStatusCode.NotImplemented)
Expand All @@ -81,7 +81,7 @@ fun Route.PetApi() {
authenticate("petstore_auth") {
get<Paths.findPetsByStatus> {

val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
val principal = call.authentication.principal<OAuthAccessTokenResponse>()


val exampleContentType = "application/json"
Expand Down Expand Up @@ -131,7 +131,7 @@ fun Route.PetApi() {
authenticate("petstore_auth") {
get<Paths.findPetsByTags> {

val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
val principal = call.authentication.principal<OAuthAccessTokenResponse>()


val exampleContentType = "application/json"
Expand Down Expand Up @@ -181,7 +181,7 @@ fun Route.PetApi() {
authenticate("api_key") {
get<Paths.getPetById> {

val principal = call.authentication.principal<ApiPrincipal>()!!
val principal = call.authentication.principal<ApiPrincipal>()


val exampleContentType = "application/json"
Expand Down Expand Up @@ -215,7 +215,7 @@ fun Route.PetApi() {
authenticate("petstore_auth") {
put<Paths.updatePet> {

val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
val principal = call.authentication.principal<OAuthAccessTokenResponse>()


val exampleContentType = "application/json"
Expand Down Expand Up @@ -249,7 +249,7 @@ fun Route.PetApi() {
authenticate("petstore_auth") {
post<Paths.updatePetWithForm> {

val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
val principal = call.authentication.principal<OAuthAccessTokenResponse>()


call.respond(HttpStatusCode.NotImplemented)
Expand All @@ -260,7 +260,7 @@ fun Route.PetApi() {
authenticate("petstore_auth") {
post<Paths.uploadFile> {

val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
val principal = call.authentication.principal<OAuthAccessTokenResponse>()


val exampleContentType = "application/json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun Route.StoreApi() {
authenticate("api_key") {
get<Paths.getInventory> {

val principal = call.authentication.principal<ApiPrincipal>()!!
val principal = call.authentication.principal<ApiPrincipal>()


call.respond(HttpStatusCode.NotImplemented)
Expand All @@ -60,7 +60,7 @@ fun Route.StoreApi() {
}"""

when (exampleContentType) {
"application/json" -> call.respond(gson.fromJson(exampleContentString, empty::class.java))
"application/json" -> call.respondText(exampleContentType, ContentType.Application.Json)
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
Expand All @@ -79,7 +79,7 @@ fun Route.StoreApi() {
}"""

when (exampleContentType) {
"application/json" -> call.respond(gson.fromJson(exampleContentString, empty::class.java))
"application/json" -> call.respondText(exampleContentType, ContentType.Application.Json)
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fun Route.UserApi() {
authenticate("api_key") {
post<Paths.createUser> {

val principal = call.authentication.principal<ApiPrincipal>()!!
val principal = call.authentication.principal<ApiPrincipal>()


call.respond(HttpStatusCode.NotImplemented)
Expand All @@ -46,7 +46,7 @@ fun Route.UserApi() {
authenticate("api_key") {
post<Paths.createUsersWithArrayInput> {

val principal = call.authentication.principal<ApiPrincipal>()!!
val principal = call.authentication.principal<ApiPrincipal>()


call.respond(HttpStatusCode.NotImplemented)
Expand All @@ -57,7 +57,7 @@ fun Route.UserApi() {
authenticate("api_key") {
post<Paths.createUsersWithListInput> {

val principal = call.authentication.principal<ApiPrincipal>()!!
val principal = call.authentication.principal<ApiPrincipal>()


call.respond(HttpStatusCode.NotImplemented)
Expand All @@ -68,7 +68,7 @@ fun Route.UserApi() {
authenticate("api_key") {
delete<Paths.deleteUser> {

val principal = call.authentication.principal<ApiPrincipal>()!!
val principal = call.authentication.principal<ApiPrincipal>()


call.respond(HttpStatusCode.NotImplemented)
Expand All @@ -90,7 +90,7 @@ fun Route.UserApi() {
}"""

when (exampleContentType) {
"application/json" -> call.respond(gson.fromJson(exampleContentString, empty::class.java))
"application/json" -> call.respondText(exampleContentType, ContentType.Application.Json)
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
Expand All @@ -105,7 +105,7 @@ fun Route.UserApi() {
authenticate("api_key") {
get<Paths.logoutUser> {

val principal = call.authentication.principal<ApiPrincipal>()!!
val principal = call.authentication.principal<ApiPrincipal>()


call.respond(HttpStatusCode.NotImplemented)
Expand All @@ -116,7 +116,7 @@ fun Route.UserApi() {
authenticate("api_key") {
put<Paths.updateUser> {

val principal = call.authentication.principal<ApiPrincipal>()!!
val principal = call.authentication.principal<ApiPrincipal>()


call.respond(HttpStatusCode.NotImplemented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
package org.openapitools.server.models


import java.io.Serializable
import kotlinx.serialization.Serializable
/**
* A category for a pet
* @param id
* @param name
*/
@Serializable
data class Category(
val id: kotlin.Long? = null,
val name: kotlin.String? = null
) : Serializable
)
{
companion object {
private const val serialVersionUID: Long = 123
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@
package org.openapitools.server.models


import java.io.Serializable
import kotlinx.serialization.Serializable
/**
* Describes the result of uploading an image resource
* @param code
* @param type
* @param message
*/
@Serializable
data class ModelApiResponse(
val code: kotlin.Int? = null,
val type: kotlin.String? = null,
val message: kotlin.String? = null
) : Serializable
)
{
companion object {
private const val serialVersionUID: Long = 123
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package org.openapitools.server.models


import java.io.Serializable
import kotlinx.serialization.Serializable
/**
* An order for a pets from the pet store
* @param id
Expand All @@ -22,6 +22,7 @@ import java.io.Serializable
* @param status Order Status
* @param complete
*/
@Serializable
data class Order(
val id: kotlin.Long? = null,
val petId: kotlin.Long? = null,
Expand All @@ -30,11 +31,8 @@ data class Order(
/* Order Status */
val status: Order.Status? = null,
val complete: kotlin.Boolean? = false
) : Serializable
)
{
companion object {
private const val serialVersionUID: Long = 123
}
/**
* Order Status
* Values: placed,approved,delivered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package org.openapitools.server.models
import org.openapitools.server.models.Category
import org.openapitools.server.models.Tag

import java.io.Serializable
import kotlinx.serialization.Serializable
/**
* A pet for sale in the pet store
* @param name
Expand All @@ -24,6 +24,7 @@ import java.io.Serializable
* @param tags
* @param status pet status in the store
*/
@Serializable
data class Pet(
val name: kotlin.String,
val photoUrls: kotlin.collections.List<kotlin.String>,
Expand All @@ -32,11 +33,8 @@ data class Pet(
val tags: kotlin.collections.List<Tag>? = null,
/* pet status in the store */
val status: Pet.Status? = null
) : Serializable
)
{
companion object {
private const val serialVersionUID: Long = 123
}
/**
* pet status in the store
* Values: available,pending,sold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
package org.openapitools.server.models


import java.io.Serializable
import kotlinx.serialization.Serializable
/**
* A tag for a pet
* @param id
* @param name
*/
@Serializable
data class Tag(
val id: kotlin.Long? = null,
val name: kotlin.String? = null
) : Serializable
)
{
companion object {
private const val serialVersionUID: Long = 123
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package org.openapitools.server.models


import java.io.Serializable
import kotlinx.serialization.Serializable
/**
* A User who is purchasing from the pet store
* @param id
Expand All @@ -24,6 +24,7 @@ import java.io.Serializable
* @param phone
* @param userStatus User Status
*/
@Serializable
data class User(
val id: kotlin.Long? = null,
val username: kotlin.String? = null,
Expand All @@ -34,10 +35,7 @@ data class User(
val phone: kotlin.String? = null,
/* User Status */
val userStatus: kotlin.Int? = null
) : Serializable
)
{
companion object {
private const val serialVersionUID: Long = 123
}
}

0 comments on commit afdc831

Please sign in to comment.