Skip to content

Commit 9b40b09

Browse files
committed
update samples
1 parent c9fea96 commit 9b40b09

7 files changed

Lines changed: 212 additions & 21 deletions

File tree

  • samples
    • client/petstore
      • kotlin-multiplatform-kotlinx-datetime/src/commonMain/kotlin/org/openapitools/client/auth
      • kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth
    • server
      • others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix
      • petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.openapitools.client.auth
2+
3+
class OAuth : Authentication {
4+
var accessToken: String? = null
5+
6+
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
7+
val token: String = accessToken ?: return
8+
headers["Authorization"] = "Bearer $token"
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.openapitools.client.auth
2+
3+
class OAuth : Authentication {
4+
var accessToken: String? = null
5+
6+
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
7+
val token: String = accessToken ?: return
8+
headers["Authorization"] = "Bearer $token"
9+
}
10+
}

samples/server/others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# org.openapitools.server - Kotlin Server library for Basic polymorphism example with discriminator
1+
# org.openapitools.server - Kotlin Server library for Polymorphism example with allOf and discriminator
22

33
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
44

samples/server/others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix/src/main/kotlin/org/openapitools/server/models/Cat.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Basic polymorphism example with discriminator
2+
* Polymorphism example with allOf and discriminator
33
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
44
*
55
* The version of the OpenAPI document: 1.0
@@ -11,21 +11,24 @@
1111
*/
1212
package org.openapitools.server.models
1313

14+
import org.openapitools.server.models.Pet
1415

1516
/**
16-
* A pet cat
17+
* A representation of a cat
1718
* @param huntingSkill The measured skill for hunting
18-
* @param petType
1919
*/
2020
data class Cat(
2121
/* The measured skill for hunting */
2222

2323
@field:com.fasterxml.jackson.annotation.JsonProperty("huntingSkill")
2424
val huntingSkill: Cat.HuntingSkill,
2525

26+
@field:com.fasterxml.jackson.annotation.JsonProperty("name")
27+
override val name: kotlin.String,
28+
2629
@field:com.fasterxml.jackson.annotation.JsonProperty("petType")
27-
val petType: kotlin.Any? = null
28-
) : Pet()
30+
override val petType: kotlin.String
31+
) : Pet(name = name, petType = petType)
2932
{
3033
/**
3134
* The measured skill for hunting
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Basic polymorphism example with discriminator
2+
* Polymorphism example with allOf and discriminator
33
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
44
*
55
* The version of the OpenAPI document: 1.0
@@ -11,19 +11,24 @@
1111
*/
1212
package org.openapitools.server.models
1313

14+
import org.openapitools.server.models.Pet
1415

1516
/**
16-
* A pet dog
17-
* @param petType
17+
* A representation of a dog
1818
* @param packSize the size of the pack the dog is from
1919
*/
2020
data class Dog(
21-
22-
@field:com.fasterxml.jackson.annotation.JsonProperty("petType")
23-
val petType: kotlin.Any?,
2421
/* the size of the pack the dog is from */
2522

2623
@field:com.fasterxml.jackson.annotation.JsonProperty("packSize")
27-
val packSize: kotlin.Int = 0
28-
) : Pet()
24+
val packSize: kotlin.Int = 0,
25+
26+
@field:com.fasterxml.jackson.annotation.JsonProperty("name")
27+
override val name: kotlin.String,
28+
29+
@field:com.fasterxml.jackson.annotation.JsonProperty("petType")
30+
override val petType: kotlin.String
31+
) : Pet(name = name, petType = petType)
32+
{
33+
}
2934

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Basic polymorphism example with discriminator
2+
* Polymorphism example with allOf and discriminator
33
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
44
*
55
* The version of the OpenAPI document: 1.0
@@ -11,16 +11,25 @@
1111
*/
1212
package org.openapitools.server.models
1313

14-
import org.openapitools.server.models.Cat
15-
import org.openapitools.server.models.Dog
1614

