Skip to content

Commit

Permalink
Updated dependencies to NixOS-24.05
Browse files Browse the repository at this point in the history
  • Loading branch information
CSVdB authored and Tom Sydney Kerckhove committed Aug 11, 2024
1 parent 2bec5cc commit 3ab8048
Show file tree
Hide file tree
Showing 22 changed files with 111 additions and 146 deletions.
20 changes: 10 additions & 10 deletions example/generatedCode/src/OpenAPI/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ import qualified Data.HashMap.Strict as HMap

-- | Abstracts the usage of 'Network.HTTP.Simple.httpBS' away,
-- so that it can be used for testing
class Monad m => MonadHTTP m where
class (Monad m) => MonadHTTP m where
httpBS :: HS.Request -> m (HS.Response BS.ByteString)

-- | This instance is the default instance used for production code
instance MonadHTTP IO where
httpBS = HS.httpBS

instance MonadHTTP m => MonadHTTP (MR.ReaderT r m) where
instance (MonadHTTP m) => MonadHTTP (MR.ReaderT r m) where
httpBS = MT.lift . httpBS

instance MonadHTTP m => MonadHTTP (ClientT m) where
instance (MonadHTTP m) => MonadHTTP (ClientT m) where
httpBS = MT.lift . httpBS

-- | The monad in which the operations can be run.
Expand All @@ -87,7 +87,7 @@ newtype ClientT m a = ClientT (MR.ReaderT Configuration m a)
instance MT.MonadTrans ClientT where
lift = ClientT . MT.lift

instance MIO.MonadIO m => MIO.MonadIO (ClientT m) where
instance (MIO.MonadIO m) => MIO.MonadIO (ClientT m) where
liftIO = ClientT . MIO.liftIO

-- | Utility type which uses 'IO' as underlying monad
Expand Down Expand Up @@ -156,7 +156,7 @@ anonymousSecurityScheme = id
--
-- It makes a concrete Call to a Server without a body
doCallWithConfiguration ::
MonadHTTP m =>
(MonadHTTP m) =>
-- | Configuration options like base URL and security scheme
Configuration ->
-- | HTTP method (GET, POST, etc.)
Expand All @@ -173,7 +173,7 @@ doCallWithConfiguration config method path queryParams =
-- | Same as 'doCallWithConfiguration' but run in a 'MR.ReaderT' environment which contains the configuration.
-- This is useful if multiple calls have to be executed with the same configuration.
doCallWithConfigurationM ::
MonadHTTP m =>
(MonadHTTP m) =>
Text ->
Text ->
[QueryParameter] ->
Expand Down Expand Up @@ -291,7 +291,7 @@ serializeQueryParam QueryParameter {..} =
)
$ jsonToFormDataFlat Nothing value

encodeStrict :: Aeson.ToJSON a => a -> BS.ByteString
encodeStrict :: (Aeson.ToJSON a) => a -> BS.ByteString
encodeStrict = LBS.toStrict . Aeson.encode

jsonToFormDataFlat :: Maybe Text -> Aeson.Value -> [(Maybe Text, BS.ByteString)]
Expand Down Expand Up @@ -343,7 +343,7 @@ jsonToFormDataPrefixed prefix (Aeson.Array vector) =
-- | This function makes the code generation for URL parameters easier as it allows to stringify a value
--
-- The 'Show' class is not sufficient as strings should not be stringified with quotes.
stringifyModel :: Aeson.ToJSON a => a -> Text
stringifyModel :: (Aeson.ToJSON a) => a -> Text
stringifyModel x = case Aeson.toJSON x of
Aeson.String s -> s
v -> toStrict $ toLazyText $ encodeToTextBuilder v
Expand Down Expand Up @@ -378,14 +378,14 @@ instance Aeson.FromJSON JsonDateTime where
data Nullable a = NonNull a | Null
deriving (Show, Eq)

instance Aeson.ToJSON a => Aeson.ToJSON (Nullable a) where
instance (Aeson.ToJSON a) => Aeson.ToJSON (Nullable a) where
toJSON Null = Aeson.Null
toJSON (NonNull x) = Aeson.toJSON x

toEncoding Null = Encoding.null_
toEncoding (NonNull x) = Aeson.toEncoding x

