Skip to content

Commit 1446407

Browse files
committed
fix samples after fix
1 parent e040bec commit 1446407

6 files changed

Lines changed: 144 additions & 0 deletions

File tree

samples/server/petstore/kotlin-springboot-sort-validation/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ src/main/kotlin/org/openapitools/configuration/ValidPageable.kt
1717
src/main/kotlin/org/openapitools/configuration/ValidSort.kt
1818
src/main/kotlin/org/openapitools/model/Pet.kt
1919
src/main/kotlin/org/openapitools/model/PetSort.kt
20+
src/main/kotlin/org/openapitools/model/PetSortEnum.kt
2021
src/main/resources/application.yaml

samples/server/petstore/kotlin-springboot-sort-validation/src/main/kotlin/org/openapitools/api/PetApiController.kt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.springframework.data.domain.Pageable
44
import org.springframework.data.web.PageableDefault
55
import org.openapitools.model.Pet
66
import org.openapitools.model.PetSort
7+
import org.openapitools.model.PetSortEnum
78
import org.springframework.data.domain.Sort
89
import org.springframework.data.web.SortDefault
910
import org.openapitools.configuration.ValidPageable
@@ -75,6 +76,39 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
7576
}
7677

7778

79+
@RequestMapping(
80+
method = [RequestMethod.GET],
81+
// "/pet/findWithArraySortEnum"
82+
value = [PATH_FIND_PETS_WITH_ARRAY_SORT_ENUM],
83+
produces = ["application/json"]
84+
)
85+
fun findPetsWithArraySortEnum(@ValidSort(allowedValues = ["id,asc", "id,desc", "name,asc", "name,desc"]) @PageableDefault(page = 0, size = 20) pageable: Pageable): ResponseEntity<List<Pet>> {
86+
return ResponseEntity(service.findPetsWithArraySortEnum(), HttpStatus.valueOf(200))
87+
}
88+
89+
90+
@RequestMapping(
91+
method = [RequestMethod.GET],
92+
// "/pet/findWithArraySortRefEnum"
93+
value = [PATH_FIND_PETS_WITH_ARRAY_SORT_REF_ENUM],
94+
produces = ["application/json"]
95+
)
96+
fun findPetsWithArraySortRefEnum(@ValidSort(allowedValues = ["id,asc", "id,desc", "createdAt,asc", "createdAt,desc"]) @PageableDefault(page = 0, size = 20) pageable: Pageable): ResponseEntity<List<Pet>> {
97+
return ResponseEntity(service.findPetsWithArraySortRefEnum(), HttpStatus.valueOf(200))
98+
}
99+
100+
101+
@RequestMapping(
102+
method = [RequestMethod.GET],
103+
// "/pet/findWithExternalParamRefArraySort"
104+
value = [PATH_FIND_PETS_WITH_EXTERNAL_PARAM_REF_ARRAY_SORT],
105+
produces = ["application/json"]
106+
)
107+
fun findPetsWithExternalParamRefArraySort(@ValidSort(allowedValues = ["name,asc", "name,desc", "id,asc", "id,desc"]) @PageableDefault(page = 0, size = 20) pageable: Pageable): ResponseEntity<List<Pet>> {
108+
return ResponseEntity(service.findPetsWithExternalParamRefArraySort(), HttpStatus.valueOf(200))
109+
}
110+
111+
78112
@RequestMapping(
79113
method = [RequestMethod.GET],
80114
// "/pet/findWithMixedSortDefaults"
@@ -86,6 +120,17 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
86120
}
87121

88122

