diff --git a/Request.template.hs b/Request.template.hs index fa8a90f..e558c5b 100644 --- a/Request.template.hs +++ b/Request.template.hs @@ -22,6 +22,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -192,13 +193,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -218,11 +219,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -296,8 +297,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/additional-properties.yaml.out b/test/golden/additional-properties.yaml.out index cdf08f4..cc65013 100644 --- a/test/golden/additional-properties.yaml.out +++ b/test/golden/additional-properties.yaml.out @@ -108,6 +108,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -278,13 +279,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -304,11 +305,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -382,8 +383,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/bug-1.yaml.out b/test/golden/bug-1.yaml.out index e48fdcb..8bac502 100644 --- a/test/golden/bug-1.yaml.out +++ b/test/golden/bug-1.yaml.out @@ -94,6 +94,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -264,13 +265,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -290,11 +291,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -368,8 +369,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/bug-2.yaml.out b/test/golden/bug-2.yaml.out index ac77ad5..03a2ed2 100644 --- a/test/golden/bug-2.yaml.out +++ b/test/golden/bug-2.yaml.out @@ -94,6 +94,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -264,13 +265,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -290,11 +291,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -368,8 +369,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/csv.yaml.out b/test/golden/csv.yaml.out index 64ea806..057b628 100644 --- a/test/golden/csv.yaml.out +++ b/test/golden/csv.yaml.out @@ -108,6 +108,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -278,13 +279,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -304,11 +305,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -382,8 +383,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/datetime.yaml.out b/test/golden/datetime.yaml.out index f9c4ad9..ab80193 100644 --- a/test/golden/datetime.yaml.out +++ b/test/golden/datetime.yaml.out @@ -94,6 +94,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -264,13 +265,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -290,11 +291,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -368,8 +369,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/enum-bug.yaml.out b/test/golden/enum-bug.yaml.out index f1c32a2..100f0c9 100644 --- a/test/golden/enum-bug.yaml.out +++ b/test/golden/enum-bug.yaml.out @@ -97,6 +97,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -267,13 +268,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -293,11 +294,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -371,8 +372,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/enum.yaml.out b/test/golden/enum.yaml.out index 45baa53..1abea96 100644 --- a/test/golden/enum.yaml.out +++ b/test/golden/enum.yaml.out @@ -161,6 +161,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -331,13 +332,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -357,11 +358,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -435,8 +436,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/haskell-ext.yaml.out b/test/golden/haskell-ext.yaml.out index 0b30cc7..5e20749 100644 --- a/test/golden/haskell-ext.yaml.out +++ b/test/golden/haskell-ext.yaml.out @@ -112,6 +112,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -282,13 +283,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -308,11 +309,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -386,8 +387,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/headers.yaml.out b/test/golden/headers.yaml.out index 189635a..b1e0654 100644 --- a/test/golden/headers.yaml.out +++ b/test/golden/headers.yaml.out @@ -125,6 +125,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -295,13 +296,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -321,11 +322,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -399,8 +400,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/lists.yaml.out b/test/golden/lists.yaml.out index 5363c1c..8bfbdcf 100644 --- a/test/golden/lists.yaml.out +++ b/test/golden/lists.yaml.out @@ -158,6 +158,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -328,13 +329,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -354,11 +355,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -432,8 +433,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/numbers.yaml.out b/test/golden/numbers.yaml.out index 7ff0d13..5ec6132 100644 --- a/test/golden/numbers.yaml.out +++ b/test/golden/numbers.yaml.out @@ -94,6 +94,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -264,13 +265,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -290,11 +291,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -368,8 +369,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/object-without-type.yaml.out b/test/golden/object-without-type.yaml.out index a61a7bf..cd0e5e4 100644 --- a/test/golden/object-without-type.yaml.out +++ b/test/golden/object-without-type.yaml.out @@ -94,6 +94,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -264,13 +265,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -290,11 +291,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -368,8 +369,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/oneof.yaml.out b/test/golden/oneof.yaml.out index 6f5ecd9..272aa01 100644 --- a/test/golden/oneof.yaml.out +++ b/test/golden/oneof.yaml.out @@ -124,6 +124,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -294,13 +295,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -320,11 +321,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -398,8 +399,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/petstore.yaml.out b/test/golden/petstore.yaml.out index 80facee..e646019 100644 --- a/test/golden/petstore.yaml.out +++ b/test/golden/petstore.yaml.out @@ -125,6 +125,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -295,13 +296,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -321,11 +322,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -399,8 +400,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/test/golden/test1.yaml.out b/test/golden/test1.yaml.out index 5f3e8e1..d24cba0 100644 --- a/test/golden/test1.yaml.out +++ b/test/golden/test1.yaml.out @@ -128,6 +128,7 @@ import qualified Data.Aeson import qualified Data.Aeson.Types import Data.Attoparsec.ByteString (eitherResult, parseWith) import Data.ByteString (ByteString) +import qualified Data.ByteString.Builder as Builder import qualified Data.ByteString as ByteString import qualified Data.ByteString.Lazy as LBS import Data.Coerce (coerce) @@ -298,13 +299,13 @@ requiredQueryParameter :: requiredQueryParameter name withParam = \request respond -> case List.lookup name (Wai.queryString request) of Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just Nothing -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam x request respond {-# INLINEABLE requiredQueryParameter #-} @@ -324,11 +325,11 @@ optionalQueryParameter name allowEmpty withParam = \request respond -> | allowEmpty -> withParam Nothing request respond | otherwise -> - respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Missing query parameter: " <> Builder.byteString name)) Just (Just value) -> case parseQueryParam (Text.decodeUtf8 value) of Left _err -> - respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> name)) + respond (Wai.responseBuilder (toEnum 400) [] ("Unable to recognize query parameter: " <> Builder.byteString name)) Right x -> withParam (Just x) request respond {-# INLINEABLE optionalQueryParameter #-} @@ -402,8 +403,8 @@ parseRequestBody parsers withBody = \request respond -> do parseRequestBodyJSON :: (Data.Aeson.FromJSON a) => (a -> Wai.Application) -> Wai.Application parseRequestBodyJSON withBody = \request respond -> do body <- Wai.lazyRequestBody request - case Data.Aeson.decode' body of - Nothing -> + case Data.Aeson.decode' body of + Nothing -> respond (Wai.responseBuilder (toEnum 400) [] mempty) Just body -> withBody body request respond diff --git a/tie.cabal b/tie.cabal index 6347fc5..821f568 100644 --- a/tie.cabal +++ b/tie.cabal @@ -1,8 +1,8 @@ cabal-version: 3.0 name: tie -version: 0.1.0.0 +version: 0.2.0.0 synopsis: - Tie allows generation of Haskell server stubs from + Tie allows generation of Haskell server stubs from OpenAPI (v 3.x) specifications. bug-reports: https://github.com/scarf-sh/tie/issues