[BUG] [KOTLIN] Fix default value generation for Kotlin Strings (#5776)

* fix default value generation for kotlin

* add updated pet templates

* Revert "add updated pet templates"

This reverts commit 7e8168ad

* regen pet store projects code
This commit is contained in:
Alex Buchkovsky
2020-04-05 20:30:03 +03:00
committed by GitHub
parent 3b495bab12
commit 166aae6fec
14 changed files with 94 additions and 75 deletions

View File

@@ -940,7 +940,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
} }
} else if (ModelUtils.isStringSchema(p)) { } else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) { if (p.getDefault() != null) {
return "'" + p.getDefault() + "'"; return "\"" + p.getDefault() + "\"";
} }
} }

View File

@@ -1 +1 @@
4.2.3-SNAPSHOT 4.3.1-SNAPSHOT

View File

@@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
mavenCentral() maven { url = uri("https://repo1.maven.org/maven2") }
} }
dependencies { dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.0.M3") classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.0.M3")
@@ -15,7 +15,7 @@ version = "1.0.0"
repositories { repositories {
jcenter() jcenter()
mavenCentral() maven { url = uri("https://repo1.maven.org/maven2") }
} }
tasks.withType<KotlinCompile> { tasks.withType<KotlinCompile> {
@@ -48,7 +48,7 @@ dependencies {
} }
repositories { repositories {
mavenCentral() maven { url = uri("https://repo1.maven.org/maven2") }
maven { url = uri("https://repo.spring.io/snapshot") } maven { url = uri("https://repo.spring.io/snapshot") }
maven { url = uri("https://repo.spring.io/milestone") } maven { url = uri("https://repo.spring.io/milestone") }
} }

View File

@@ -0,0 +1,19 @@
package org.openapitools.api
import org.springframework.web.context.request.NativeWebRequest
import javax.servlet.http.HttpServletResponse
import java.io.IOException
object ApiUtil {
fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) {
try {
val res = req.getNativeResponse(HttpServletResponse::class.java)
res.setCharacterEncoding("UTF-8")
res.addHeader("Content-Type", contentType)
res.getWriter().print(example)
} catch (e: IOException) {
throw RuntimeException(e)
}
}
}

View File

@@ -17,13 +17,13 @@ class DefaultExceptionHandler {
@ExceptionHandler(value = [ApiException::class]) @ExceptionHandler(value = [ApiException::class])
fun onApiException(ex: ApiException, response: HttpServletResponse): Unit = fun onApiException(ex: ApiException, response: HttpServletResponse): Unit =
response.sendError(ex.code, ex.message) response.sendError(ex.code, ex.message)
@ExceptionHandler(value = [NotImplementedError::class]) @ExceptionHandler(value = [NotImplementedError::class])
fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit = fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit =
response.sendError(HttpStatus.NOT_IMPLEMENTED.value()) response.sendError(HttpStatus.NOT_IMPLEMENTED.value())
@ExceptionHandler(value = [ConstraintViolationException::class]) @ExceptionHandler(value = [ConstraintViolationException::class])
fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit = fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit =
response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message }) response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message })
} }

View File

@@ -16,13 +16,13 @@ import io.swagger.annotations.ApiModelProperty
* @param id * @param id
* @param name * @param name
*/ */
data class Category ( data class Category(
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("id") var id: kotlin.Long? = null, @JsonProperty("id") var id: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("name") var name: kotlin.String? = null @JsonProperty("name") var name: kotlin.String? = null
) { ) {
} }

View File

@@ -17,16 +17,16 @@ import io.swagger.annotations.ApiModelProperty
* @param type * @param type
* @param message * @param message
*/ */
data class ModelApiResponse ( data class ModelApiResponse(
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("code") var code: kotlin.Int? = null, @JsonProperty("code") var code: kotlin.Int? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("type") var type: kotlin.String? = null, @JsonProperty("type") var type: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("message") var message: kotlin.String? = null @JsonProperty("message") var message: kotlin.String? = null
) { ) {
} }

View File

