generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 18
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
12 changed files
with
652 additions
and
18 deletions.
There are no files selected for viewing
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
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
21 changes: 21 additions & 0 deletions
21
doc-examples/example-kotlin-ksp/src/main/kotlin/example/openapi/test/api/RequestBodyApi.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,21 @@ | ||
package example.openapi.test.api | ||
|
||
import io.micronaut.http.annotation.Body | ||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Put | ||
import example.openapi.test.model.Animal | ||
|
||
@Controller | ||
interface RequestBodyApi { | ||
|
||
/** | ||
* A method to send a model with discriminator in body | ||
* | ||
* @param animal (required) | ||
* @return Animal | ||
*/ | ||
@Put("/sendModelWithDiscriminator") | ||
fun sendModelWithDiscriminator( | ||
@Body animal: Animal, | ||
): Animal | ||
} |
11 changes: 11 additions & 0 deletions
11
...xamples/example-kotlin-ksp/src/main/kotlin/example/openapi/test/api/RequestBodyApiImpl.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,11 @@ | ||
package example.openapi.test.api | ||
|
||
import io.micronaut.http.annotation.Controller | ||
import example.openapi.test.model.Animal | ||
|
||
@Controller | ||
class RequestBodyApiImpl : RequestBodyApi { | ||
|
||
override fun sendModelWithDiscriminator(animal: Animal): Animal = | ||
animal | ||
} |
64 changes: 64 additions & 0 deletions
64
doc-examples/example-kotlin-ksp/src/main/kotlin/example/openapi/test/model/Animal.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,64 @@ | ||
package example.openapi.test.model | ||
|
||
import com.fasterxml.jackson.annotation.* | ||
import io.micronaut.core.annotation.Nullable | ||
import io.micronaut.serde.annotation.Serdeable | ||
import jakarta.annotation.Generated | ||
import java.util.* | ||
|
||
/** | ||
* Animal | ||
*/ | ||
@Serdeable | ||
@JsonPropertyOrder( | ||
Animal.JSON_PROPERTY_PROPERTY_CLASS, | ||
Animal.JSON_PROPERTY_COLOR, | ||
) | ||
@Generated("io.micronaut.openapi.generator.KotlinMicronautServerCodegen") | ||
@JsonIgnoreProperties( | ||
value = ["class"], // ignore manually set class, it will be automatically generated by Jackson during serialization | ||
allowSetters = true, // allows the class to be set during deserialization | ||
) | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "class", visible = true) | ||
@JsonSubTypes( | ||
JsonSubTypes.Type(value = Bird::class, name = "ave"), | ||
JsonSubTypes.Type(value = Mammal::class, name = "mammalia"), | ||
JsonSubTypes.Type(value = Reptile::class, name = "reptilia"), | ||
) | ||
open class Animal( | ||
|
||
@field:Nullable | ||
@field:JsonProperty(JSON_PROPERTY_PROPERTY_CLASS) | ||
@field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) | ||
open var propertyClass: String? = null, | ||
|
||
@field:Nullable | ||
@field:JsonProperty(JSON_PROPERTY_COLOR) | ||
@field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) | ||
open var color: ColorEnum? = null, | ||
) { | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) { | ||
return true | ||
} | ||
if (javaClass != other?.javaClass) { | ||
return false | ||
} | ||
other as Animal | ||
return propertyClass == other.propertyClass | ||
&& color == other.color | ||
} | ||
|
||
override fun hashCode(): Int = | ||
Objects.hash(propertyClass, color) | ||
|
||
override fun toString(): String = | ||
"Animal(propertyClass='$propertyClass', color='$color')" | ||
|
||
companion object { | ||
|
||
const val JSON_PROPERTY_PROPERTY_CLASS = "class" | ||
const val JSON_PROPERTY_COLOR = "color" | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
doc-examples/example-kotlin-ksp/src/main/kotlin/example/openapi/test/model/Bird.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,76 @@ | ||
package example.openapi.test.model | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder | ||
import io.micronaut.core.annotation.Nullable | ||
import io.micronaut.serde.annotation.Serdeable | ||
import jakarta.annotation.Generated | ||
import java.math.BigDecimal | ||
import java.util.* | ||
|
||
/** | ||
* Bird | ||
*/ | ||
@Serdeable | ||
@JsonPropertyOrder( | ||
Bird.JSON_PROPERTY_NUM_WINGS, | ||
Bird.JSON_PROPERTY_BEAK_LENGTH, | ||
Bird.JSON_PROPERTY_FEATHER_DESCRIPTION, | ||
) | ||
@Generated("io.micronaut.openapi.generator.KotlinMicronautServerCodegen") | ||
class Bird( | ||
|
||
@field:Nullable | ||
@field:JsonProperty(JSON_PROPERTY_NUM_WINGS) | ||
@field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) | ||
var numWings: Int? = null, | ||
|
||
@field:Nullable | ||
@field:JsonProperty(JSON_PROPERTY_BEAK_LENGTH) | ||
@field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) | ||
var beakLength: BigDecimal? = null, | ||
|
||
@field:Nullable | ||
@field:JsonProperty(JSON_PROPERTY_FEATHER_DESCRIPTION) | ||
@field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) | ||
var featherDescription: String? = null, | ||
|
||
@Nullable | ||
@JsonProperty(JSON_PROPERTY_PROPERTY_CLASS) | ||
@JsonInclude(JsonInclude.Include.USE_DEFAULTS) | ||
propertyClass: String? = null, | ||
|
||
@Nullable | ||
@JsonProperty(JSON_PROPERTY_COLOR) | ||
@JsonInclude(JsonInclude.Include.USE_DEFAULTS) | ||
color: ColorEnum? = null, | ||
) : Animal(propertyClass, color) { | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) { | ||
return true | ||
} | ||
if (javaClass != other?.javaClass) { | ||
return false | ||
} | ||
other as Bird | ||
return numWings == other.numWings | ||
&& beakLength == other.beakLength | ||
&& featherDescription == other.featherDescription | ||
&& super.equals(other) | ||
} | ||
|
||
override fun hashCode(): Int = | ||
Objects.hash(numWings, beakLength, featherDescription, super.hashCode()) | ||
|
||
override fun toString(): String = | ||
"Bird(numWings='$numWings', beakLength='$beakLength', featherDescription='$featherDescription', propertyClass='$propertyClass', color='$color')" | ||
|
||
companion object { | ||
|
||
const val JSON_PROPERTY_NUM_WINGS = "numWings" | ||
const val JSON_PROPERTY_BEAK_LENGTH = "beakLength" | ||
const val JSON_PROPERTY_FEATHER_DESCRIPTION = "featherDescription" | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
doc-examples/example-kotlin-ksp/src/main/kotlin/example/openapi/test/model/ColorEnum.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,58 @@ | ||
package example.openapi.test.model | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.annotation.JsonValue | ||
import io.micronaut.serde.annotation.Serdeable | ||
import jakarta.annotation.Generated | ||
|
||
/** | ||
* Gets or Sets ColorEnum | ||
* | ||
* @param value The value represented by this enum | ||
*/ | ||
@Serdeable | ||
@Generated("io.micronaut.openapi.generator.KotlinMicronautServerCodegen") | ||
enum class ColorEnum( | ||
@get:JsonValue val value: String, | ||
) { | ||
|
||
@JsonProperty("red") | ||
RED("red"), | ||
|
||
@JsonProperty("blue") | ||
BLUE("blue"), | ||
|
||
@JsonProperty("green") | ||
GREEN("green"), | ||
|
||
@JsonProperty("light-blue") | ||
LIGHT_BLUE("light-blue"), | ||
|
||
@JsonProperty("dark-green") | ||
DARK_GREEN("dark-green"), | ||
; | ||
|
||
override fun toString(): String = value | ||
|
||
companion object { | ||
|
||
@JvmField | ||
val VALUE_MAPPING = entries.associateBy { it.value.lowercase() } | ||
|
||
/** | ||
* Create this enum from a value. | ||
* | ||
* @param value The value | ||
* | ||
* @return The enum | ||
*/ | ||
@JsonCreator | ||
@JvmStatic | ||
fun fromValue(value: String): ColorEnum { | ||
val key = value.lowercase() | ||
require(VALUE_MAPPING.containsKey(key)) { "Unexpected value '$key'" } | ||
return VALUE_MAPPING[key]!! | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
doc-examples/example-kotlin-ksp/src/main/kotlin/example/openapi/test/model/Error.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,33 @@ | ||
package example.openapi.test.model | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder | ||
import io.micronaut.core.annotation.Nullable | ||
import io.micronaut.serde.annotation.Serdeable | ||
import jakarta.annotation.Generated | ||
|
||
/** | ||
* An object for describing errors | ||
*/ | ||
@Serdeable | ||
@JsonPropertyOrder( | ||
Error.JSON_PROPERTY_MESSAGE, | ||
) | ||
@Generated("io.micronaut.openapi.generator.KotlinMicronautServerCodegen") | ||
data class Error( | ||
|
||
/** | ||
* The error message | ||
*/ | ||
@field:Nullable | ||
@field:JsonProperty(JSON_PROPERTY_MESSAGE) | ||
@field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) | ||
var message: String? = null, | ||
) { | ||
|
||
companion object { | ||
|
||
const val JSON_PROPERTY_MESSAGE = "message" | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
doc-examples/example-kotlin-ksp/src/main/kotlin/example/openapi/test/model/Mammal.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,63 @@ | ||
package example.openapi.test.model | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder | ||
import io.micronaut.core.annotation.Nullable | ||
import io.micronaut.serde.annotation.Serdeable | ||
import jakarta.annotation.Generated | ||
import java.util.* | ||
|
||
/** | ||
* Mammal | ||
*/ | ||
@Serdeable | ||
@JsonPropertyOrder( | ||
Mammal.JSON_PROPERTY_WEIGHT, | ||
Mammal.JSON_PROPERTY_DESCRIPTION, | ||
) | ||
@Generated("io.micronaut.openapi.generator.KotlinMicronautServerCodegen") | ||
class Mammal( | ||
|
||
@field:JsonProperty(JSON_PROPERTY_WEIGHT) | ||
var weight: Float, | ||
|
||
@field:JsonProperty(JSON_PROPERTY_DESCRIPTION) | ||
var description: String, | ||
|
||
@Nullable | ||
@JsonProperty(JSON_PROPERTY_PROPERTY_CLASS) | ||
@JsonInclude(JsonInclude.Include.USE_DEFAULTS) | ||
propertyClass: String? = null, | ||
|
||
@Nullable | ||
@JsonProperty(JSON_PROPERTY_COLOR) | ||
@JsonInclude(JsonInclude.Include.USE_DEFAULTS) | ||
color: ColorEnum? = null, | ||
) : Animal(propertyClass, color) { | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) { | ||
return true | ||
} | ||
if (javaClass != other?.javaClass) { | ||
return false | ||
} | ||
other as Mammal | ||
return weight == other.weight | ||
&& description == other.description | ||
&& super.equals(other) | ||
} | ||
|
||
override fun hashCode(): Int = | ||
Objects.hash(weight, description, super.hashCode()) | ||
|
||
override fun toString(): String = | ||
"Mammal(weight='$weight', description='$description', propertyClass='$propertyClass', color='$color')" | ||
|
||
companion object { | ||
|
||
const val JSON_PROPERTY_WEIGHT = "weight" | ||
const val JSON_PROPERTY_DESCRIPTION = "description" | ||
} | ||
} |
Oops, something went wrong.