@@ -6,10 +6,12 @@
7module Data.Schematic.Schema where
7module Data.Schematic.Schema where
9+import Data.Functor.Foldable
9import Data.Kind hiding (Type)
10import Data.Kind hiding (Type)
10import Data.Proxy
11import Data.Proxy
11import Data.Schematic.Validation
12import Data.Schematic.Validation
12import Data.Text (Text)
13import Data.Text (Text)
13import GHC.TypeLits (KnownNat, natVal, KnownSymbol, symbolVal, Symbol, Nat)
15import GHC.TypeLits (KnownNat, natVal, KnownSymbol, symbolVal, Symbol, Nat)
@@ -79,13 +81,13 @@ class SchemaConstructor jty where
79 constructor :: Proxy jty -> [CRepr jty] -> Schema
81 constructor :: Proxy jty -> [CRepr jty] -> Schema
81instance SchemaConstructor 'JText where
83instance SchemaConstructor 'JText where
82− constructor _ = SchemaText SJText
84+ constructor _ = Fix . SchemaText SJText
84instance SchemaConstructor 'JNumber where
86instance SchemaConstructor 'JNumber where
85− constructor _ = SchemaNumber SJNumber
87+ constructor _ = Fix . SchemaNumber SJNumber
87instance SchemaConstructor 'JObject where
89instance SchemaConstructor 'JObject where
88− constructor _ = SchemaObject SJObject
90+ constructor _ = Fix . SchemaObject SJObject
90class Schematic ty where
92class Schematic ty where
91 type JT (ty :: k) :: JType
93 type JT (ty :: k) :: JType
@@ -128,11 +130,40 @@ instance
128 => Schematic (SArray cs s) where
130 => Schematic (SArray cs s) where
129 type JT (SArray cs s) = 'JArray
131 type JT (SArray cs s) = 'JArray
130 build _ =
132 build _ =
131− SchemaArray
133+ Fix $ SchemaArray
133 (schema (Proxy @'JArray) (Proxy @cs))
135 (schema (Proxy @'JArray) (Proxy @cs))
134 (build (Proxy @s))
136 (build (Proxy @s))
138+data Generate name ty
141+ ( Verifiable JText cs
142+ , KnownSymbol name, Schematic ty )
143+ => Schematic (Generate name (SText cs)) where
144+ type JT (Generate name (SText cs)) = JT (SText cs)
145+ build _ = build (Proxy @(SText cs))
148+ ( Verifiable JNumber cs
149+ , KnownSymbol name, Schematic ty )
150+ => Schematic (Generate name (SNumber cs)) where
151+ type JT (Generate name (SNumber cs)) = JT (SNumber cs)
152+ build _ = build (Proxy @(SNumber cs))
155+ ( Verifiable JArray cs
157+ => Schematic (Generate name (SArray cs s)) where
158+ type JT (Generate name (SArray cs s)) = JT (SArray cs s)
159+ build _ = build (Proxy @(SArray cs s))
162+ (Verifiable JObject els)
163+ => Schematic (Generate name (SObject els)) where
164+ type JT (Generate name (SObject els)) = JT (SObject els)
165+ build _ = build (Proxy @(SObject els))
136-- | Shows it's top-level definition according to the json-schema
167-- | Shows it's top-level definition according to the json-schema
137class TopLevel spec
168class TopLevel spec