1715
/**
1816
*
17+
* @param name
18+
* @param petType
1919
*/
20-
@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, include = com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY, property = "petType", visible = false)
20+
@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, include = com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY, property = "petType", visible = true)
2121
@com.fasterxml.jackson.annotation.JsonSubTypes(
22-
com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = Cat::class, name = "cat"),
23-
com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = Dog::class, name = "dog")
22+
com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = Cat::class, name = "Cat"),
23+
com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = Dog::class, name = "Dog")
24+
)
25+
sealed class Pet(
26+
27+
@field:com.fasterxml.jackson.annotation.JsonProperty("name")
28+
open val name: kotlin.String
29+
,
30+
31+
@field:com.fasterxml.jackson.annotation.JsonProperty("petType")
32+
open val petType: kotlin.String
33+
2434
)
25-
sealed class Pet
2635

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
package org.openapitools.api
2+
3+
import org.openapitools.model.ModelApiResponse
4+
import org.openapitools.model.Pet
5+
import org.springframework.http.HttpStatus
6+
import org.springframework.http.MediaType
7+
import org.springframework.http.ResponseEntity
8+
9+
import org.springframework.web.bind.annotation.*
10+
import org.springframework.validation.annotation.Validated
11+
import org.springframework.web.context.request.NativeWebRequest
12+
import org.springframework.beans.factory.annotation.Autowired
13+
14+
import jakarta.validation.Valid
15+
import jakarta.validation.constraints.DecimalMax
16+
import jakarta.validation.constraints.DecimalMin
17+
import jakarta.validation.constraints.Email
18+
import jakarta.validation.constraints.Max
19+
import jakarta.validation.constraints.Min
20+
import jakarta.validation.constraints.NotNull
21+
import jakarta.validation.constraints.Pattern
22+
import jakarta.validation.constraints.Size
23+
24+
import kotlin.collections.List
25+
import kotlin.collections.Map
26+
27+
@RestController
28+
@Validated
29+
class PetApiController(@Autowired(required = true) val service: PetApiService) {
30+
31+
32+
@RequestMapping(
33+
method = [RequestMethod.POST],
34+
// "/pet"
35+
value = [PATH_ADD_PET],
36+
produces = ["application/xml", "application/json"],
37+
consumes = ["application/json", "application/xml"]
38+
)
39+
fun addPet(
40+
@Valid @RequestBody pet: Pet
41+
): ResponseEntity<Pet> {
42+
return ResponseEntity(service.addPet(pet), HttpStatus.valueOf(200))
43+
}
44+
45+
46+
@RequestMapping(
47+
method = [RequestMethod.DELETE],
48+
// "/pet/{petId}"
49+
value = [PATH_DELETE_PET]
50+
)
51+
fun deletePet(
52+
@PathVariable("petId") petId: kotlin.Long,
53+
@RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?
54+
): ResponseEntity<Unit> {
55+
return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400))
56+
}
57+
58+
59+
@RequestMapping(
60+
method = [RequestMethod.GET],
61+
// "/pet/findByStatus"
62+
value = [PATH_FIND_PETS_BY_STATUS],
63+
produces = ["application/xml", "application/json"]
64+
)
65+
fun findPetsByStatus(
66+
@NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List<kotlin.String>
67+
): ResponseEntity<List<Pet>> {
68+
return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200))
69+
}
70+
71+
72+
@Deprecated(message="Operation is deprecated")
73+
@RequestMapping(
74+
method = [RequestMethod.GET],
75+
// "/pet/findByTags"
76+
value = [PATH_FIND_PETS_BY_TAGS],
77+
produces = ["application/xml", "application/json"]
78+
)
79+
fun findPetsByTags(
80+
@NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List<kotlin.String>
81+
): ResponseEntity<List<Pet>> {
82+
return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200))
83+
}
84+
85+
86+
@RequestMapping(
87+
method = [RequestMethod.GET],
88+
// "/pet/{petId}"
89+
value = [PATH_GET_PET_BY_ID],
90+
produces = ["application/xml", "application/json"]
91+
)
92+
fun getPetById(
93+
@PathVariable("petId") petId: kotlin.Long
94+
): ResponseEntity<Pet> {
95+
return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200))
96+
}
97+
98+
99+
@RequestMapping(
100+
method = [RequestMethod.PUT],
101+
// "/pet"
102+
value = [PATH_UPDATE_PET],
103+
produces = ["application/xml", "application/json"],
104+
consumes = ["application/json", "application/xml"]
105+
)
106+
fun updatePet(
107+
@Valid @RequestBody pet: Pet
108+
): ResponseEntity<Pet> {
109+
return ResponseEntity(service.updatePet(pet), HttpStatus.valueOf(200))
110+
}
111+
112+
113+
@RequestMapping(
114+
method = [RequestMethod.POST],
115+
// "/pet/{petId}"
116+
value = [PATH_UPDATE_PET_WITH_FORM],
117+
consumes = ["application/x-www-form-urlencoded"]
118+
)
119+
fun updatePetWithForm(
120+
@PathVariable("petId") petId: kotlin.Long,
121+
@Valid @RequestParam(value = "name", required = false) name: kotlin.String?,
122+
@Valid @RequestParam(value = "status", required = false) status: kotlin.String?
123+
): ResponseEntity<Unit> {
124+
return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405))
125+
}
126+
127+
128+
@RequestMapping(
129+
method = [RequestMethod.POST],
130+
// "/pet/{petId}/uploadImage"
131+
value = [PATH_UPLOAD_FILE],
132+
produces = ["application/json"],
133+
consumes = ["multipart/form-data"]
134+
)
135+
fun uploadFile(
136+
@PathVariable("petId") petId: kotlin.Long,
137+
@Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?,
138+
@Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile
139+
): ResponseEntity<ModelApiResponse> {
140+
return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200))
141+
}
142+
143+
companion object {
144+
//for your own safety never directly reuse these path definitions in tests
145+
const val PATH_ADD_PET: String = "/pet"
146+
const val PATH_DELETE_PET: String = "/pet/{petId}"
147+
const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus"
148+
const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags"
149+
const val PATH_GET_PET_BY_ID: String = "/pet/{petId}"
150+
const val PATH_UPDATE_PET: String = "/pet"
151+
const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}"
152+
const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage"
153+
}
154+
}

0 commit comments

Comments
 (0)