@@ -4,29 +4,29 @@ import org.scalatest.{FreeSpec, Inside, Matchers}
4
4
import cats .data .NonEmptyList
5
5
import cats .data .Validated
6
6
import SchemaError ._
7
+ import com .timeout .docless .schema .JsonSchema
7
8
import com .timeout .docless .schema .JsonSchema ._
8
9
import com .timeout .docless .swagger .Method ._
9
- import com .timeout .docless .swagger .Path ._
10
10
11
11
class PathGroupTest extends FreeSpec with Matchers {
12
12
" PathGroup" - {
13
13
val petstore = PetstoreSchema ()
14
14
val pet = PetstoreSchema .Schemas .pet
15
15
16
- val paths = Path (" example" ) :: petstore.paths.get.toList
16
+ val paths = Path (" / example" ) :: petstore.paths.get.toList
17
17
val defs = petstore.definitions.get.toList
18
18
val defsNoPet = defs.filterNot(_.id === pet.id)
19
19
val params = petstore.parameters.get.toList
20
20
21
21
val group1 = PathGroup (paths, defs, params)
22
- val group2 = PathGroup (List (Path (" extra" )), Nil , Nil )
22
+ val group2 = PathGroup (List (Path (" / extra" )), Nil , Nil )
23
23
val groupMissingErr = PathGroup (paths, defsNoPet, params)
24
24
25
25
def err (path : String , m : Method , f : Definition => Ref ): SchemaError =
26
- missingDefinition(ResponseRef (f(pet.definition), path, m ))
26
+ missingDefinition(RefWithContext .response (f(pet.definition), m, path ))
27
27
28
28
" aggregate" - {
29
- " when some definitions are missing" - {
29
+ " when some top level definitions are missing" - {
30
30
" returns the missing refs" in {
31
31
PathGroup .aggregate(petstore.info, List (groupMissingErr)) should === (
32
32
Validated .invalid[NonEmptyList [SchemaError ], APISchema ](
@@ -40,6 +40,37 @@ class PathGroupTest extends FreeSpec with Matchers {
40
40
)
41
41
}
42
42
}
43
+ " when some nested definitions are missing" - {
44
+ val info = Info (" example" )
45
+ case class Nested (name : String )
46
+ case class TopLevel (nested : Nested )
47
+
48
+ val schema = JsonSchema .deriveFor[TopLevel ]
49
+ val nested = schema.relatedDefinitions.head
50
+
51
+ val paths = List (
52
+ " /example" .Post (
53
+ Operation (' _ , " ..." )
54
+ .withParams(BodyParameter (schema = Some (schema.asRef)))
55
+ )
56
+ )
57
+
58
+ val withNested = PathGroup (paths, schema.definitions.toList, Nil )
59
+ val withoutNested = PathGroup (paths, List (schema.definition), Nil )
60
+
61
+ " returns the missing refs" in {
62
+ PathGroup .aggregate(info, List (withNested)).isValid shouldBe true
63
+ PathGroup .aggregate(info, List (withoutNested)) should === (
64
+ Validated .invalid[NonEmptyList [SchemaError ], APISchema ](
65
+ NonEmptyList .of(
66
+ MissingDefinition (
67
+ RefWithContext .definition(nested.asRef, schema.definition)
68
+ )
69
+ )
70
+ )
71
+ )
72
+ }
73
+ }
43
74
" when no definition is missing" - {
44
75
" returns a valid api schema" in new Inside {
45
76
inside(PathGroup .aggregate(petstore.info, List (group1, group2))) {
0 commit comments