-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
291 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Main where | ||
|
||
import Data.Aeson.Encode.Pretty (encodePretty) | ||
import Data.ByteString.Lazy qualified as BSL | ||
import Data.Proxy (Proxy (..)) | ||
import Servant.OpenApi (toOpenApi) | ||
import System.Environment qualified | ||
import Wst.Server.Types (APIInEra) | ||
|
||
main :: IO () | ||
main = do | ||
fp:_ <- System.Environment.getArgs | ||
BSL.writeFile fp $ encodePretty $ toOpenApi $ Proxy @APIInEra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{-| JSON utility functions | ||
-} | ||
module Wst.JSON.Utils( | ||
customJsonOptions | ||
) where | ||
|
||
import Data.Aeson qualified as JSON | ||
|
||
-- | JSON options that drop @n@ characters and then apply @JSON.camel2@ to the rest | ||
customJsonOptions :: Int -> JSON.Options | ||
customJsonOptions i = JSON.defaultOptions{JSON.fieldLabelModifier= JSON.camelTo2 '_' . drop i } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE OverloadedLists #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-| Orphan instances | ||
-} | ||
module Wst.Orphans() where | ||
|
||
import Cardano.Api qualified as C | ||
import Control.Lens ((&), (.~), (?~)) | ||
import Data.OpenApi.Internal (NamedSchema (..), | ||
OpenApiType (OpenApiInteger, OpenApiObject, OpenApiString), | ||
Referenced (Inline), Schema) | ||
import Data.OpenApi.Lens qualified as L | ||
import Data.OpenApi.Schema (ToSchema (..)) | ||
import Data.Typeable (Typeable) | ||
|
||
instance (Typeable ctx, Typeable era) => ToSchema (C.TxOut ctx era) where | ||
declareNamedSchema _ = pure | ||
$ NamedSchema (Just "TxOut") | ||
$ mempty | ||
& L.type_ ?~ OpenApiObject | ||
& L.description ?~ "Global parameters of the programmable token directory" | ||
& L.properties .~ | ||
[ ( "address" | ||
, Inline addrSchema | ||
) | ||
, ( "datum" | ||
, Inline $ mempty | ||
& L.type_ ?~ OpenApiObject | ||
& L.description ?~ "the datum of the output (if any)" | ||
) | ||
, ( "inlineDatum" | ||
, Inline $ mempty | ||
& L.type_ ?~ OpenApiObject | ||
& L.description ?~ "the inline datum of the output (if any)" | ||
) | ||
, ( "inlineDatumRaw" | ||
, Inline $ mempty | ||
& L.type_ ?~ OpenApiObject | ||
& L.description ?~ "the inline datum of the output (if any), CBOR serialised and base-16 encoded" | ||
) | ||
, ( "inlineDatumhash" | ||
, Inline $ mempty | ||
& L.type_ ?~ OpenApiString | ||
& L.description ?~ "hash of the inline datum of the output (if it exists)" | ||
) | ||
, ( "referenceScript" | ||
, Inline $ mempty | ||
& L.type_ ?~ OpenApiObject | ||
& L.description ?~ "reference script (if any), text envelope format" | ||
) | ||
, ( "value" | ||
, Inline valueSchema | ||
) | ||
] | ||
|
||
instance ToSchema C.TxIn where | ||
declareNamedSchema _ = pure | ||
$ NamedSchema (Just "TxIn") | ||
$ mempty | ||
& L.type_ ?~ OpenApiString | ||
& L.description ?~ "TxIn consisting of (Transaction hash + # + index)" | ||
& L.example ?~ "01f4b788593d4f70de2a45c2e1e87088bfbdfa29577ae1b62aba60e095e3ab53#2" | ||
|
||
instance ToSchema (C.Hash C.PaymentKey) where | ||
declareNamedSchema _ = pure | ||
$ NamedSchema (Just "Hash PaymentKey") | ||
$ mempty | ||
& L.type_ ?~ OpenApiString | ||
& L.description ?~ "Hash of a payment key" | ||
& L.example ?~ "f6ac5676b58d8ce280c1f09af4a2e82dd58c1aa2fb075aa005afa1da" | ||
|
||
valueSchema :: Schema | ||
valueSchema = mempty | ||
& L.type_ ?~ OpenApiObject | ||
& L.description ?~ "Value locked in the output. Always includes a 'lovelace' key, may include other keys if non-Ada assets are present." | ||
& L.properties .~ | ||
[ ("lovelace", Inline $ mempty & L.type_ ?~ OpenApiInteger) | ||
] | ||
|
||
instance ToSchema C.Value where | ||
declareNamedSchema _ = pure | ||
$ NamedSchema (Just "Value") valueSchema | ||
|
||
addrSchema :: Schema | ||
addrSchema = mempty | ||
& L.type_ ?~ OpenApiString | ||
& L.description ?~ "bech32-encoded cardano address" | ||
& L.example ?~ "addr_test1qpju2uhn72ur6j5alln6nz7dqcgcjal7xjaw7lwdjdaex4qhr3xpz63fjwvlpsnu8efnhfdja78d3vkv8ks6ac09g3usemu2yl" | ||
|
||
instance ToSchema (C.Address C.ShelleyAddr) where | ||
declareNamedSchema _ = pure | ||
$ NamedSchema (Just "Address") addrSchema | ||
|
||
instance ToSchema C.AssetName where | ||
declareNamedSchema _ = pure | ||
$ NamedSchema (Just "Asset name") | ||
$ mempty | ||
& L.type_ ?~ OpenApiString | ||
|
||
instance ToSchema C.Quantity where | ||
declareNamedSchema _ = pure | ||
$ NamedSchema (Just "Quantity") | ||
$ mempty | ||
& L.type_ ?~ OpenApiInteger | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.