git.iko.soy/typeable/schematic
on master help sign in
fix warnings
5771fa9Denis Redozubov
schematic.cabal+3−1
@@ -133,4 +133,6 @@ test-suite spec
133 , validationt >= 0.1.0.1
133 , validationt >= 0.1.0.1
134 , vinyl
134 , vinyl
135 other-modules: SchemaSpec
135 other-modules: SchemaSpec
136− , LensSpec
136+ , LensSpec
137+ , JsonSchemaSpec
138+ , MigrationSpec
src/Data/Schematic/JsonSchema.hs+1
@@ -4,6 +4,7 @@
4
4
5module Data.Schematic.JsonSchema
5module Data.Schematic.JsonSchema
6 ( toJsonSchema
6 ( toJsonSchema
7+ , toJsonSchema
7 ) where
8 ) where
8
9
9import Control.Monad.State.Strict
10import Control.Monad.State.Strict
test/LensSpec.hs+4−5
@@ -8,12 +8,12 @@ import Data.Vinyl
8import Test.Hspec
8import Test.Hspec
9
9
10
10
11−type ArraySchema = 'SchemaArray '[AEq 1] ('SchemaNumber '[NGt 10])
11+type ArraySchema = 'SchemaArray '[ 'AEq 1] ('SchemaNumber '[ 'NGt 10])
12
12
13type ArrayField = '("foo", ArraySchema)
13type ArrayField = '("foo", ArraySchema)
14
14
15type FieldsSchema =
15type FieldsSchema =
16− '[ ArrayField, '("bar", 'SchemaOptional ('SchemaText '[TEnum '["foo", "bar"]]))]
16+ '[ ArrayField, '("bar", 'SchemaOptional ('SchemaText '[ 'TEnum '["foo", "bar"]]))]
17
17
18type SchemaExample = 'SchemaObject FieldsSchema
18type SchemaExample = 'SchemaObject FieldsSchema
19
19
@@ -164,8 +164,8 @@ type BigRecord = Rec FieldRepr
164 , '("f130", 'SchemaNumber '[])
164 , '("f130", 'SchemaNumber '[])
165 ]
165 ]
166
166
167−bigRecord :: BigRecord
167+_bigRecord :: BigRecord
168−bigRecord =
168+_bigRecord =
169 FieldRepr (ReprNumber 1)
169 FieldRepr (ReprNumber 1)
170 :& FieldRepr (ReprNumber 2)
170 :& FieldRepr (ReprNumber 2)
171 :& FieldRepr (ReprNumber 3)
171 :& FieldRepr (ReprNumber 3)
@@ -298,7 +298,6 @@ bigRecord =
298 :& FieldRepr (ReprNumber 130)
298 :& FieldRepr (ReprNumber 130)
299 :& RNil
299 :& RNil
300
300
301−
302spec :: Spec
301spec :: Spec
303spec = do
302spec = do
304 let
303 let
test/SchemaSpec.hs+3−21
@@ -2,24 +2,18 @@
2
2
3module SchemaSpec (spec, main) where
3module SchemaSpec (spec, main) where
4
4
5−import Control.Monad
6import Data.ByteString.Lazy
5import Data.ByteString.Lazy
7import Data.Aeson
6import Data.Aeson
8import Data.Proxy
7import Data.Proxy
9import Data.Schematic
8import Data.Schematic
10−import Data.Singletons
11−import Data.Singletons.Prelude
12import Data.Vinyl
9import Data.Vinyl
13import Test.Hspec
10import Test.Hspec
14−import Test.Hspec.SmallCheck
15−import Test.SmallCheck
16−import Test.SmallCheck.Series.Instances
17
11
18
12
19type SchemaExample
13type SchemaExample
20 = 'SchemaObject
14 = 'SchemaObject
21− '[ '("foo", 'SchemaArray '[AEq 1] ('SchemaNumber '[NGt 10]))
15+ '[ '("foo", 'SchemaArray '[ 'AEq 1] ('SchemaNumber '[ 'NGt 10]))
22− , '("bar", 'SchemaOptional ('SchemaText '[TEnum '["foo", "bar"]]))]
16+ , '("bar", 'SchemaOptional ('SchemaText '[ 'TEnum '["foo", "bar"]]))]
23
17
24type TestMigration =
18type TestMigration =
25 'Migration "test_revision"
19 'Migration "test_revision"
@@ -28,15 +22,6 @@ type TestMigration =
28
22
29type VS = 'Versioned SchemaExample '[ TestMigration ]
23type VS = 'Versioned SchemaExample '[ TestMigration ]
30
24
31−exampleTest :: JsonRepr (SchemaOptional (SchemaText '[TEq 3]))
32−exampleTest = ReprOptional (Just (ReprText "lil"))
33−
34−exampleNumber :: JsonRepr (SchemaNumber '[NGt 10])
35−exampleNumber = ReprNumber 12
36−
37−exampleArray :: JsonRepr (SchemaArray '[AEq 1] (SchemaNumber '[NGt 10]))
38−exampleArray = ReprArray [exampleNumber]
39−
40jsonExample :: JsonRepr SchemaExample
25jsonExample :: JsonRepr SchemaExample
41jsonExample = ReprObject $
26jsonExample = ReprObject $
42 FieldRepr (ReprArray [ReprNumber 12])
27 FieldRepr (ReprArray [ReprNumber 12])
@@ -49,9 +34,6 @@ schemaJson = "{\"foo\": [13], \"bar\": null}"
49schemaJson2 :: ByteString
34schemaJson2 :: ByteString
50schemaJson2 = "{\"foo\": [3], \"bar\": null}"
35schemaJson2 = "{\"foo\": [3], \"bar\": null}"
51
36
52−schemaJsonTopVersion :: ByteString
53−schemaJsonTopVersion = "{ \"foo\": 42, \"bar\": \"bar\" }"
54−
55topObject
37topObject
56 :: JsonRepr
38 :: JsonRepr
57 ('SchemaObject
39 ('SchemaObject
@@ -88,7 +70,7 @@ spec = do
88 it "validates versioned json" $ do
70 it "validates versioned json" $ do
89 decodeAndValidateVersionedJson (Proxy @VS) schemaJson
71 decodeAndValidateVersionedJson (Proxy @VS) schemaJson
90 `shouldSatisfy` isValid
72 `shouldSatisfy` isValid
91− it "validates with Migration List" $ do
73+ it "validates versioned json with a migration list" $ do
92 decodeAndValidateVersionedWithMList
74 decodeAndValidateVersionedWithMList
93 (Proxy @VS)
75 (Proxy @VS)
94 ((:&&) (Proxy @(SchemaByRevision "test_revision" VS)) (const topObject) MNil)
76 ((:&&) (Proxy @(SchemaByRevision "test_revision" VS)) (const topObject) MNil)