1
1
package com .timeout .docless .schema
2
2
3
+ import com .timeout .docless .schema .JsonSchema .NamedDefinition
3
4
import com .timeout .docless .swagger .Responses .Response
4
5
import io .circe ._
5
6
import io .circe .syntax ._
@@ -19,6 +20,9 @@ trait JsonSchema[A] extends JsonSchema.HasRef {
19
20
20
21
def relatedDefinitions : Set [JsonSchema .Definition ]
21
22
23
+ def fieldDefinitions : Set [JsonSchema .NamedDefinition ] =
24
+ relatedDefinitions.collect { case d : NamedDefinition => d }
25
+
22
26
def jsonObject : JsonObject
23
27
24
28
def asJson : Json = jsonObject.asJson
@@ -30,8 +34,16 @@ trait JsonSchema[A] extends JsonSchema.HasRef {
30
34
31
35
def asJsonRef : Json = asObjectRef.asJson
32
36
33
- lazy val definition : JsonSchema .Definition =
34
- JsonSchema .Definition (id, relatedDefinitions.map(_.asRef), asJson)
37
+ def namedDefinition (fieldName : String ): NamedDefinition =
38
+ JsonSchema .NamedDefinition (
39
+ id,
40
+ fieldName,
41
+ relatedDefinitions.map(_.asRef),
42
+ asJson
43
+ )
44
+
45
+ lazy val definition : JsonSchema .UnnamedDefinition =
46
+ JsonSchema .UnnamedDefinition (id, relatedDefinitions.map(_.asRef), asJson)
35
47
36
48
def definitions : Set [JsonSchema .Definition ] =
37
49
relatedDefinitions + definition
@@ -49,27 +61,43 @@ object JsonSchema
49
61
with derive.CoprodInstances {
50
62
trait HasRef {
51
63
def id : String
52
- def asRef : Ref = TypeRef (id)
53
- def asArrayRef : Ref = ArrayRef (id)
64
+ def asRef : Ref = TypeRef (id, None )
65
+ def asArrayRef : Ref = ArrayRef (id, None )
54
66
}
55
67
56
- case class Definition (id : String , relatedRefs : Set [Ref ], json : Json )
57
- extends HasRef
68
+ sealed trait Definition extends HasRef {
69
+ def id : String
70
+ def json : Json
71
+ def relatedRefs : Set [Ref ]
72
+ }
73
+
74
+ case class UnnamedDefinition (id : String , relatedRefs : Set [Ref ], json : Json )
75
+ extends Definition
76
+
77
+ case class NamedDefinition (id : String ,
78
+ fieldName : String ,
79
+ relatedRefs : Set [Ref ],
80
+ json : Json )
81
+ extends Definition {
82
+ override def asRef = TypeRef (id, Some (fieldName))
83
+ override def asArrayRef = ArrayRef (id, Some (fieldName))
84
+ }
58
85
59
86
sealed trait Ref {
60
87
def id : String
88
+ def fieldName : Option [String ]
61
89
}
62
90
63
- case class TypeRef (id : String ) extends Ref
91
+ case class TypeRef (id : String , fieldName : Option [ String ] ) extends Ref
64
92
object TypeRef {
65
- def apply (definition : Definition ): TypeRef = TypeRef (definition.id)
66
- def apply (schema : JsonSchema [_]): TypeRef = TypeRef (schema.id)
93
+ def apply (definition : Definition ): TypeRef = TypeRef (definition.id, None )
94
+ def apply (schema : JsonSchema [_]): TypeRef = TypeRef (schema.id, None )
67
95
}
68
96
69
- case class ArrayRef (id : String ) extends Ref
97
+ case class ArrayRef (id : String , fieldName : Option [ String ] ) extends Ref
70
98
object ArrayRef {
71
- def apply (definition : Definition ): ArrayRef = ArrayRef (definition.id)
72
- def apply (schema : JsonSchema [_]): ArrayRef = ArrayRef (schema.id)
99
+ def apply (definition : Definition ): ArrayRef = ArrayRef (definition.id, None )
100
+ def apply (schema : JsonSchema [_]): ArrayRef = ArrayRef (schema.id, None )
73
101
}
74
102
75
103
trait PatternProperty [K ] {
0 commit comments