Skip to content

Commit 90050a2

Browse files
authored
Add reproduction test for UnsupportedOperationException (#206)
* Add reproduction test for UnsupportedOperationException caused by java.base/java.util.AbstractMap.put on a scala wrapped hash map, which the properties are initialized with when unwanted properties are filtered out. branch: * Initialize properties with Java hashmap to prevent it from being a scala wrapped hasmap branch:
1 parent 2b3a3f8 commit 90050a2

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/main/scala/com/github/swagger/scala/converter/SwaggerScalaModelConverter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class SwaggerScalaModelConverter extends ModelResolver(SwaggerScalaModelConverte
252252
propNamesSet.contains(key)
253253
}
254254
if (originalProps.size > newProps.size) {
255-
schema.setProperties(newProps.asJava)
255+
schema.setProperties(new util.LinkedHashMap(newProps.asJava))
256256
}
257257
}
258258

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,16 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
594594
nullSafeSeq(model.value.getRequired) shouldEqual Seq("amount")
595595
}
596596

597+
it should "process ModelWGetFunction with optional field" in new PropertiesScope[ModelWGetFunctionWithOptionalField] {
598+
val props = nullSafeMap(model.value.getProperties)
599+
props should have size 1
600+
val amountField = props.get("amount").value
601+
amountField shouldBe a[IntegerSchema]
602+
amountField.asInstanceOf[IntegerSchema].getFormat shouldEqual "int64"
603+
604+
nullSafeSeq(model.value.getRequired) shouldBe empty
605+
}
606+
597607
it should "process ModelWJacksonAnnotatedGetFunction" in new PropertiesScope[ModelWJacksonAnnotatedGetFunction] {
598608
val props = nullSafeMap(model.value.getProperties)
599609
props should have size 1

src/test/scala/models/ModelWGetFunction.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ case class ModelWGetFunction(amount: Long) {
66
def getOptionalAmount(): Option[Long] = Some(amount)
77
}
88

9+
case class ModelWGetFunctionWithOptionalField(amount: Option[Long]) {
10+
def getOptionalAmount(): Option[Long] = amount
11+
}
12+
913
case class ModelWJacksonAnnotatedGetFunction(amount: Long) {
1014
@JsonIgnore def getOptionalAmount(): Option[Long] = Some(amount)
1115
}

0 commit comments

Comments
 (0)