Skip to content

Commit

Permalink
Add missing JsonProperty parameter annotation. (#220)
Browse files Browse the repository at this point in the history
Since moving the discriminator property from the class into the constructor, we need to have the parameter annotation also.
Closes #219
  • Loading branch information
cjbooms authored Jun 14, 2023
1 parent 05a2732 commit f7b8788
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ object PropertyUtils {
this as PropertyInfo.Field
if (classSettings.polymorphyType == ClassSettings.PolymorphyType.SUB) {
property.initializer(name)
property.addAnnotation(JacksonMetadata.jacksonParameterAnnotation(oasKey))
val constructorParameter: ParameterSpec.Builder = ParameterSpec.builder(name, wrappedType)
val discriminators = maybeDiscriminator.getDiscriminatorMappings(schemaName)
when (val discriminator = discriminators.first()) {
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/examples/companionObject/models/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ data class Cat(
val age: Int? = null,
@get:JsonProperty("petType")
@get:NotNull
@param:JsonProperty("petType")
override val petType: String = "Cat"
) : Pet(id, name, tag) {
companion object
Expand All @@ -56,6 +57,7 @@ data class Dog(
val breed: DogBreed? = null,
@get:JsonProperty("petType")
@get:NotNull
@param:JsonProperty("petType")
override val petType: String = "Dog"
) : Pet(id, name, tag) {
companion object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ data class DiscriminatedChild1(
val someProp: String? = null,
@get:JsonProperty("some_enum")
@get:NotNull
@param:JsonProperty("some_enum")
override val someEnum: ChildDiscriminator = ChildDiscriminator.OBJ_ONE_ONLY
) : ChildDefinition()

Expand All @@ -79,6 +80,7 @@ data class DiscriminatedChild2(
data class DiscriminatedChild3(
@get:JsonProperty("some_enum")
@get:NotNull
@param:JsonProperty("some_enum")
override val someEnum: ChildDiscriminator = ChildDiscriminator.OBJ_THREE
) : ChildDefinition()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ data class OneOfOne(
val oneOfOne: String? = null,
@get:JsonProperty("discriminator")
@get:NotNull
@param:JsonProperty("discriminator")
override val discriminator: String = "OneOfOne"
) : ParentOneOf()

Expand All @@ -99,6 +100,7 @@ data class OneOfTwo(
val oneOfTwo: String? = null,
@get:JsonProperty("discriminator")
@get:NotNull
@param:JsonProperty("discriminator")
override val discriminator: String = "OneOfTwo"
) : ParentOneOf()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ data class FirstModel(
val extraFirstAttr: List<String>? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.FIRST_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag), Serializable

Expand Down Expand Up @@ -135,6 +136,7 @@ data class SecondModel(
val extraSecondAttr: Boolean? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.SECOND_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag), Serializable

Expand Down Expand Up @@ -162,5 +164,6 @@ data class ThirdModel(
val extraSecondAttr: Int? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.THIRD_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag), Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ data class FirstModel(
val extraFirstAttr: List<String>? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.FIRST_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)

Expand Down Expand Up @@ -141,6 +142,7 @@ data class SecondModel(
val extraSecondAttr: Boolean? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.SECOND_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)

Expand Down Expand Up @@ -169,5 +171,6 @@ data class ThirdModel(
val extraSecondAttr: Int? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.THIRD_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ data class FirstModel(
val extraFirstAttr: List<String>? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.FIRST_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)

Expand Down Expand Up @@ -141,6 +142,7 @@ data class SecondModel(
val extraSecondAttr: Boolean? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.SECOND_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)

Expand Down Expand Up @@ -169,5 +171,6 @@ data class ThirdModel(
val extraSecondAttr: Int? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.THIRD_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ sealed class FirstLevelChild(
open val firstLevelField2: Int? = null,
@get:JsonProperty("rootDiscriminator")
@get:NotNull
@param:JsonProperty("rootDiscriminator")
override val rootDiscriminator: RootDiscriminator = RootDiscriminator.FIRST_LEVEL_CHILD
) : RootType(rootField1, rootField2) {
abstract val firstLevelDiscriminator: FirstLevelDiscriminator
Expand Down Expand Up @@ -137,6 +138,7 @@ sealed class SecondLevelChild1(
open val metadata: SecondLevelMetadata,
@get:JsonProperty("firstLevelDiscriminator")
@get:NotNull
@param:JsonProperty("firstLevelDiscriminator")
override val firstLevelDiscriminator: FirstLevelDiscriminator =
FirstLevelDiscriminator.SECOND_LEVEL_CHILD1
) : FirstLevelChild(rootField1, rootField2, firstLevelField1, firstLevelField2) {
Expand Down Expand Up @@ -179,6 +181,7 @@ sealed class SecondLevelChild2(
open val metadata: SecondLevelMetadata,
@get:JsonProperty("firstLevelDiscriminator")
@get:NotNull
@param:JsonProperty("firstLevelDiscriminator")
override val firstLevelDiscriminator: FirstLevelDiscriminator =
FirstLevelDiscriminator.SECOND_LEVEL_CHILD2
) : FirstLevelChild(rootField1, rootField2, firstLevelField1, firstLevelField2) {
Expand Down Expand Up @@ -235,6 +238,7 @@ data class ThirdLevelChild11(
val creationDate: Int,
@get:JsonProperty("secondLevelDiscriminator")
@get:NotNull
@param:JsonProperty("secondLevelDiscriminator")
override val secondLevelDiscriminator: SecondLevelDiscriminator =
SecondLevelDiscriminator.THIRD_LEVEL_CHILD1
) : SecondLevelChild1(rootField1, rootField2, firstLevelField1, firstLevelField2, metadata)
Expand Down Expand Up @@ -265,6 +269,7 @@ data class ThirdLevelChild12(
val isDeleted: Boolean,
@get:JsonProperty("secondLevelDiscriminator")
@get:NotNull
@param:JsonProperty("secondLevelDiscriminator")
override val secondLevelDiscriminator: SecondLevelDiscriminator =
SecondLevelDiscriminator.THIRD_LEVEL_CHILD2
) : SecondLevelChild1(rootField1, rootField2, firstLevelField1, firstLevelField2, metadata)
Expand Down Expand Up @@ -295,6 +300,7 @@ data class ThirdLevelChild21(
val creationDate: Int,
@get:JsonProperty("secondLevelDiscriminator")
@get:NotNull
@param:JsonProperty("secondLevelDiscriminator")
override val secondLevelDiscriminator: SecondLevelDiscriminator =
SecondLevelDiscriminator.THIRD_LEVEL_CHILD1
) : SecondLevelChild2(rootField1, rootField2, firstLevelField1, firstLevelField2, metadata)
Expand Down Expand Up @@ -325,6 +331,7 @@ data class ThirdLevelChild22(
val isDeleted: Boolean,
@get:JsonProperty("secondLevelDiscriminator")
@get:NotNull
@param:JsonProperty("secondLevelDiscriminator")
override val secondLevelDiscriminator: SecondLevelDiscriminator =
SecondLevelDiscriminator.THIRD_LEVEL_CHILD2
) : SecondLevelChild2(rootField1, rootField2, firstLevelField1, firstLevelField2, metadata)
3 changes: 3 additions & 0 deletions src/test/resources/examples/okHttpClient/models/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ data class FirstModel(
val extraFirstAttr: List<String>? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.FIRST_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)

Expand Down Expand Up @@ -134,6 +135,7 @@ data class SecondModel(
val extraSecondAttr: Boolean? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.SECOND_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)

Expand Down Expand Up @@ -161,5 +163,6 @@ data class ThirdModel(
val extraSecondAttr: Int? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.THIRD_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ data class FirstModel(
val extraFirstAttr: List<String>? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.FIRST_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)

Expand Down Expand Up @@ -167,6 +168,7 @@ data class SecondModel(
val extraSecondAttr: Boolean? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.SECOND_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)

Expand Down Expand Up @@ -194,5 +196,6 @@ data class ThirdModel(
val extraSecondAttr: Int? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.THIRD_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class ChildTypeA(
val someString: String,
@get:JsonProperty("type")
@get:NotNull
@param:JsonProperty("type")
override val type: ParentType = ParentType.CHILD_TYPE_A
) : ParentSpec()

Expand All @@ -28,6 +29,7 @@ data class ChildTypeB(
val someInt: Int,
@get:JsonProperty("type")
@get:NotNull
@param:JsonProperty("type")
override val type: ParentType = ParentType.CHILD_TYPE_B
) : ParentSpec()

Expand Down Expand Up @@ -125,6 +127,7 @@ data class PolymorphicTypeOneA(
val whateverA: String? = null,
@get:JsonProperty("shared")
@get:NotNull
@param:JsonProperty("shared")
override val shared: String = "PolymorphicTypeOneA"
) : PolymorphicSuperTypeOne()

Expand All @@ -134,6 +137,7 @@ data class PolymorphicTypeOneB(
val whateverB: Int? = null,
@get:JsonProperty("shared")
@get:NotNull
@param:JsonProperty("shared")
override val shared: String = "PolymorphicTypeOneB"
) : PolymorphicSuperTypeOne()

Expand All @@ -143,6 +147,7 @@ data class PolymorphicTypeTwoA(
val whateverC: String? = null,
@get:JsonProperty("shared")
@get:NotNull
@param:JsonProperty("shared")
override val shared: String = "PolymorphicTypeTwoA"
) : PolymorphicSuperTypeTwo()

Expand All @@ -152,5 +157,6 @@ data class PolymorphicTypeTwoB(
val whateverD: Int? = null,
@get:JsonProperty("shared")
@get:NotNull
@param:JsonProperty("shared")
override val shared: String = "PolymorphicTypeTwoB"
) : PolymorphicSuperTypeTwo()
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ data class PolymorphicTypeOne(
val childOneName: String? = null,
@get:JsonProperty("generation")
@get:NotNull
@param:JsonProperty("generation")
override val generation: String = "PolymorphicTypeOne"
) : PolymorphicSuperType(firstName, lastName)

Expand All @@ -69,6 +70,7 @@ data class PolymorphicTypeOneAnotherRef(
val childOneName: String? = null,
@get:JsonProperty("generation")
@get:NotNull
@param:JsonProperty("generation")
override val generation: String = "PolymorphicTypeOne"
) : PolymorphicSuperType(firstName, lastName)

Expand All @@ -86,6 +88,7 @@ data class PolymorphicTypeOneRef(
val childOneName: String? = null,
@get:JsonProperty("generation")
@get:NotNull
@param:JsonProperty("generation")
override val generation: String = "PolymorphicTypeOne"
) : PolymorphicSuperType(firstName, lastName)

Expand All @@ -106,6 +109,7 @@ data class PolymorphicTypeTwo(
val childTwoAge: Int? = null,
@get:JsonProperty("generation")
@get:NotNull
@param:JsonProperty("generation")
override val generation: String = "polymorphic_type_two"
) : PolymorphicSuperType(firstName, lastName)

Expand All @@ -126,5 +130,6 @@ data class PolymorphicTypeTwoRef(
val childTwoAge: Int? = null,
@get:JsonProperty("generation")
@get:NotNull
@param:JsonProperty("generation")
override val generation: String = "polymorphic_type_two"
) : PolymorphicSuperType(firstName, lastName)
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ data class PolymorphicTypeOneRef(
val childOneName: String? = null,
@get:JsonProperty("generation")
@get:NotNull
@param:JsonProperty("generation")
override val generation: String = "PolymorphicTypeOne"
) : PolymorphicSuperType(firstName, lastName)

Expand All @@ -63,6 +64,7 @@ data class PolymorphicTypeOneAnotherRef(
val childOneName: String? = null,
@get:JsonProperty("generation")
@get:NotNull
@param:JsonProperty("generation")
override val generation: String = "PolymorphicTypeOne"
) : PolymorphicSuperType(firstName, lastName)

Expand All @@ -83,6 +85,7 @@ data class PolymorphicTypeTwoRef(
val childTwoAge: Int? = null,
@get:JsonProperty("generation")
@get:NotNull
@param:JsonProperty("generation")
override val generation: String = "polymorphic_type_two"
) : PolymorphicSuperType(firstName, lastName)

Expand All @@ -100,6 +103,7 @@ data class PolymorphicTypeOne(
val childOneName: String? = null,
@get:JsonProperty("generation")
@get:NotNull
@param:JsonProperty("generation")
override val generation: String = "PolymorphicTypeOne"
) : PolymorphicSuperType(firstName, lastName)

Expand All @@ -120,5 +124,6 @@ data class PolymorphicTypeTwo(
val childTwoAge: Int? = null,
@get:JsonProperty("generation")
@get:NotNull
@param:JsonProperty("generation")
override val generation: String = "polymorphic_type_two"
) : PolymorphicSuperType(firstName, lastName)
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ data class FirstModel(
val extraFirstAttr: List<String>? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.FIRST_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)

Expand Down Expand Up @@ -141,6 +142,7 @@ data class SecondModel(
val extraSecondAttr: Boolean? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.SECOND_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)

Expand Down Expand Up @@ -169,5 +171,6 @@ data class ThirdModel(
val extraSecondAttr: Int? = null,
@get:JsonProperty("model_type")
@get:NotNull
@param:JsonProperty("model_type")
override val modelType: ContentModelType = ContentModelType.THIRD_MODEL
) : Content(id, firstAttr, secondAttr, thirdAttr, etag)

0 comments on commit f7b8788

Please sign in to comment.