Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{{/-last}}{{/requiredVars}}{{#hasRequired}}{{#hasOptional}},
{{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>dataClassOptVar}}{{^-last}},
{{/-last}}{{/optionalVars}}
) {{/discriminator}}{{#parent}}: {{{.}}}{{/parent}}{
) {{/discriminator}}{{#parent}}: {{{.}}}{{#serializableModel}}, Serializable{{/serializableModel}}{{/parent}}{{#serializableModel}}: Serializable{{/serializableModel}}{
{{#discriminator}}
{{#requiredVars}}
{{>interfaceReqVar}}
Expand All @@ -33,4 +33,9 @@
@JsonProperty({{{value}}}) {{{name}}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
}
{{/isEnum}}{{/vars}}{{/hasEnums}}
{{#serializableModel}}
companion object {
private const val serialVersionUID: kotlin.Long = 1
}
{{/serializableModel}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package {{package}}
import java.util.Objects
{{#imports}}import {{import}}
{{/imports}}
{{#serializableModel}}
import java.io.Serializable
{{/serializableModel}}
{{#useBeanValidation}}
import {{javaxPackage}}.validation.constraints.DecimalMax
import {{javaxPackage}}.validation.constraints.DecimalMin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public void testSettersForConfigValues() throws Exception {
codegen.setServiceImplementation(true);
codegen.setUseBeanValidation(false);
codegen.setReactive(false);
codegen.setSerializableModel(true);
codegen.processOpts();

Assert.assertEquals(codegen.modelPackage(), "xx.yyyyyyyy.model");
Expand All @@ -206,6 +207,8 @@ public void testSettersForConfigValues() throws Exception {
Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.USE_BEANVALIDATION), false);
Assert.assertFalse(codegen.isReactive());
Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.REACTIVE), false);
Assert.assertTrue(codegen.isSerializableModel());
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.SERIALIZABLE_MODEL), true);
}

@Test
Expand Down Expand Up @@ -747,4 +750,35 @@ public void givenMultipartForm_whenGenerateReactiveServer_thenParameterAreCreate
"@Parameter(description = \"image to upload\") @Valid @RequestPart(\"image\", required = false) image: org.springframework.core.io.Resource?");

}
}

@Test
public void generateSerializableModel() throws Exception {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
String outputPath = output.getAbsolutePath().replace('\\', '/');

KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(CodegenConstants.SERIALIZABLE_MODEL, true);

ClientOptInput input = new ClientOptInput()
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/petstore.yaml"))
.config(codegen);
DefaultGenerator generator = new DefaultGenerator();

generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false");

generator.opts(input).generate();

assertFileContains(
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Pet.kt"),
"import java.io.Serializable",
") : Serializable{",
"private const val serialVersionUID: kotlin.Long = 1"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openapitools.model

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Email
Expand All @@ -23,7 +24,10 @@ data class Category(

@get:Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$")
@get:JsonProperty("name") val name: kotlin.String? = null
) {
) : Serializable{

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openapitools.model

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Email
Expand All @@ -25,7 +26,10 @@ data class ModelApiResponse(
@get:JsonProperty("type") val type: kotlin.String? = null,

@get:JsonProperty("message") val message: kotlin.String? = null
) {
) : Serializable{

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonValue
import java.io.Serializable
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Email
Expand Down Expand Up @@ -35,7 +36,7 @@ data class Order(
@get:JsonProperty("status") val status: Order.Status? = null,

@get:JsonProperty("complete") val complete: kotlin.Boolean? = false
) {
) : Serializable{

/**
* Order Status
Expand All @@ -48,5 +49,8 @@ data class Order(
@JsonProperty("delivered") delivered("delivered")
}

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonValue
import org.openapitools.model.Category
import org.openapitools.model.Tag
import java.io.Serializable
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Email
Expand Down Expand Up @@ -40,7 +41,7 @@ data class Pet(

@Deprecated(message = "")
@get:JsonProperty("status") val status: Pet.Status? = null
) {
) : Serializable{

/**
* pet status in the store
Expand All @@ -53,5 +54,8 @@ data class Pet(
@JsonProperty("sold") sold("sold")
}

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openapitools.model

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Email
Expand All @@ -22,7 +23,10 @@ data class Tag(
@get:JsonProperty("id") val id: kotlin.Long? = null,

@get:JsonProperty("name") val name: kotlin.String? = null
) {
) : Serializable{

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openapitools.model

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Email
Expand Down Expand Up @@ -40,7 +41,10 @@ data class User(
@get:JsonProperty("phone") val phone: kotlin.String? = null,

@get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null
) {
) : Serializable{

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openapitools.model

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
Expand All @@ -23,7 +24,10 @@ data class Category(

@get:Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$")
@get:JsonProperty("name") val name: kotlin.String? = null
) {
) : Serializable{

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openapitools.model

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
Expand All @@ -25,7 +26,10 @@ data class ModelApiResponse(
@get:JsonProperty("type") val type: kotlin.String? = null,

@get:JsonProperty("message") val message: kotlin.String? = null
) {
) : Serializable{

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonValue
import java.io.Serializable
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
Expand Down Expand Up @@ -35,7 +36,7 @@ data class Order(
@get:JsonProperty("status") val status: Order.Status? = null,

@get:JsonProperty("complete") val complete: kotlin.Boolean? = false
) {
) : Serializable{

/**
* Order Status
Expand All @@ -48,5 +49,8 @@ data class Order(
@JsonProperty("delivered") delivered("delivered")
}

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonValue
import org.openapitools.model.Category
import org.openapitools.model.Tag
import java.io.Serializable
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
Expand Down Expand Up @@ -40,7 +41,7 @@ data class Pet(

@Deprecated(message = "")
@get:JsonProperty("status") val status: Pet.Status? = null
) {
) : Serializable{

/**
* pet status in the store
Expand All @@ -53,5 +54,8 @@ data class Pet(
@JsonProperty("sold") sold("sold")
}

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openapitools.model

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
Expand All @@ -22,7 +23,10 @@ data class Tag(
@get:JsonProperty("id") val id: kotlin.Long? = null,

@get:JsonProperty("name") val name: kotlin.String? = null
) {
) : Serializable{

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openapitools.model

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
Expand Down Expand Up @@ -40,7 +41,10 @@ data class User(
@get:JsonProperty("phone") val phone: kotlin.String? = null,

@get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null
) {
) : Serializable{

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openapitools.model

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Email
Expand All @@ -25,7 +26,10 @@ data class Category(

@Schema(example = "null", description = "")
@get:JsonProperty("name") var name: kotlin.String? = null
) {
) : Serializable{

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openapitools.model

import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Email
Expand Down Expand Up @@ -29,7 +30,10 @@ data class ModelApiResponse(

@Schema(example = "null", description = "")
@get:JsonProperty("message") var message: kotlin.String? = null
) {
) : Serializable{

companion object {
private const val serialVersionUID: kotlin.Long = 1
}
}

Loading