11package com .github .swagger .scala .converter
22
3- import com .fasterxml .jackson .module .scala .introspect .ScalaAnnotationIntrospector
43import io .swagger .v3 .core .converter ._
54import io .swagger .v3 .core .util .Json
65import io .swagger .v3 .oas .models .media ._
@@ -107,10 +106,14 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
107106 val model = schemas.get(" ModelWOptionInt" )
108107 model should be (defined)
109108 model.value.getProperties should not be (null )
110- val optInt = model.value.getProperties.get(" optInt" )
109+ val optInt = model.value.getProperties() .get(" optInt" )
111110 optInt should not be (null )
112- optInt shouldBe a [IntegerSchema ]
113- optInt.asInstanceOf [IntegerSchema ].getFormat shouldEqual " int32"
111+ if (RuntimeUtil .isScala3()) {
112+ optInt shouldBe a[ObjectSchema ]
113+ } else {
114+ optInt shouldBe a[IntegerSchema ]
115+ optInt.asInstanceOf [IntegerSchema ].getFormat shouldEqual " int32"
116+ }
114117 nullSafeList(model.value.getRequired) shouldBe empty
115118 }
116119
@@ -122,8 +125,12 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
122125 model.value.getProperties should not be (null )
123126 val optInt = model.value.getProperties().get(" optInt" )
124127 optInt should not be (null )
125- optInt shouldBe a [IntegerSchema ]
126- optInt.asInstanceOf [IntegerSchema ].getFormat shouldEqual " int32"
128+ if (RuntimeUtil .isScala3()) {
129+ optInt shouldBe a[ObjectSchema ]
130+ } else {
131+ optInt shouldBe a[IntegerSchema ]
132+ optInt.asInstanceOf [IntegerSchema ].getFormat shouldEqual " int32"
133+ }
127134 optInt.getDescription shouldBe " This is an optional int"
128135 nullSafeList(model.value.getRequired) shouldBe empty
129136 }
@@ -136,7 +143,12 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
136143 model.value.getProperties should not be (null )
137144 val optInt = model.value.getProperties().get(" optInt" )
138145 optInt should not be (null )
139- optInt shouldBe an [IntegerSchema ]
146+ if (RuntimeUtil .isScala3()) {
147+ optInt shouldBe a[ObjectSchema ]
148+ } else {
149+ optInt shouldBe a[IntegerSchema ]
150+ optInt.asInstanceOf [IntegerSchema ].getFormat shouldEqual " int32"
151+ }
140152 nullSafeList(model.value.getRequired) shouldEqual Seq (" optInt" )
141153 }
142154
@@ -148,27 +160,13 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
148160 model.value.getProperties should not be (null )
149161 val optLong = model.value.getProperties().get(" optLong" )
150162 optLong should not be (null )
151- optLong shouldBe a [IntegerSchema ]
152- nullSafeList(model.value.getRequired) shouldBe empty
153- }
154-
155- // needs investigation
156- it should " process Model with Scala Option Long (with jackson model override)" ignore {
157- ScalaAnnotationIntrospector .registerReferencedValueType(
158- classOf [ModelWOptionLong ], " optLong" , classOf [Long ])
159- try {
160- val converter = ModelConverters .getInstance()
161- val schemas = converter.readAll(classOf [ModelWOptionLong ]).asScala.toMap
162- val model = schemas.get(" ModelWOptionLong" )
163- model should be (defined)
164- model.value.getProperties should not be (null )
165- val optLong = model.value.getProperties().get(" optLong" )
166- optLong shouldBe a [IntegerSchema ]
163+ if (RuntimeUtil .isScala3()) {
164+ optLong shouldBe a[ObjectSchema ]
165+ } else {
166+ optLong shouldBe a[IntegerSchema ]
167167 optLong.asInstanceOf [IntegerSchema ].getFormat shouldEqual " int64"
168- nullSafeList(model.value.getRequired) shouldBe empty
169- } finally {
170- ScalaAnnotationIntrospector .clearRegisteredReferencedTypes()
171168 }
169+ nullSafeList(model.value.getRequired) shouldBe empty
172170 }
173171
174172 it should " process Model with Scala Option Long with Schema Override" in {
@@ -350,7 +348,11 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
350348 stringsField shouldBe a[ArraySchema ]
351349 val arraySchema = stringsField.asInstanceOf [ArraySchema ]
352350 arraySchema.getUniqueItems() shouldBe (null )
353- arraySchema.getItems shouldBe a[IntegerSchema ]
351+ if (RuntimeUtil .isScala3()) {
352+ arraySchema.getItems shouldBe a[ObjectSchema ]
353+ } else {
354+ arraySchema.getItems shouldBe a[IntegerSchema ]
355+ }
354356 nullSafeMap(arraySchema.getProperties()) shouldBe empty
355357 nullSafeList(arraySchema.getRequired()) shouldBe empty
356358 }
@@ -368,8 +370,11 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
368370 val arraySchema = stringsField.asInstanceOf [ArraySchema ]
369371 arraySchema.getUniqueItems() shouldBe (null )
370372
371-
372- arraySchema.getItems shouldBe a[IntegerSchema ]
373+ if (RuntimeUtil .isScala3()) {
374+ arraySchema.getItems shouldBe a[ObjectSchema ]
375+ } else {
376+ arraySchema.getItems shouldBe a[IntegerSchema ]
377+ }
373378 arraySchema.getItems.getDescription shouldBe " These are ints"
374379 nullSafeMap(arraySchema.getProperties()) shouldBe empty
375380 nullSafeList(arraySchema.getRequired()) shouldBe empty
0 commit comments