Skip to content

Commit 1a68540

Browse files
committed
add test
1 parent 1ed482c commit 1a68540

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

src/test/scala/com/github/swagger/scala/converter/ModelPropertyParserTest.scala

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
137137
model should be(defined)
138138
model.value.getProperties should not be (null)
139139
val field = model.value.getProperties().get("field")
140-
field shouldBe a[IntegerSchema]
140+
field shouldBe an[IntegerSchema]
141141
nullSafeSeq(model.value.getRequired) should not be empty
142142
}
143143

@@ -151,14 +151,14 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
151151
it should "process Model with Scala Option BigInt" in new PropertiesScope[ModelWOptionBigInt] {
152152
val optBigInt = model.value.getProperties().get("optBigInt")
153153
optBigInt should not be (null)
154-
optBigInt shouldBe a[IntegerSchema]
154+
optBigInt shouldBe an[IntegerSchema]
155155
model.value.getRequired shouldBe null
156156
}
157157

158158
it should "process Model with Scala Option Int" in new PropertiesScope[ModelWOptionInt] {
159159
val optInt = model.value.getProperties().get("optInt")
160160
optInt should not be (null)
161-
optInt shouldBe a[IntegerSchema]
161+
optInt shouldBe an[IntegerSchema]
162162
optInt.asInstanceOf[IntegerSchema].getFormat shouldEqual "int32"
163163
model.value.getRequired shouldBe null
164164
}
@@ -167,14 +167,25 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
167167
val optInt = model.value.getProperties().get("optInt")
168168
optInt should not be (null)
169169
if (RuntimeUtil.isScala3()) {
170-
optInt shouldBe a[ObjectSchema]
170+
optInt shouldBe an[ObjectSchema]
171171
} else {
172-
optInt shouldBe a[IntegerSchema]
172+
optInt shouldBe an[IntegerSchema]
173173
optInt.asInstanceOf[IntegerSchema].getFormat shouldEqual "int32"
174174
}
175175
model.value.getRequired shouldBe null
176176
}
177177