instance Aeson.FromJSON a => Aeson.FromJSON (Nullable a) where
instance (Aeson.FromJSON a) => Aeson.FromJSON (Nullable a) where
parseJSON Aeson.Null = pure Null
parseJSON x = NonNull <$> Aeson.parseJSON x

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import OpenAPI.Types
findPetsByStatus :: forall m . OpenAPI.Common.MonadHTTP m => [FindPetsByStatusParametersStatus] -- ^ status: Status values that need to be considered for filter
-> OpenAPI.Common.ClientT m (Network.HTTP.Client.Types.Response FindPetsByStatusResponse) -- ^ Monadic computation which returns the result of the operation
findPetsByStatus status = GHC.Base.fmap (\response_0 -> GHC.Base.fmap (Data.Either.either FindPetsByStatusResponseError GHC.Base.id GHC.Base.. (\response body -> if | (\status_1 -> Network.HTTP.Types.Status.statusCode status_1 GHC.Classes.== 200) (Network.HTTP.Client.Types.responseStatus response) -> FindPetsByStatusResponse200 Data.Functor.<$> (Data.Aeson.eitherDecodeStrict body :: Data.Either.Either GHC.Base.String
([Pet]))
[Pet])
| (\status_2 -> Network.HTTP.Types.Status.statusCode status_2 GHC.Classes.== 400) (Network.HTTP.Client.Types.responseStatus response) -> Data.Either.Right FindPetsByStatusResponse400
| GHC.Base.otherwise -> Data.Either.Left "Missing default response type") response_0) response_0) (OpenAPI.Common.doCallWithConfigurationM (Data.Text.toUpper GHC.Base.$ Data.Text.Internal.pack "GET") "/pet/findByStatus" [OpenAPI.Common.QueryParameter (Data.Text.Internal.pack "status") (GHC.Maybe.Just GHC.Base.$ Data.Aeson.Types.ToJSON.toJSON status) (Data.Text.Internal.pack "form") GHC.Types.True])
-- | Defines the enum schema located at @paths.\/pet\/findByStatus.GET.parameters.[0].schema.items@ in the specification.
Expand Down Expand Up @@ -80,7 +80,7 @@ instance Data.Aeson.Types.FromJSON.FromJSON FindPetsByStatusParametersStatus
-- The response constructor is chosen by the status code of the response. If no case matches (no specific case for the response code, no range case, no default case), 'FindPetsByStatusResponseError' is used.
data FindPetsByStatusResponse =
FindPetsByStatusResponseError GHC.Base.String -- ^ Means either no matching case available or a parse error
| FindPetsByStatusResponse200 ([Pet]) -- ^ successful operation
| FindPetsByStatusResponse200 [Pet] -- ^ successful operation
| FindPetsByStatusResponse400 -- ^ Invalid status value
deriving (GHC.Show.Show, GHC.Classes.Eq)
-- | > GET /pet/findByStatus
Expand All @@ -91,7 +91,7 @@ findPetsByStatusWithConfiguration :: forall m . OpenAPI.Common.MonadHTTP m => Op
-> m (Network.HTTP.Client.Types.Response FindPetsByStatusResponse) -- ^ Monadic computation which returns the result of the operation
findPetsByStatusWithConfiguration config
status = GHC.Base.fmap (\response_3 -> GHC.Base.fmap (Data.Either.either FindPetsByStatusResponseError GHC.Base.id GHC.Base.. (\response body -> if | (\status_4 -> Network.HTTP.Types.Status.statusCode status_4 GHC.Classes.== 200) (Network.HTTP.Client.Types.responseStatus response) -> FindPetsByStatusResponse200 Data.Functor.<$> (Data.Aeson.eitherDecodeStrict body :: Data.Either.Either GHC.Base.String
([Pet]))
[Pet])
| (\status_5 -> Network.HTTP.Types.Status.statusCode status_5 GHC.Classes.== 400) (Network.HTTP.Client.Types.responseStatus response) -> Data.Either.Right FindPetsByStatusResponse400
| GHC.Base.otherwise -> Data.Either.Left "Missing default response type") response_3) response_3) (OpenAPI.Common.doCallWithConfiguration config (Data.Text.toUpper GHC.Base.$ Data.Text.Internal.pack "GET") "/pet/findByStatus" [OpenAPI.Common.QueryParameter (Data.Text.Internal.pack "status") (GHC.Maybe.Just GHC.Base.$ Data.Aeson.Types.ToJSON.toJSON status) (Data.Text.Internal.pack "form") GHC.Types.True])
-- | > GET /pet/findByStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ import OpenAPI.Types
findPetsByTags :: forall m . OpenAPI.Common.MonadHTTP m => [Data.Text.Internal.Text] -- ^ tags: Tags to filter by
-> OpenAPI.Common.ClientT m (Network.HTTP.Client.Types.Response FindPetsByTagsResponse) -- ^ Monadic computation which returns the result of the operation
findPetsByTags tags = GHC.Base.fmap (\response_0 -> GHC.Base.fmap (Data.Either.either FindPetsByTagsResponseError GHC.Base.id GHC.Base.. (\response body -> if | (\status_1 -> Network.HTTP.Types.Status.statusCode status_1 GHC.Classes.== 200) (Network.HTTP.Client.Types.responseStatus response) -> FindPetsByTagsResponse200 Data.Functor.<$> (Data.Aeson.eitherDecodeStrict body :: Data.Either.Either GHC.Base.String
([Pet]))
[Pet])
| (\status_2 -> Network.HTTP.Types.Status.statusCode status_2 GHC.Classes.== 400) (Network.HTTP.Client.Types.responseStatus response) -> Data.Either.Right FindPetsByTagsResponse400
| GHC.Base.otherwise -> Data.Either.Left "Missing default response type") response_0) response_0) (OpenAPI.Common.doCallWithConfigurationM (Data.Text.toUpper GHC.Base.$ Data.Text.Internal.pack "GET") "/pet/findByTags" [OpenAPI.Common.QueryParameter (Data.Text.Internal.pack "tags") (GHC.Maybe.Just GHC.Base.$ Data.Aeson.Types.ToJSON.toJSON tags) (Data.Text.Internal.pack "form") GHC.Types.True])
-- | Represents a response of the operation 'findPetsByTags'.
--
-- The response constructor is chosen by the status code of the response. If no case matches (no specific case for the response code, no range case, no default case), 'FindPetsByTagsResponseError' is used.
data FindPetsByTagsResponse =
FindPetsByTagsResponseError GHC.Base.String -- ^ Means either no matching case available or a parse error
| FindPetsByTagsResponse200 ([Pet]) -- ^ successful operation
| FindPetsByTagsResponse200 [Pet] -- ^ successful operation
| FindPetsByTagsResponse400 -- ^ Invalid tag value
deriving (GHC.Show.Show, GHC.Classes.Eq)
-- | > GET /pet/findByTags
Expand All @@ -70,7 +70,7 @@ findPetsByTagsWithConfiguration :: forall m . OpenAPI.Common.MonadHTTP m => Open
-> m (Network.HTTP.Client.Types.Response FindPetsByTagsResponse) -- ^ Monadic computation which returns the result of the operation
findPetsByTagsWithConfiguration config
tags = GHC.Base.fmap (\response_3 -> GHC.Base.fmap (Data.Either.either FindPetsByTagsResponseError GHC.Base.id GHC.Base.. (\response body -> if | (\status_4 -> Network.HTTP.Types.Status.statusCode status_4 GHC.Classes.== 200) (Network.HTTP.Client.Types.responseStatus response) -> FindPetsByTagsResponse200 Data.Functor.<$> (Data.Aeson.eitherDecodeStrict body :: Data.Either.Either GHC.Base.String
([Pet]))
[Pet])
| (\status_5 -> Network.HTTP.Types.Status.statusCode status_5 GHC.Classes.== 400) (Network.HTTP.Client.Types.responseStatus response) -> Data.Either.Right FindPetsByTagsResponse400
| GHC.Base.otherwise -> Data.Either.Left "Missing default response type") response_3) response_3) (OpenAPI.Common.doCallWithConfiguration config (Data.Text.toUpper GHC.Base.$ Data.Text.Internal.pack "GET") "/pet/findByTags" [OpenAPI.Common.QueryParameter (Data.Text.Internal.pack "tags") (GHC.Maybe.Just GHC.Base.$ Data.Aeson.Types.ToJSON.toJSON tags) (Data.Text.Internal.pack "form") GHC.Types.True])
-- | > GET /pet/findByTags
Expand Down
4 changes: 2 additions & 2 deletions example/generatedCode/src/OpenAPI/Types/Pet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ data Pet = Pet {
-- | name
, petName :: Data.Text.Internal.Text
-- | photoUrls
, petPhotoUrls :: ([Data.Text.Internal.Text])
, petPhotoUrls :: [Data.Text.Internal.Text]
-- | status: pet status in the store
, petStatus :: (GHC.Maybe.Maybe PetStatus)
-- | tags
, petTags :: (GHC.Maybe.Maybe ([Tag]))
, petTags :: (GHC.Maybe.Maybe [Tag])
} deriving (GHC.Show.Show
, GHC.Classes.Eq)
instance Data.Aeson.Types.ToJSON.ToJSON Pet
Expand Down
6 changes: 3 additions & 3 deletions example/src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Network.HTTP.Client
import OpenAPI
import OpenAPI.Common

runAddPet :: MonadHTTP m => m (Response AddPetResponse)
runAddPet :: (MonadHTTP m) => m (Response AddPetResponse)
runAddPet = runWithConfiguration defaultConfiguration (addPet myPet)
where
myPet =
Expand All @@ -20,10 +20,10 @@ runAddPet = runWithConfiguration defaultConfiguration (addPet myPet)
petTags = Nothing
}

runGetInventory :: MonadHTTP m => m (Response GetInventoryResponse)
runGetInventory :: (MonadHTTP m) => m (Response GetInventoryResponse)
runGetInventory = runWithConfiguration defaultConfiguration getInventory

runFindPetsByStatus :: MonadHTTP m => m (Response FindPetsByStatusResponse)
runFindPetsByStatus :: (MonadHTTP m) => m (Response FindPetsByStatusResponse)
runFindPetsByStatus =
runWithConfiguration
defaultConfiguration
Expand Down
Loading

0 comments on commit 3ab8048

Please sign in to comment.