@@ -21,25 +21,25 @@ import io.swagger.annotations.ApiModelProperty
* @param status Order Status * @param status Order Status
* @param complete * @param complete
*/ */
data class Order ( data class Order(
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("id") var id: kotlin.Long? = null, @JsonProperty("id") var id: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("petId") var petId: kotlin.Long? = null, @JsonProperty("petId") var petId: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("quantity") var quantity: kotlin.Int? = null, @JsonProperty("quantity") var quantity: kotlin.Int? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("shipDate") var shipDate: java.time.OffsetDateTime? = null, @JsonProperty("shipDate") var shipDate: java.time.OffsetDateTime? = null,
@ApiModelProperty(example = "null", value = "Order Status") @ApiModelProperty(example = "null", value = "Order Status")
@JsonProperty("status") var status: Order.Status? = null, @JsonProperty("status") var status: Order.Status? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("complete") var complete: kotlin.Boolean? = null @JsonProperty("complete") var complete: kotlin.Boolean? = null
) { ) {
/** /**

View File

@@ -23,27 +23,27 @@ import io.swagger.annotations.ApiModelProperty
* @param tags * @param tags
* @param status pet status in the store * @param status pet status in the store
*/ */
data class Pet ( data class Pet(
@get:NotNull @get:NotNull
@ApiModelProperty(example = "doggie", required = true, value = "") @ApiModelProperty(example = "doggie", required = true, value = "")
@JsonProperty("name") var name: kotlin.String, @JsonProperty("name") var name: kotlin.String,
@get:NotNull @get:NotNull
@ApiModelProperty(example = "null", required = true, value = "") @ApiModelProperty(example = "null", required = true, value = "")
@JsonProperty("photoUrls") var photoUrls: kotlin.collections.List<kotlin.String>, @JsonProperty("photoUrls") var photoUrls: kotlin.collections.List<kotlin.String>,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("id") var id: kotlin.Long? = null, @JsonProperty("id") var id: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("category") var category: Category? = null, @JsonProperty("category") var category: Category? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("tags") var tags: kotlin.collections.List<Tag>? = null, @JsonProperty("tags") var tags: kotlin.collections.List<Tag>? = null,
@ApiModelProperty(example = "null", value = "pet status in the store") @ApiModelProperty(example = "null", value = "pet status in the store")
@JsonProperty("status") var status: Pet.Status? = null @JsonProperty("status") var status: Pet.Status? = null
) { ) {
/** /**

View File

@@ -16,13 +16,13 @@ import io.swagger.annotations.ApiModelProperty
* @param id * @param id
* @param name * @param name
*/ */
data class Tag ( data class Tag(
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("id") var id: kotlin.Long? = null, @JsonProperty("id") var id: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("name") var name: kotlin.String? = null @JsonProperty("name") var name: kotlin.String? = null
) { ) {
} }

View File

@@ -22,31 +22,31 @@ import io.swagger.annotations.ApiModelProperty
* @param phone * @param phone
* @param userStatus User Status * @param userStatus User Status
*/ */
data class User ( data class User(
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("id") var id: kotlin.Long? = null, @JsonProperty("id") var id: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("username") var username: kotlin.String? = null, @JsonProperty("username") var username: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("firstName") var firstName: kotlin.String? = null, @JsonProperty("firstName") var firstName: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("lastName") var lastName: kotlin.String? = null, @JsonProperty("lastName") var lastName: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("email") var email: kotlin.String? = null, @JsonProperty("email") var email: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("password") var password: kotlin.String? = null, @JsonProperty("password") var password: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "") @ApiModelProperty(example = "null", value = "")
@JsonProperty("phone") var phone: kotlin.String? = null, @JsonProperty("phone") var phone: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "User Status") @ApiModelProperty(example = "null", value = "User Status")
@JsonProperty("userStatus") var userStatus: kotlin.Int? = null @JsonProperty("userStatus") var userStatus: kotlin.Int? = null
) { ) {
} }

View File

@@ -1 +1 @@
4.2.1-SNAPSHOT 4.3.1-SNAPSHOT

View File

@@ -7,7 +7,7 @@
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>OpenAPI Petstore</name> <name>OpenAPI Petstore</name>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -187,4 +187,4 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@@ -20,10 +20,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonInclude
/** /**
* A pet for sale in the pet store * A pet for sale in the pet store
* @param id
* @param category
* @param name * @param name
* @param photoUrls * @param photoUrls
* @param id
* @param category
* @param tags * @param tags
* @param status pet status in the store * @param status pet status in the store
*/ */