178+
it should "process AddRequest" in new PropertiesScope[AddRequest] {
179+
val numbers = model.value.getProperties().get("numbers")
180+
numbers should not be (null)
181+
numbers shouldBe an[ArraySchema]
182+
val arraySchema = numbers.asInstanceOf[ArraySchema]
183+
arraySchema.getMinItems shouldEqual 2
184+
arraySchema.getMaxItems shouldEqual 10
185+
// TODO - this should be an IntegerSchema but the @ArraySchema annotation items schema is not being picked up
186+
// arraySchema.getItems shouldBe an[IntegerSchema]
187+
}
188+
178189
it should "process Model without any properties" in new TestScope {
179190
val schemas = converter.readAll(classOf[NoProperties]).asScala.toMap
180191
val model = schemas.get("NoProperties")
@@ -187,7 +198,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
187198
it should "process Model with nested Scala Option Int with Schema Override" in new PropertiesScope[ModelWOptionIntSchemaOverride] {
188199
val optInt = model.value.getProperties().get("optInt")
189200
optInt should not be (null)
190-
optInt shouldBe a[IntegerSchema]
201+
optInt shouldBe an[IntegerSchema]
191202
optInt.asInstanceOf[IntegerSchema].getFormat shouldEqual "int32"
192203
optInt.getDescription shouldBe "This is an optional int"
193204
model.value.getRequired shouldBe null
@@ -196,7 +207,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
196207
it should "process Model with Scala Option Int with Schema Override" in new PropertiesScope[ModelWOptionIntSchemaOverride] {
197208
val optInt = model.value.getProperties().get("optInt")
198209
optInt should not be (null)
199-
optInt shouldBe a[IntegerSchema]
210+
optInt shouldBe an[IntegerSchema]
200211
optInt.asInstanceOf[IntegerSchema].getFormat shouldEqual "int32"
201212
optInt.getDescription shouldBe "This is an optional int"
202213
model.value.getRequired shouldBe null
@@ -334,7 +345,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
334345
it should "process Model with Scala Option Long (Some Default)" in new PropertiesScope[ModelWOptionLongWithSomeDefault] {
335346
val optLong = model.value.getProperties().get("optLong")
336347
optLong should not be (null)
337-
optLong shouldBe a[IntegerSchema]
348+
optLong shouldBe an[IntegerSchema]
338349
optLong.asInstanceOf[IntegerSchema].getFormat shouldEqual "int64"
339350
optLong.getDefault shouldEqual Long.MaxValue
340351
model.value.getRequired shouldBe null
@@ -343,23 +354,23 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
343354
it should "process Model with Scala Option Long" in new PropertiesScope[ModelWOptionLong] {
344355
val optLong = model.value.getProperties().get("optLong")
345356
optLong should not be (null)
346-
optLong shouldBe a[IntegerSchema]
357+
optLong shouldBe an[IntegerSchema]
347358
optLong.asInstanceOf[IntegerSchema].getFormat shouldEqual "int64"
348359
model.value.getRequired shouldBe null
349360
}
350361

351362
it should "process Model with Scala Option Long with Schema Override" in new PropertiesScope[ModelWOptionLongSchemaOverride] {
352363
val optLong = model.value.getProperties().get("optLong")
353364
optLong should not be (null)
354-
optLong shouldBe a[IntegerSchema]
365+
optLong shouldBe an[IntegerSchema]
355366
optLong.asInstanceOf[IntegerSchema].getFormat shouldEqual "int64"
356367
model.value.getRequired shouldBe null
357368
}
358369

359370
it should "process Model with Scala Option Long with Schema Int Override" in new PropertiesScope[ModelWOptionLongSchemaIntOverride] {
360371
val optLong = model.value.getProperties().get("optLong")
361372
optLong should not be (null)
362-
optLong shouldBe a[IntegerSchema]
373+
optLong shouldBe an[IntegerSchema]
363374
optLong.asInstanceOf[IntegerSchema].getFormat shouldEqual "int32"
364375
model.value.getRequired shouldBe null
365376
}
@@ -572,7 +583,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
572583
val arraySchema = stringsField.asInstanceOf[ArraySchema]
573584
arraySchema.getUniqueItems shouldBe null
574585
arraySchema.getRequired shouldBe null
575-
arraySchema.getItems shouldBe a[ObjectSchema] // probably type erasure - ideally this would eval as StringSchema
586+
arraySchema.getItems shouldBe an[ObjectSchema] // probably type erasure - ideally this would eval as StringSchema
576587
// next line used to fail (https://github.com/swagger-akka-http/swagger-akka-http/issues/171)
577588
Json.mapper().writeValueAsString(model.value)
578589
}
@@ -620,7 +631,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
620631
stringsField shouldBe a[ArraySchema]
621632
val arraySchema = stringsField.asInstanceOf[ArraySchema]
622633
arraySchema.getUniqueItems() shouldBe (null)
623-
arraySchema.getItems shouldBe a[IntegerSchema]
634+
arraySchema.getItems shouldBe an[IntegerSchema]
624635
nullSafeMap(arraySchema.getProperties()) shouldBe empty
625636
nullSafeSeq(arraySchema.getRequired()) shouldBe empty
626637
}
@@ -633,7 +644,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
633644
stringsField shouldBe a[ArraySchema]
634645
val arraySchema = stringsField.asInstanceOf[ArraySchema]
635646
arraySchema.getUniqueItems() shouldBe (null)
636-
arraySchema.getItems shouldBe a[IntegerSchema]
647+
arraySchema.getItems shouldBe an[IntegerSchema]
637648
nullSafeMap(arraySchema.getProperties()) shouldBe empty
638649
arraySchema.getRequired() shouldBe null
639650
}
@@ -645,7 +656,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
645656
val arraySchema = stringsField.asInstanceOf[ArraySchema]
646657
arraySchema.getUniqueItems() shouldBe (null)
647658

648-
arraySchema.getItems shouldBe a[IntegerSchema]
659+
arraySchema.getItems shouldBe an[IntegerSchema]
649660
arraySchema.getItems.getDescription shouldBe "These are ints"
650661
nullSafeMap(arraySchema.getProperties()) shouldBe empty
651662
arraySchema.getRequired() shouldBe null
@@ -658,7 +669,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
658669
val arraySchema = stringsField.asInstanceOf[ArraySchema]
659670
arraySchema.getUniqueItems() shouldBe (null)
660671

661-
arraySchema.getItems shouldBe a[IntegerSchema]
672+
arraySchema.getItems shouldBe an[IntegerSchema]
662673
arraySchema.getItems.getDescription shouldBe "These are ints"
663674
nullSafeMap(arraySchema.getProperties()) shouldBe empty
664675
arraySchema.getRequired() shouldBe null
@@ -726,17 +737,17 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
726737

727738
it should "process EchoList" in new PropertiesScope[EchoList] {
728739
val val1Field = model.value.getProperties.get("val1")
729-
val1Field shouldBe a[IntegerSchema]
740+
val1Field shouldBe an[IntegerSchema]
730741
val val2Field = model.value.getProperties.get("val2")
731-
val2Field shouldBe a[IntegerSchema]
742+
val2Field shouldBe an[IntegerSchema]
732743
model.value.getRequired().asScala shouldEqual Seq("val1", "val2")
733744
}
734745

735746
it should "process ModelWGetFunction" in new PropertiesScope[ModelWGetFunction] {
736747
val props = nullSafeMap(model.value.getProperties)
737748
props should have size 1
738749
val amountField = props.get("amount").value
739-
amountField shouldBe a[IntegerSchema]
750+
amountField shouldBe an[IntegerSchema]
740751
amountField.asInstanceOf[IntegerSchema].getFormat shouldEqual "int64"
741752

742753
nullSafeSeq(model.value.getRequired) shouldEqual Seq("amount")
@@ -746,7 +757,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
746757
val props = nullSafeMap(model.value.getProperties)
747758
props should have size 1
748759
val amountField = props.get("amount").value
749-
amountField shouldBe a[IntegerSchema]
760+
amountField shouldBe an[IntegerSchema]
750761
amountField.asInstanceOf[IntegerSchema].getFormat shouldEqual "int64"
751762

752763
model.value.getRequired shouldBe null
@@ -756,7 +767,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
756767
val props = nullSafeMap(model.value.getProperties)
757768
props should have size 1
758769
val amountField = props.get("amount").value
759-
amountField shouldBe a[IntegerSchema]
770+
amountField shouldBe an[IntegerSchema]
760771
amountField.asInstanceOf[IntegerSchema].getFormat shouldEqual "int64"
761772

762773
nullSafeSeq(model.value.getRequired) shouldEqual Seq("amount")
@@ -803,7 +814,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
803814
val catProps = nullSafeMap(catModel.value.getProperties)
804815
catProps should have size 3
805816
catProps.get("name").value shouldBe a[StringSchema]
806-
catProps.get("age").value shouldBe a[IntegerSchema]
817+
catProps.get("age").value shouldBe an[IntegerSchema]
807818
catProps.get("animalType").value shouldBe a[StringSchema]
808819
nullSafeSeq(catModel.value.getRequired) shouldEqual Seq("age", "animalType", "name")
809820
val dogModel = findModel(schemas, "Dog")

src/test/scala/com/github/swagger/scala/converter/ScalaModelTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class ScalaModelTest extends AnyFlatSpec with Matchers {
6363
val schemas = ModelConverters.getInstance().readAll(classOf[SimpleUser]).asScala
6464
val userSchema = schemas("SimpleUser")
6565
val id = userSchema.getProperties().get("id")
66-
id shouldBe a[IntegerSchema]
66+
id shouldBe an[IntegerSchema]
6767

6868
val name = userSchema.getProperties().get("name")
6969
name shouldBe a[StringSchema]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package models
2+
3+
import io.swagger.v3.oas.annotations.media.{ArraySchema, Schema}
4+
5+
case class AddRequest(@ArraySchema(items = new Schema(implementation = classOf[Long]), minItems = 2, maxItems = 10)
6+
numbers: Array[Double])

0 commit comments

Comments
 (0)