Skip to content

Commit 1019573

Browse files
committed
add a case with nullable attribute with non-null default. That breaks the logic. Needs fix
1 parent 611eb87 commit 1019573

7 files changed

Lines changed: 229 additions & 0 deletions

File tree

modules/openapi-generator/src/test/resources/3_0/kotlin/petstore-with-x-kotlin-implements.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,62 @@ components:
566566
items:
567567
$ref: '#/components/schemas/SomeEnum'
568568
default: [ ENUMVALUE3, ENUMVALUE1 ]
569+
nonRequiredWithDefaultNullList:
570+
type: array
571+
items:
572+
type: string
573+
nullable: true
574+
default: null
575+
nonRequiredWithDefaultNullSet:
576+
type: array
577+
items:
578+
type: string
579+
uniqueItems: true
580+
nullable: true
581+
default: null
582+
nonRequiredWithDefaultNullString:
583+
type: string
584+
nullable: true
585+
default: null
586+
nonRequiredWithDefaultNullInt:
587+
type: number
588+
format: int32
589+
nullable: true
590+
default: null
591+
nonRequiredWithDefaultNullLong:
592+
type: number
593+
format: int64
594+
nullable: true
595+
default: null
596+
nonRequiredWithDefaultNullFloat:
597+
type: number
598+
format: float
599+
nullable: true
600+
default: null
601+
nonRequiredWithDefaultNullDouble:
602+
type: number
603+
format: double
604+
nullable: true
605+
default: null
606+
nonRequiredWithDefaultNullEnum:
607+
$ref: '#/components/schemas/SomeNullableEnum'
608+
nonRequiredWithDefaultNullEnumList:
609+
type: array
610+
items:
611+
$ref: '#/components/schemas/SomeEnum'
612+
nullable: true
613+
default: null
614+
nonRequiredWithDefaultNullEnumSet:
615+
type: array
616+
uniqueItems: true
617+
items:
618+
$ref: '#/components/schemas/SomeEnum'
619+
nullable: true
620+
default: null
621+
nonRequiredNullableWithDefaultString:
622+
type: string
623+
nullable: true
624+
default: "someString"
569625
photoUrls:
570626
type: array
571627
items:
@@ -630,6 +686,14 @@ components:
630686
- ENUMVALUE2
631687
- ENUMVALUE3
632688
default: ENUMVALUE1
689+
SomeNullableEnum:
690+
type: string
691+
enum:
692+
- ENUMVALUE1
693+
- ENUMVALUE2
694+
- ENUMVALUE3
695+
nullable: true
696+
default: null
633697
Color:
634698
x-kotlin-implements: [ com.some.pack.WithDefaultMethods ]
635699
type: string

samples/server/petstore/kotlin-springboot-x-kotlin-implements/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ src/main/kotlin/org/openapitools/model/ModelApiResponse.kt
2020
src/main/kotlin/org/openapitools/model/Order.kt
2121
src/main/kotlin/org/openapitools/model/Pet.kt
2222
src/main/kotlin/org/openapitools/model/SomeEnum.kt
23+
src/main/kotlin/org/openapitools/model/SomeNullableEnum.kt
2324
src/main/kotlin/org/openapitools/model/Tag.kt
2425
src/main/kotlin/org/openapitools/model/User.kt

samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/configuration/EnumConverterConfiguration.kt

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

33
import org.openapitools.model.Color
44
import org.openapitools.model.SomeEnum
5+
import org.openapitools.model.SomeNullableEnum
56

67
import org.springframework.context.annotation.Bean
78
import org.springframework.context.annotation.Configuration
@@ -29,5 +30,11 @@ class EnumConverterConfiguration {
2930
override fun convert(source: kotlin.String): SomeEnum = SomeEnum.forValue(source)
3031
}
3132
}
33+
@Bean(name = ["org.openapitools.configuration.EnumConverterConfiguration.someNullableEnumConverter"])
34+
fun someNullableEnumConverter(): Converter<kotlin.String, SomeNullableEnum> {
35+
return object: Converter<kotlin.String, SomeNullableEnum> {
36+
override fun convert(source: kotlin.String): SomeNullableEnum = SomeNullableEnum.forValue(source)
37+
}
38+
}
3239

3340
}

samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Cat.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.openapitools.model.Category
99
import org.openapitools.model.Color
1010
import org.openapitools.model.Pet
1111
import org.openapitools.model.SomeEnum
12+
import org.openapitools.model.SomeNullableEnum
1213
import org.openapitools.model.Tag
1314
import java.io.Serializable
1415
import javax.validation.constraints.DecimalMax
@@ -83,6 +84,42 @@ data class Cat(
8384
@get:JsonProperty("nonRequiredWithDefaultEnumSet", required = false)
8485
override val nonRequiredWithDefaultEnumSet: kotlin.collections.Set<SomeEnum> = setOf(SomeEnum.ENUMVALUE3,SomeEnum.ENUMVALUE1),
8586

87+
@get:JsonProperty("nonRequiredWithDefaultNullList", required = false)
88+
override val nonRequiredWithDefaultNullList: kotlin.collections.List<kotlin.String>? = null,
89+
90+
@get:JsonProperty("nonRequiredWithDefaultNullSet", required = false)
91+
override val nonRequiredWithDefaultNullSet: kotlin.collections.Set<kotlin.String>? = null,
92+
93+
@get:JsonProperty("nonRequiredWithDefaultNullString", required = false)
94+
override val nonRequiredWithDefaultNullString: kotlin.String? = null,
95+
96+
@get:JsonProperty("nonRequiredWithDefaultNullInt", required = false)
97+
override val nonRequiredWithDefaultNullInt: java.math.BigDecimal? = null,
98+
99+
@get:JsonProperty("nonRequiredWithDefaultNullLong", required = false)
100+
override val nonRequiredWithDefaultNullLong: java.math.BigDecimal? = null,
101+
102+
@get:JsonProperty("nonRequiredWithDefaultNullFloat", required = false)
103+
override val nonRequiredWithDefaultNullFloat: kotlin.Float? = null,
104+
105+
@get:JsonProperty("nonRequiredWithDefaultNullDouble", required = false)
106+
override val nonRequiredWithDefaultNullDouble: kotlin.Double? = null,
107+
108+
@field:Valid
109+
@get:JsonProperty("nonRequiredWithDefaultNullEnum", required = false)
110+
override val nonRequiredWithDefaultNullEnum: SomeNullableEnum? = null,
111+
112+
@field:Valid
113+
@get:JsonProperty("nonRequiredWithDefaultNullEnumList", required = false)
114+
override val nonRequiredWithDefaultNullEnumList: kotlin.collections.List<SomeEnum>? = null,
115+
116+
@field:Valid
117+
@get:JsonProperty("nonRequiredWithDefaultNullEnumSet", required = false)
118+
override val nonRequiredWithDefaultNullEnumSet: kotlin.collections.Set<SomeEnum>? = null,
119+
120+
@get:JsonProperty("nonRequiredNullableWithDefaultString", required = false)
121+
override val nonRequiredNullableWithDefaultString: kotlin.String = "someString",
122+
86123
@field:Valid
87124
@get:JsonProperty("tags", required = false)
88125
override val tags: kotlin.collections.List<Tag>? = null,

samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Dog.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.openapitools.model.Category
99
import org.openapitools.model.Color
1010
import org.openapitools.model.Pet
1111
import org.openapitools.model.SomeEnum
12+
import org.openapitools.model.SomeNullableEnum
1213
import org.openapitools.model.Tag
1314
import java.io.Serializable
1415
import javax.validation.constraints.DecimalMax
@@ -87,6 +88,42 @@ data class Dog(
8788
@get:JsonProperty("nonRequiredWithDefaultEnumSet", required = false)
8889
override val nonRequiredWithDefaultEnumSet: kotlin.collections.Set<SomeEnum> = setOf(SomeEnum.ENUMVALUE3,SomeEnum.ENUMVALUE1),
8990

91+
@get:JsonProperty("nonRequiredWithDefaultNullList", required = false)
92+
override val nonRequiredWithDefaultNullList: kotlin.collections.List<kotlin.String>? = null,
93+
94+
@get:JsonProperty("nonRequiredWithDefaultNullSet", required = false)
95+
override val nonRequiredWithDefaultNullSet: kotlin.collections.Set<kotlin.String>? = null,
96+
97+
@get:JsonProperty("nonRequiredWithDefaultNullString", required = false)
98+
override val nonRequiredWithDefaultNullString: kotlin.String? = null,
99+
100+
@get:JsonProperty("nonRequiredWithDefaultNullInt", required = false)
101+
override val nonRequiredWithDefaultNullInt: java.math.BigDecimal? = null,
102+
103+
@get:JsonProperty("nonRequiredWithDefaultNullLong", required = false)
104+
override val nonRequiredWithDefaultNullLong: java.math.BigDecimal? = null,
105+
106+
@get:JsonProperty("nonRequiredWithDefaultNullFloat", required = false)
107+
override val nonRequiredWithDefaultNullFloat: kotlin.Float? = null,
108+
109+
@get:JsonProperty("nonRequiredWithDefaultNullDouble", required = false)
110+
override val nonRequiredWithDefaultNullDouble: kotlin.Double? = null,
111+
112+
@field:Valid
113+
@get:JsonProperty("nonRequiredWithDefaultNullEnum", required = false)
114+
override val nonRequiredWithDefaultNullEnum: SomeNullableEnum? = null,
115+
116+
@field:Valid
117+
@get:JsonProperty("nonRequiredWithDefaultNullEnumList", required = false)
118+
override val nonRequiredWithDefaultNullEnumList: kotlin.collections.List<SomeEnum>? = null,
119+
120+
@field:Valid
121+
@get:JsonProperty("nonRequiredWithDefaultNullEnumSet", required = false)
122+
override val nonRequiredWithDefaultNullEnumSet: kotlin.collections.Set<SomeEnum>? = null,
123+
124+
@get:JsonProperty("nonRequiredNullableWithDefaultString", required = false)
125+
override val nonRequiredNullableWithDefaultString: kotlin.String = "someString",
126+
90127
@field:Valid
91128
@get:JsonProperty("tags", required = false)
92129
override val tags: kotlin.collections.List<Tag>? = null,

samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Pet.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.fasterxml.jackson.annotation.JsonValue
1111
import org.openapitools.model.Category
1212
import org.openapitools.model.Color
1313
import org.openapitools.model.SomeEnum
14+
import org.openapitools.model.SomeNullableEnum
1415
import org.openapitools.model.Tag
1516
import java.io.Serializable
1617
import javax.validation.constraints.DecimalMax
@@ -40,6 +41,17 @@ import javax.validation.Valid
4041
* @param nonRequiredWithDefaultEnum
4142
* @param nonRequiredWithDefaultEnumList
4243
* @param nonRequiredWithDefaultEnumSet
44+
* @param nonRequiredWithDefaultNullList
45+
* @param nonRequiredWithDefaultNullSet
46+
* @param nonRequiredWithDefaultNullString
47+
* @param nonRequiredWithDefaultNullInt
48+
* @param nonRequiredWithDefaultNullLong
49+
* @param nonRequiredWithDefaultNullFloat
50+
* @param nonRequiredWithDefaultNullDouble
51+
* @param nonRequiredWithDefaultNullEnum
52+
* @param nonRequiredWithDefaultNullEnumList
53+
* @param nonRequiredWithDefaultNullEnumSet
54+
* @param nonRequiredNullableWithDefaultString
4355
* @param tags
4456
* @param color
4557
*/
@@ -100,6 +112,39 @@ interface Pet : Serializable, com.some.pack.Named, com.some.pack.WithCategory, c
100112
val nonRequiredWithDefaultEnumSet: kotlin.collections.Set<SomeEnum>
101113

102114

115+
val nonRequiredWithDefaultNullList: kotlin.collections.List<kotlin.String>?
116+
117+
118+
val nonRequiredWithDefaultNullSet: kotlin.collections.Set<kotlin.String>?
119+
120+
121+
val nonRequiredWithDefaultNullString: kotlin.String?
122+
123+
124+
val nonRequiredWithDefaultNullInt: java.math.BigDecimal?
125+
126+
127+
val nonRequiredWithDefaultNullLong: java.math.BigDecimal?
128+
129+
130+
val nonRequiredWithDefaultNullFloat: kotlin.Float?
131+
132+
133+
val nonRequiredWithDefaultNullDouble: kotlin.Double?
134+
135+
136+
val nonRequiredWithDefaultNullEnum: SomeNullableEnum?
137+
138+
139+
val nonRequiredWithDefaultNullEnumList: kotlin.collections.List<SomeEnum>?
140+
141+
142+
val nonRequiredWithDefaultNullEnumSet: kotlin.collections.Set<SomeEnum>?
143+
144+
145+
val nonRequiredNullableWithDefaultString: kotlin.String
146+
147+
103148
val tags: kotlin.collections.List<Tag>?
104149

105150

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

0 commit comments

Comments
 (0)