json-spec-elm-servant 0.4.3.0 → 0.4.4.0
raw patch · 2 files changed
+25/−8 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.JsonSpec.Elm.Servant: generateElmExtra :: forall {k} (api :: k). Elmable api => OsPath -> Proxy api -> Set Definition -> IO ()
Files
json-spec-elm-servant.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: json-spec-elm-servant-version: 0.4.3.0+version: 0.4.4.0 synopsis: Generated elm code for servant APIs. description: Generate Elm encoders, decoders, and API requests for an Servant API, where the shape of the data
src/Data/JsonSpec/Elm/Servant.hs view
@@ -19,6 +19,7 @@ -- * Generating Elm Clients servantDefs, generateElm,+ generateElmExtra, -- * Extensions {-|@@ -45,7 +46,6 @@ ( HasJsonDecodingSpec(DecodingSpec), HasJsonEncodingSpec(EncodingSpec) ) import Data.JsonSpec.Elm (HasType(decoderOf, encoderOf, typeOf), Definitions)-import Data.List (drop, foldl', init, unlines) import Data.Maybe (fromJust, fromMaybe, mapMaybe) import Data.Proxy (Proxy(Proxy)) import Data.Set (Set)@@ -60,10 +60,11 @@ import Language.Elm.Type (Type) import Network.HTTP.Types (Method) import Prelude- ( Applicative(pure), Bool(False, True), Eq((==)), Foldable(foldr, length)- , Functor(fmap), Maybe(Just, Nothing), Monad((>>=)), Monoid(mconcat)- , Semigroup((<>)), Show(show), Traversable(sequence, traverse), ($), (.)- , (<$>), IO, Int, String, error, putStrLn, reverse+ ( Applicative(pure), Bool(False, True), Eq((==))+ , Foldable(foldl', foldr, length), Functor(fmap), Maybe(Just, Nothing)+ , Monad((>>=)), Monoid(mconcat, mempty), Semigroup((<>)), Show(show)+ , Traversable(sequence, traverse), ($), (.), (<$>), IO, Int, String, drop+ , error, init, putStrLn, reverse, unlines ) import Prettyprinter (defaultLayoutOptions, layoutPretty) import Prettyprinter.Render.Text (renderStrict)@@ -749,7 +750,23 @@ => OsPath {-^ The directory in which to deposit Elm code. -} -> Proxy api -> IO ()-generateElm dir Proxy = do+generateElm dir proxy =+ generateElmExtra dir proxy mempty+++{-|+ Like 'generateElm', but allow for some extra definitions to be+ added. This might be useful for piling on elm definitions that need+ to be decoded by the front end but which are not directly referenced+ in your servant API (e.g. a common response body for error responses).+-}+generateElmExtra+ :: forall api. (Elmable api)+ => OsPath {-^ The directory in which to deposit Elm code. -}+ -> Proxy api+ -> Set Definition {-^ Any extra definitions you want added. -}+ -> IO ()+generateElmExtra dir Proxy extra = do definitions :: HashMap Module Text <- traverse@@ -761,7 +778,7 @@ ) . modules . Set.toList- $ servantDefs (Proxy @api)+ $ servantDefs (Proxy @api) <> extra doesDirectoryExist dir >>= \case False -> do