Skip to content

Commit

Permalink
Add SendFaucetAsset type and json instances
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed May 7, 2024
1 parent e323174 commit 97e8096
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Cardano.Wallet.Launch.Cluster.Monitoring.Http.OpenApi
, definitions
, monitorStateSchema
, observationSchema
, sendAssetsSchema
) where

import Prelude
Expand All @@ -31,10 +32,13 @@ import Data.OpenApi
, HasDescription (..)
, HasEnum (..)
, HasGet (..)
, HasIn (..)
, HasInfo (..)
, HasItems (..)
, HasLicense (license)
, HasName (..)
, HasOneOf (..)
, HasParameters (..)
, HasPaths (..)
, HasPost (..)
, HasProperties (..)
Expand All @@ -50,6 +54,7 @@ import Data.OpenApi
, OpenApiItems (..)
, OpenApiType (..)
, Operation
, ParamLocation (..)
, PathItem
, Reference (..)
, Referenced (..)
Expand All @@ -68,24 +73,106 @@ import qualified Data.ByteString.Lazy.Char8 as BL

generateOpenapi3 :: BL.ByteString
generateOpenapi3 = encodePretty apiSchema
-- jsonMediaType :: MediaType
-- jsonMediaType = "application/json"

-- jsonMediaType :: MediaType
-- jsonMediaType = "application/json"

apiSchema :: OpenApi
apiSchema :: OpenApi =
mempty
& info . title .~ "Cardano Wallet Monitoring API"
& info . version .~ "0.1.0.0"
& info . description ?~ "This is the API for the monitoring server"
& info . license ?~ license'
& paths .~ paths'
& components . schemas .~ definitions
mempty
& info . title .~ "Cardano Wallet Monitoring API"
& info . version .~ "0.1.0.0"
& info . description ?~ "This is the API for the monitoring server"
& info . license ?~ license'
& paths .~ paths'
& components . schemas .~ definitions

definitions :: Definitions Schema
definitions = [ ("Ready", mempty & type_ ?~ OpenApiBoolean)
, ("MonitorState", monitorStateSchema)
, ("Observation", observationSchema)
]
definitions =
[ ("Ready", mempty & type_ ?~ OpenApiBoolean)
, ("MonitorState", monitorStateSchema)
, ("Observation", observationSchema)
, ("SendAssets", sendAssetsSchema)
]

sendAssetsSchema :: Schema
sendAssetsSchema =
mempty
& type_ ?~ OpenApiObject
& properties
.~ [ ("batch-size", Inline $ mempty & type_ ?~ OpenApiInteger)
, ("assets", Inline assetsSchema)
]

assetsSchema :: Schema
assetsSchema =
mempty
& type_ ?~ OpenApiArray
& items
?~ OpenApiItemsObject
(Inline assetSchema)

assetSchema :: Schema
assetSchema =
mempty
& type_ ?~ OpenApiObject
& properties
.~ [ ("address", Inline $ mempty & type_ ?~ OpenApiString)
, ("bundle", Inline bundleSchema)
, ("metadata", Inline metadataSchema)
]

metadataSchema :: Schema
metadataSchema =
mempty
& type_ ?~ OpenApiArray
& items
?~ OpenApiItemsObject
(Inline metadataValueSchema)

metadataValueSchema :: Schema
metadataValueSchema =
mempty
& type_ ?~ OpenApiObject
& properties
.~ [ ("key", Inline $ mempty & type_ ?~ OpenApiString)
, ("value", Inline $ mempty & type_ ?~ OpenApiString)
]

bundleSchema :: Schema
bundleSchema =
mempty
& type_ ?~ OpenApiObject
& properties
.~ [ ("assets", Inline assetsQuantitySchema)
, ("coin", Inline $ mempty & type_ ?~ OpenApiInteger)
]

assetsQuantitySchema :: Schema
assetsQuantitySchema =
mempty
& type_ ?~ OpenApiArray
& items
?~ OpenApiItemsObject
(Inline assetQuantitySchema)

assetQuantitySchema :: Schema
assetQuantitySchema =
mempty
& type_ ?~ OpenApiObject
& properties
.~ [ ("asset", Inline assetNameSchema)
, ("quantity", Inline $ mempty & type_ ?~ OpenApiInteger)
]

assetNameSchema :: Schema
assetNameSchema =
mempty
& type_ ?~ OpenApiObject
& properties
.~ [ ("name", Inline $ mempty & type_ ?~ OpenApiString)
, ("policy", Inline $ mempty & type_ ?~ OpenApiString)
]

monitorStateSchema :: Schema
monitorStateSchema =
Expand All @@ -108,7 +195,7 @@ historySchema =
& type_ ?~ OpenApiArray
& items
?~ OpenApiItemsObject
(Inline timedPhaseSchema)
(Inline timedPhaseSchema)

timedPhaseSchema :: Schema
timedPhaseSchema =
Expand Down Expand Up @@ -171,6 +258,7 @@ paths' =
, controlStepPath
, controlSwitchPath
, controlObservePath
, sendFaucetAssetsPath
]

controlObservePath :: (FilePath, PathItem)
Expand Down Expand Up @@ -239,3 +327,28 @@ readyPath = ("/ready", pathItem)
"Ok"
& _Inline . content . at jsonMediaType
?~ (mempty & schema ?~ Ref (Reference "Ready"))

sendFaucetAssetsPath :: (FilePath, PathItem)
sendFaucetAssetsPath = ("/send/assets", pathItem)
where
pathItem :: PathItem
pathItem =
mempty
& post ?~ operation
& parameters
.~ [ Inline
$ mempty
& in_ .~ ParamPath
& name .~ "assets"
& schema ?~ Ref (Reference "SendAssets")
]
operation :: Operation
operation =
mempty
& summary ?~ summary'
& at 204 ?~ at204
summary' = "Send assets to the faucet"
at204 =
"No Content"
& _Inline . content . at jsonMediaType
?~ mempty

0 comments on commit 97e8096

Please sign in to comment.