Skip to content

Commit a0a4f80

Browse files
committed
extra option override test
1 parent fb79dff commit a0a4f80

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,32 @@ class ModelPropertyParserTest extends FlatSpec with Matchers {
160160
requiredItems shouldBe List("forcedRequired", "required")
161161
}
162162

163+
it should "process all properties as required barring Option[_] or if overridden in annotation (Schema annotation)" in {
164+
val schemas = ModelConverters
165+
.getInstance()
166+
.readAll(classOf[ModelWithOptionAndNonOption2])
167+
.asScala
168+
169+
val model = schemas("ModelWithOptionAndNonOption2")
170+
model should not be (null)
171+
model.getProperties() should not be (null)
172+
173+
val optional = model.getProperties().get("optional")
174+
optional should not be (null)
175+
176+
val required = model.getProperties().get("required")
177+
required should not be (null)
178+
179+
val forcedRequired = model.getProperties().get("forcedRequired")
180+
forcedRequired should not be (null)
181+
182+
val forcedOptional = model.getProperties().get("forcedOptional")
183+
forcedOptional should not be (null)
184+
185+
val requiredItems = nullSafeList(model.getRequired)
186+
requiredItems shouldBe List("forcedRequired", "required")
187+
}
188+
163189
it should "handle null properties from converters later in the chain" in {
164190
object CustomConverter extends ModelConverter {
165191
override def resolve(`type`: AnnotatedType, context: ModelConverterContext, chain: util.Iterator[ModelConverter]): Schema[_] = {

src/test/scala/models/ModelWOptionString.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package models
22

33
import io.swagger.v3.oas.annotations.Parameter
4+
import io.swagger.v3.oas.annotations.media.Schema
45

56
case class ModelWOptionString (
67
stringOpt: Option[String],
@@ -14,3 +15,9 @@ case class ModelWithOptionAndNonOption(required: String,
1415
@Parameter(required = false) forcedOptional: String,
1516
@Parameter(required = true) forcedRequired: Option[String]
1617
)
18+
19+
case class ModelWithOptionAndNonOption2(required: String,
20+
optional: Option[String],
21+
@Schema(required = false, implementation = classOf[String]) forcedOptional: String,
22+
@Schema(required = true, implementation = classOf[String]) forcedRequired: Option[String]
23+
)

0 commit comments

Comments
 (0)