forked from OAI/OpenAPI-Specification
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModelsTest.scala
55 lines (48 loc) · 1.97 KB
/
ModelsTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import com.fasterxml.jackson.databind.JsonNode
import com.github.fge.jsonschema.core.exceptions.ProcessingException
import com.github.fge.jsonschema.main.{ JsonSchema, JsonSchemaFactory}
import com.github.fge.jsonschema.core.report.ProcessingReport
import com.github.fge.jackson.JsonLoader
import scala.io.Source
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
@RunWith(classOf[JUnitRunner])
class ModelsTest extends FlatSpec with ShouldMatchers with TestBase {
val schema = readSchema(true)
val factory = JsonSchemaFactory.byDefault()
val jsonSchema = factory.getJsonSchema(schema.get("definitions").get("definitions"))
it should "validate a models hash" in {
val json = Source.fromFile("fixtures/v2.0/json/models/models.json").mkString
val data = JsonLoader.fromString(json)
val report = jsonSchema.validate(data)
if(report.isSuccess == false)
println(report)
report.isSuccess should be (true)
}
it should "validate multiple models" in {
val json = Source.fromFile("fixtures/v2.0/json/models/multipleModels.json").mkString
val data = JsonLoader.fromString(json)
val report = jsonSchema.validate(data)
if(report.isSuccess == false)
println(report)
report.isSuccess should be (true)
}
it should "validate models with examples" in {
val json = Source.fromFile("fixtures/v2.0/json/models/modelWithExamples.json").mkString
val data = JsonLoader.fromString(json)
val report = jsonSchema.validate(data)
if(report.isSuccess == false)
println(report)
report.isSuccess should be (true)
}
it should "validate models with composition" in {
val json = Source.fromFile("fixtures/v2.0/json/models/modelWithComposition.json").mkString
val data = JsonLoader.fromString(json)
val report = jsonSchema.validate(data)
if(report.isSuccess == false)
println(report)
report.isSuccess should be (true)
}
}