123+
@RequestMapping(
124+
method = [RequestMethod.GET],
125+
// "/pet/findWithNonExplodedExternalParamRefArraySort"
126+
value = [PATH_FIND_PETS_WITH_NON_EXPLODED_EXTERNAL_PARAM_REF_ARRAY_SORT],
127+
produces = ["application/json"]
128+
)
129+
fun findPetsWithNonExplodedExternalParamRefArraySort(@ValidSort(allowedValues = ["name,asc", "name,desc", "id,asc", "id,desc"]) @PageableDefault(page = 0, size = 20) pageable: Pageable): ResponseEntity<List<Pet>> {
130+
return ResponseEntity(service.findPetsWithNonExplodedExternalParamRefArraySort(), HttpStatus.valueOf(200))
131+
}
132+
133+
89134
@RequestMapping(
90135
method = [RequestMethod.GET],
91136
// "/pet/findWithPageAndSizeConstraint"
@@ -181,7 +226,11 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
181226
const val PATH_FIND_PETS_AUTO_DETECTED_WITH_SORT: String = "/pet/findAutoDetectedWithSort"
182227
const val PATH_FIND_PETS_NON_PAGINATED_WITH_SORT_ENUM: String = "/pet/findNonPaginatedWithSortEnum"
183228
const val PATH_FIND_PETS_WITH_ALL_DEFAULTS: String = "/pet/findWithAllDefaults"
229+
const val PATH_FIND_PETS_WITH_ARRAY_SORT_ENUM: String = "/pet/findWithArraySortEnum"
230+
const val PATH_FIND_PETS_WITH_ARRAY_SORT_REF_ENUM: String = "/pet/findWithArraySortRefEnum"
231+
const val PATH_FIND_PETS_WITH_EXTERNAL_PARAM_REF_ARRAY_SORT: String = "/pet/findWithExternalParamRefArraySort"
184232
const val PATH_FIND_PETS_WITH_MIXED_SORT_DEFAULTS: String = "/pet/findWithMixedSortDefaults"
233+
const val PATH_FIND_PETS_WITH_NON_EXPLODED_EXTERNAL_PARAM_REF_ARRAY_SORT: String = "/pet/findWithNonExplodedExternalParamRefArraySort"
185234
const val PATH_FIND_PETS_WITH_PAGE_AND_SIZE_CONSTRAINT: String = "/pet/findWithPageAndSizeConstraint"
186235
const val PATH_FIND_PETS_WITH_PAGE_SIZE_DEFAULTS_ONLY: String = "/pet/findWithPageSizeDefaultsOnly"
187236
const val PATH_FIND_PETS_WITH_REF_SORT: String = "/pet/findWithRefSort"

samples/server/petstore/kotlin-springboot-sort-validation/src/main/kotlin/org/openapitools/api/PetApiService.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.springframework.data.domain.Pageable
44
import org.springframework.data.web.PageableDefault
55
import org.openapitools.model.Pet
66
import org.openapitools.model.PetSort
7+
import org.openapitools.model.PetSortEnum
78
import org.springframework.data.domain.Sort
89
import org.springframework.data.web.SortDefault
910
import org.openapitools.configuration.ValidPageable
@@ -40,6 +41,30 @@ interface PetApiService {
4041
*/
4142
fun findPetsWithAllDefaults(): List<Pet>
4243

44+
/**
45+
* GET /pet/findWithArraySortEnum : Find pets with x-spring-paginated and array sort param with inline enum on items
46+
*
47+
* @return successful operation (status code 200)
48+
* @see PetApi#findPetsWithArraySortEnum
49+
*/
50+
fun findPetsWithArraySortEnum(): List<Pet>
51+
52+
/**
53+
* GET /pet/findWithArraySortRefEnum : Find pets with x-spring-paginated and array sort param whose items use a $ref enum
54+
*
55+
* @return successful operation (status code 200)
56+
* @see PetApi#findPetsWithArraySortRefEnum
57+
*/
58+
fun findPetsWithArraySortRefEnum(): List<Pet>
59+
60+
/**
61+
* GET /pet/findWithExternalParamRefArraySort : Find pets with x-spring-paginated and sort param referenced from an external components file
62+
*
63+
* @return successful operation (status code 200)
64+
* @see PetApi#findPetsWithExternalParamRefArraySort
65+
*/
66+
fun findPetsWithExternalParamRefArraySort(): List<Pet>
67+
4368
/**
4469
* GET /pet/findWithMixedSortDefaults : Find pets — multiple sort defaults with mixed directions (array sort param)
4570
*
@@ -48,6 +73,14 @@ interface PetApiService {
4873
*/
4974
fun findPetsWithMixedSortDefaults(): List<Pet>
5075

76+
/**
77+
* GET /pet/findWithNonExplodedExternalParamRefArraySort : Find pets with x-spring-paginated and non-exploded sort param referenced from an external components file
78+
*
79+
* @return successful operation (status code 200)
80+
* @see PetApi#findPetsWithNonExplodedExternalParamRefArraySort
81+
*/
82+
fun findPetsWithNonExplodedExternalParamRefArraySort(): List<Pet>
83+
5184
/**
5285
* GET /pet/findWithPageAndSizeConstraint : Find pets — both page and size have maximum constraints
5386
*

samples/server/petstore/kotlin-springboot-sort-validation/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.springframework.data.domain.Pageable
44
import org.springframework.data.web.PageableDefault
55
import org.openapitools.model.Pet
66
import org.openapitools.model.PetSort
7+
import org.openapitools.model.PetSortEnum
78
import org.springframework.data.domain.Sort
89
import org.springframework.data.web.SortDefault
910
import org.openapitools.configuration.ValidPageable
@@ -24,10 +25,26 @@ class PetApiServiceImpl : PetApiService {
2425
TODO("Implement me")
2526
}
2627

28+
override fun findPetsWithArraySortEnum(): List<Pet> {
29+
TODO("Implement me")
30+
}
31+
32+
override fun findPetsWithArraySortRefEnum(): List<Pet> {
33+
TODO("Implement me")
34+
}
35+
36+
override fun findPetsWithExternalParamRefArraySort(): List<Pet> {
37+
TODO("Implement me")
38+
}
39+
2740
override fun findPetsWithMixedSortDefaults(): List<Pet> {
2841
TODO("Implement me")
2942
}
3043

44+
override fun findPetsWithNonExplodedExternalParamRefArraySort(): List<Pet> {
45+
TODO("Implement me")
46+
}
47+
3148
override fun findPetsWithPageAndSizeConstraint(): List<Pet> {
3249
TODO("Implement me")
3350
}

samples/server/petstore/kotlin-springboot-sort-validation/src/main/kotlin/org/openapitools/configuration/EnumConverterConfiguration.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.openapitools.configuration
22

33
import org.openapitools.model.PetSort
4+
import org.openapitools.model.PetSortEnum
45

56
import org.springframework.context.annotation.Bean
67
import org.springframework.context.annotation.Configuration
@@ -22,5 +23,11 @@ class EnumConverterConfiguration {
2223
override fun convert(source: kotlin.String): PetSort = PetSort.forValue(source)
2324
}
2425
}
26+
@Bean(name = ["org.openapitools.configuration.EnumConverterConfiguration.petSortEnumConverter"])
27+
fun petSortEnumConverter(): Converter<kotlin.String, PetSortEnum> {
28+
return object: Converter<kotlin.String, PetSortEnum> {
29+
override fun convert(source: kotlin.String): PetSortEnum = PetSortEnum.forValue(source)
30+
}
31+
}
2532

2633
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.openapitools.model
2+
3+
import java.util.Objects
4+
import com.fasterxml.jackson.annotation.JsonValue
5+
import com.fasterxml.jackson.annotation.JsonCreator
6+
import com.fasterxml.jackson.annotation.JsonProperty
7+
import jakarta.validation.constraints.DecimalMax
8+
import jakarta.validation.constraints.DecimalMin
9+
import jakarta.validation.constraints.Email
10+
import jakarta.validation.constraints.Max
11+
import jakarta.validation.constraints.Min
12+
import jakarta.validation.constraints.NotNull
13+
import jakarta.validation.constraints.Pattern
14+
import jakarta.validation.constraints.Size
15+
import jakarta.validation.Valid
16+
17+
/**
18+
*
19+
* Values: nameCommaAsc,nameCommaDesc,idCommaAsc,idCommaDesc
20+
*/
21+
enum class PetSortEnum(@get:JsonValue val value: kotlin.String) : java.io.Serializable {
22+
23+
nameCommaAsc("name,asc"),
24+
nameCommaDesc("name,desc"),
25+
idCommaAsc("id,asc"),
26+
idCommaDesc("id,desc");
27+
28+
companion object {
29+
@JvmStatic
30+
@JsonCreator
31+
fun forValue(value: kotlin.String): PetSortEnum {
32+
return values().firstOrNull{it -> it.value == value}
33+
?: throw IllegalArgumentException("Unexpected value '$value' for enum 'PetSortEnum'")
34+
}
35+
}
36+
}
37+

0 commit comments

Comments
 (0)