Skip to content

Commit

Permalink
Extract the top open-api specs code from Monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed May 9, 2024
1 parent 430ffdc commit b981154
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import Control.Lens
, (.~)
, (?~)
)
import Data.HashMap.Strict.InsOrd
( InsOrdHashMap
)
import Data.OpenApi
( Definitions
, HasContent (..)
Expand Down Expand Up @@ -126,7 +129,7 @@ assetNameSchema =
, ("policy", Inline $ mempty & type_ ?~ OpenApiString)
]

faucetPaths :: [(FilePath, PathItem)]
faucetPaths :: InsOrdHashMap FilePath PathItem
faucetPaths = [sendFaucetAssetsPath]

sendFaucetAssetsPath :: (FilePath, PathItem)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.Wallet.Launch.Cluster.Http.OpenApi
( generateOpenapi3
, apiSchema
, definitions
) where

import Prelude

import Control.Lens
( (&)
, (.~)
, (?~)
)
import Data.Aeson.Encode.Pretty
( encodePretty
)
import Data.OpenApi
( Definitions
, HasComponents (..)
, HasDescription (..)
, HasInfo (..)
, HasLicense (license)
, HasPaths (..)
, HasSchemas (..)
, HasTitle (..)
, HasUrl (..)
, HasVersion (..)
, License
, OpenApi
, Schema
, URL (..)
)

import Cardano.Wallet.Launch.Cluster.Http.Faucet.OpenApi
( faucetDefinitions
, faucetPaths
)
import Cardano.Wallet.Launch.Cluster.Monitoring.Http.OpenApi
( monitoringDefinitions
, monitoringPaths
)
import qualified Data.ByteString.Lazy.Char8 as BL

generateOpenapi3 :: BL.ByteString
generateOpenapi3 = encodePretty apiSchema

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 .~ (faucetPaths <> monitoringPaths)
& components . schemas .~ definitions

definitions :: Definitions Schema
definitions = faucetDefinitions <> monitoringDefinitions

license' :: License
license' =
"Apache 2"
& url ?~ URL "https://www.apache.org/licenses/LICENSE-2.0.html"
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.Wallet.Launch.Cluster.Monitoring.Http.OpenApi
( generateOpenapi3
, apiSchema
, definitions
( monitoringPaths
, monitoringDefinitions
, monitorStateSchema
, observationSchema
) where
Expand All @@ -18,43 +17,29 @@ import Control.Lens
, (?~)
)
import Data.Aeson
import Data.Aeson.Encode.Pretty
( encodePretty
)
import Data.HashMap.Strict.InsOrd
( InsOrdHashMap
)
import Data.OpenApi
( Definitions
, HasComponents (..)
, HasContent (..)
, HasDescription (..)
, HasEnum (..)
, HasGet (..)
, HasInfo (..)
, HasItems (..)
, HasLicense (license)
, HasOneOf (..)
, HasPaths (..)
, HasPost (..)
, HasProperties (..)
, HasSchema (..)
, HasSchemas (..)
, HasSummary (..)
, HasTitle (..)
, HasType (..)
, HasUrl (..)
, HasVersion (..)
, License
, OpenApi
, OpenApiItems (..)
, OpenApiType (..)
, Operation
, PathItem
, Reference (..)
, Referenced (..)
, Schema
, URL (..)
, _Inline
)
import Data.Text
Expand All @@ -64,26 +49,8 @@ import Network.HTTP.Media
( MediaType
)

import qualified Data.ByteString.Lazy.Char8 as BL

generateOpenapi3 :: BL.ByteString
generateOpenapi3 = encodePretty apiSchema

-- 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

definitions :: Definitions Schema
definitions =
monitoringDefinitions :: Definitions Schema
monitoringDefinitions =
[ ("Ready", mempty & type_ ?~ OpenApiBoolean)
, ("MonitorState", monitorStateSchema)
, ("Observation", observationSchema)
Expand Down Expand Up @@ -162,13 +129,8 @@ relayNodeSchema =
& type_ ?~ OpenApiString
& description ?~ "The socket file or pipe of a relay node"

license' :: License
license' =
"Apache 2"
& url ?~ URL "https://www.apache.org/licenses/LICENSE-2.0.html"

paths' :: InsOrdHashMap FilePath PathItem
paths' =
monitoringPaths :: InsOrdHashMap FilePath PathItem
monitoringPaths =
[ readyPath
, controlStepPath
, controlSwitchPath
Expand Down
3 changes: 2 additions & 1 deletion lib/local-cluster/local-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ library
Cardano.Wallet.Launch.Cluster.GenesisFiles
Cardano.Wallet.Launch.Cluster.Http.Faucet.OpenApi
Cardano.Wallet.Launch.Cluster.Http.Faucet.SendFaucetAssets
Cardano.Wallet.Launch.Cluster.Http.OpenApi
Cardano.Wallet.Launch.Cluster.KeyRegistration
Cardano.Wallet.Launch.Cluster.Logging
Cardano.Wallet.Launch.Cluster.MonetaryPolicyScript
Expand Down Expand Up @@ -205,8 +206,8 @@ test-suite test
other-modules:
Cardano.Wallet.Launch.Cluster.Http.Faucet.APISpec
Cardano.Wallet.Launch.Cluster.Http.Faucet.SendFaucetAssetsSpec
Cardano.Wallet.Launch.Cluster.Http.OpenAPISpec
Cardano.Wallet.Launch.Cluster.Monitoring.Http.APISpec
Cardano.Wallet.Launch.Cluster.Monitoring.Http.OpenAPISpec
Cardano.Wallet.Launch.Cluster.Monitoring.MonitorSpec
Control.Monitoring.MonitorSpec
Control.Monitoring.TracingSpec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Cardano.Wallet.Launch.Cluster.Monitoring.Http.OpenAPISpec
module Cardano.Wallet.Launch.Cluster.Http.OpenAPISpec
( spec
) where

import Prelude

import Cardano.Wallet.Launch.Cluster.Monitoring.Http.OpenApi
import Cardano.Wallet.Launch.Cluster.Http.OpenApi
( generateOpenapi3
)
import Paths_local_cluster
Expand Down

0 comments on commit b981154

Please sign in to comment.