packages feed

highjson-th (empty) → 0.4.0.0

raw patch · 6 files changed

+156/−0 lines, 6 filesdep +QuickCheckdep +aesondep +basesetup-changed

Dependencies added: QuickCheck, aeson, base, bytestring, highjson, highjson-swagger, highjson-th, hspec, lens, swagger2, template-haskell, text

Files

+ Data/HighJson/TH.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE TemplateHaskell #-}+module Data.HighJson.TH+    ( deriveJsonSwagger+    , jsonSerializer, jsonEncoder, jsonParser+    , makeDeclareNamedSchema+    , ToSchema(..)+    , ToJSON(..), FromJSON(..)+    )+where++import Data.Aeson+import Data.Swagger+import Language.Haskell.TH++import Data.HighJson (jsonSerializer, jsonEncoder, jsonParser)+import Data.HighJson.Swagger (makeDeclareNamedSchema)++deriveJsonSwagger :: Name -> Name -> Q [Dec]+deriveJsonSwagger typ spec =+    [d|+     instance ToJSON $(conT typ) where+         toJSON = jsonSerializer $(varE spec)+         toEncoding = jsonEncoder $(varE spec)+     instance FromJSON $(conT typ) where+         parseJSON = jsonParser $(varE spec)+     instance ToSchema $(conT typ) where+         declareNamedSchema p = makeDeclareNamedSchema $(varE spec) p+    |]
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2017 Alexander Thiemann <mail@athiemann.net>++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ highjson-th.cabal view
@@ -0,0 +1,55 @@+name:                highjson-th+version:             0.4.0.0+synopsis:            Template Haskell helpers for highjson specs+description:         Template Haskell helpers for highjson specs+homepage:            https://github.com/agrafix/highjson+bug-reports:         https://github.com/agrafix/highjson/issues+license:             MIT+license-file:        LICENSE+author:              Alexander Thiemann <mail@athiemann.net>+maintainer:          Alexander Thiemann <mail@athiemann.net>+copyright:           (c) 2017 Alexander Thiemann+category:            Text, Web, JSON+build-type:          Simple+stability:           experimental+cabal-version:       >=1.10+tested-with:         GHC==8.0.1++library+  exposed-modules:+                  Data.HighJson.TH+  build-depends:+                base >=4.8 && <5,+                highjson >= 0.4,+                highjson-swagger >= 0.4,+                text,+                template-haskell >= 2.10,+                aeson,+                swagger2+  hs-source-dirs:      .+  default-language:    Haskell2010++test-suite highjson-th-tests+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             Main.hs+  other-modules:+                Data.HighJson.THSpec+  build-depends:+                QuickCheck >=2.8,+                base,+                highjson,+                highjson-swagger,+                highjson-th,+                aeson,+                hspec >= 2.0,+                text,+                lens,+                swagger2,+                bytestring+  default-language:    Haskell2010+  ghc-options: -Wall -fno-warn-orphans++source-repository head+  type:     git+  location: git://github.com/agrafix/highjson.git
+ test/Data/HighJson/THSpec.hs view
@@ -0,0 +1,42 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TemplateHaskell #-}+module Data.HighJson.THSpec+    ( spec )+where++import Data.HighJson+import Data.HighJson.TH++import Control.Lens.TH+import Data.Swagger+import Test.Hspec+import Test.QuickCheck hiding (Success)++data SomeSum+    = SomeSumInt Int+    | SomeSumDummy Bool+    deriving (Show, Eq)++makePrisms ''SomeSum++someSumSpec :: SumTypeSpec SomeSum '[Int, Bool]+someSumSpec =+    sumSpec "some sum" Nothing $+    "int" .-> _SomeSumInt+    :& "dummy" .-> _SomeSumDummy++$(deriveJsonSwagger ''SomeSum 'someSumSpec)++instance Arbitrary SomeSum where+    arbitrary =+        oneof+        [ SomeSumInt <$> arbitrary+        , SomeSumDummy <$> arbitrary+        ]++spec :: Spec+spec =+    it "should work for sum types" $+    property $ \(t :: SomeSum) -> validateToJSON t `shouldBe` []
+ test/Main.hs view
@@ -0,0 +1,9 @@+module Main where++import qualified Data.HighJson.THSpec++import Test.Hspec++main :: IO ()+main = hspec $+    do Data.HighJson.THSpec.spec