Skip to content

Commit

Permalink
better organize swagger documentations by grouping tags (byron vs she…
Browse files Browse the repository at this point in the history
…lley)

Also renamed '/byron/wallets' to '/byron-wallets' to better reflect what the resource should be
  • Loading branch information
KtorZ committed Oct 16, 2019
1 parent 082131d commit d9bcf54
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 77 deletions.
18 changes: 9 additions & 9 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -989,9 +989,9 @@ tearDown ctx = do
d <- request @Value ctx ("DELETE", endpoint) None Empty
expectResponseCode HTTP.status204 d
respByron <-
request @[ApiByronWallet] ctx ("GET", "v2/byron/wallets") Default Empty
request @[ApiByronWallet] ctx ("GET", "v2/byron-wallets") Default Empty
forM_ (wallets (snd respByron)) $ \wal -> do
let endpoint = "v2/byron/wallets" </> wal ^. walletId
let endpoint = "v2/byron-wallets" </> wal ^. walletId
d <- request @Value ctx ("DELETE", endpoint) None Empty
expectResponseCode HTTP.status204 d
where
Expand Down Expand Up @@ -1055,37 +1055,37 @@ networkInfoEp =
postByronWalletEp :: (Method, Text)
postByronWalletEp =
( "POST"
, "v2/byron/wallets"
, "v2/byron-wallets"
)

listByronWalletEp :: (Method, Text)
listByronWalletEp =
( "GET"
, "v2/byron/wallets"
, "v2/byron-wallets"
)

migrateByronWalletEp :: ApiByronWallet -> ApiWallet -> (Method, Text)
migrateByronWalletEp wSrc wDest =
( "POST"
, "v2/byron/wallets/" <> wSrc ^. walletId <> "/migrate/" <> wDest ^. walletId
, "v2/byron-wallets/" <> wSrc ^. walletId <> "/migrations/" <> wDest ^. walletId
)

calculateByronMigrationCostEp :: ApiByronWallet -> (Method, Text)
calculateByronMigrationCostEp w =
( "GET"
, "v2/byron/wallets/" <> w ^. walletId <> "/migrate"
, "v2/byron-wallets/" <> w ^. walletId <> "/migrations"
)

getByronWalletEp :: ApiByronWallet -> (Method, Text)
getByronWalletEp w =
( "GET"
, "v2/byron/wallets/" <> w ^. walletId
, "v2/byron-wallets/" <> w ^. walletId
)

deleteByronWalletEp :: ApiByronWallet -> (Method, Text)
deleteByronWalletEp w =
( "DELETE"
, "v2/byron/wallets/" <> w ^. walletId
, "v2/byron-wallets/" <> w ^. walletId
)

listStakePoolsEp :: (Method, Text)
Expand All @@ -1103,7 +1103,7 @@ postWalletEp =
postExternalTxEp :: (Method, Text)
postExternalTxEp =
( "POST"
, "v2/external-transactions"
, "v2/proxy/transactions"
)

getWalletEp :: ApiWallet -> (Method, Text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,26 @@ spec :: forall t. (EncodeAddress t, DecodeAddress t) => SpecWith (Context t)
spec = do

describe "BYRON_ESTIMATE_06 - non-existing wallets" $ do
forM_ falseWalletIds $ \(desc, walId) -> it desc $ \ctx -> do
let endpoint = "v2/byron/wallets/" <> T.pack walId <> "/migrate"
forM_ (take 1 falseWalletIds) $ \(desc, walId) -> it desc $ \ctx -> do
let endpoint = "v2/byron-wallets/" <> T.pack walId <> "/migrations"
rg <- request @ApiByronWallet ctx ("GET", endpoint) Default Empty
expectResponseCode @IO HTTP.status501 rg

forM_ (drop 1 falseWalletIds) $ \(desc, walId) -> it desc $ \ctx -> do
let endpoint = "v2/byron-wallets/" <> T.pack walId <> "/migrations"
rg <- request @ApiByronWallet ctx ("GET", endpoint) Default Empty
expectResponseCode @IO HTTP.status404 rg
expectErrorMessage errMsg404NoEndpoint rg

it "BYRON_GET_02 - Byron ep does not show new wallet" $ \ctx -> do
w <- emptyWallet ctx
let ep = ( "GET", "v2/byron/wallets/" <> w ^. walletId )
let ep = ( "GET", "v2/byron-wallets/" <> w ^. walletId )
r <- request @ApiByronWallet ctx ep Default Empty
expectResponseCode @IO HTTP.status404 r

describe "BYRON_GET_06 - non-existing wallets" $ do
forM_ falseWalletIds $ \(desc, walId) -> it desc $ \ctx -> do
let endpoint = "v2/byron/wallets/" <> T.pack walId
let endpoint = "v2/byron-wallets/" <> T.pack walId
rg <- request @ApiByronWallet ctx ("GET", endpoint) Default Empty
if (desc == valid40CharHexDesc) then do
expectErrorMessage (errMsg404NoWallet $ T.pack walId) rg
Expand All @@ -107,13 +112,13 @@ spec = do

it "BYRON_DELETE_02 - Byron ep does not delete new wallet" $ \ctx -> do
w <- emptyWallet ctx
let ep = ( "DELETE", "v2/byron/wallets/" <> w ^. walletId )
let ep = ( "DELETE", "v2/byron-wallets/" <> w ^. walletId )
r <- request @ApiByronWallet ctx ep Default Empty
expectResponseCode @IO HTTP.status404 r

describe "BYRON_DELETE_04 - non-existing wallets" $ do
forM_ falseWalletIds $ \(desc, walId) -> it desc $ \ctx -> do
let endpoint = "v2/byron/wallets/" <> T.pack walId
let endpoint = "v2/byron-wallets/" <> T.pack walId
rg <- request @ApiByronWallet ctx ("DELETE", endpoint) Default Empty
if (desc == valid40CharHexDesc) then do
expectErrorMessage (errMsg404NoWallet $ T.pack walId) rg
Expand Down Expand Up @@ -496,7 +501,7 @@ spec = do
describe "BYRON_RESTORE_07 - v2/wallets - Methods Not Allowed" $ do
let matrix = ["PUT", "DELETE", "CONNECT", "TRACE", "OPTIONS"]
forM_ matrix $ \method -> it (show method) $ \ctx -> do
r <- request @ApiByronWallet ctx (method, "v2/byron/wallets") Default Empty
r <- request @ApiByronWallet ctx (method, "v2/byron-wallets") Default Empty
expectResponseCode @IO HTTP.status405 r
expectErrorMessage errMsg405 r

Expand Down
46 changes: 24 additions & 22 deletions lib/core/src/Cardano/Wallet/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ type ListTransactions t = "wallets"
:> QueryParam "order" (ApiT SortOrder)
:> Get '[JSON] [ApiTransaction t]

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/postExternalTransaction
type PostExternalTransaction = "external-transactions"
:> ReqBody '[OctetStream] PostExternalTransactionData
:> PostAccepted '[JSON] ApiTxId

{-------------------------------------------------------------------------------
StakePools
Expand All @@ -261,50 +256,57 @@ type Network =
:> "information"
:> Get '[JSON] ApiNetworkInformation

{-------------------------------------------------------------------------------
Proxy
See also: https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Proxy
-------------------------------------------------------------------------------}

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/postExternalTransaction
type PostExternalTransaction = "proxy"
:> "transactions"
:> ReqBody '[OctetStream] PostExternalTransactionData
:> PostAccepted '[JSON] ApiTxId

{-------------------------------------------------------------------------------
Compatibility API
See also: https://input-output-hk.github.io/cardano-wallet/api/#tag/Byron-Wallets
-------------------------------------------------------------------------------}

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/postByronWallet
type PostByronWallet = "byron-wallets"
:> ReqBody '[JSON] ByronWalletPostData
:> PostAccepted '[JSON] ApiByronWallet

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/deleteByronWallet
type DeleteByronWallet = "byron"
:> "wallets"
type DeleteByronWallet = "byron-wallets"
:> Capture "walletId" (ApiT WalletId)
:> DeleteNoContent '[Any] NoContent

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/getByronWallet
type GetByronWallet = "byron"
:> "wallets"
type GetByronWallet = "byron-wallets"
:> Capture "walletId" (ApiT WalletId)
:> Get '[JSON] ApiByronWallet

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/getByronWalletMigrationInfo
type GetByronWalletMigrationInfo = "byron"
:> "wallets"
type GetByronWalletMigrationInfo = "byron-wallets"
:> Capture "walletId" (ApiT WalletId)
:> "migrations"
:> Get '[JSON] ApiByronWalletMigrationInfo

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/listByronWallets
type ListByronWallets = "byron"
:> "wallets"
type ListByronWallets = "byron-wallets"
:> Get '[JSON] [ApiByronWallet]

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/migrateByronWallet
type MigrateByronWallet t = "byron"
:> "wallets"
type MigrateByronWallet t = "byron-wallets"
:> Capture "sourceWalletId" (ApiT WalletId)
:> "migrate"
:> "migrations"
:> Capture "targetWalletId" (ApiT WalletId)
:> ReqBody '[JSON] ApiMigrateByronWalletData
:> PostAccepted '[JSON] [ApiTransaction t]

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/postByronWallet
type PostByronWallet = "byron"
:> "wallets"
:> ReqBody '[JSON] ByronWalletPostData
:> PostAccepted '[JSON] ApiByronWallet

{-------------------------------------------------------------------------------
Internals
-------------------------------------------------------------------------------}
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ import Data.Generics.Internal.VL.Lens
import Data.Generics.Labels
()
import Data.List
( sortOn )
( isSubsequenceOf, sortOn )
import Data.Maybe
( fromMaybe, isJust )
import Data.Proxy
Expand Down Expand Up @@ -1327,7 +1327,7 @@ instance LiftHandler (Request, ServantErr) where
]
415 ->
let cType =
if "external-transactions" `elem` (pathInfo req)
if ["proxy", "transactions"] `isSubsequenceOf` pathInfo req
then "application/octet-stream"
else "application/json"
in apiError err' UnsupportedMediaType $ mconcat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ spec = do
]

describe "TRANS_EXTERNAL_CREATE_04 - \
\v2/external-transactions - Methods Not Allowed" $ do
\v2/proxy/transactions - Methods Not Allowed" $ do

let matrix = ["PUT", "DELETE", "CONNECT", "TRACE", "OPTIONS", "GET"]
forM_ matrix $ \method -> it (show method) $ \ctx -> do
Expand All @@ -289,7 +289,7 @@ spec = do
let payload = (NonJson . BL.fromStrict . toRawBytes Base16) txBlob
let headers = Headers [ ("Content-Type", "application/octet-stream") ]

let endpoint = "v2/external-transactions"
let endpoint = "v2/proxy/transactions"
r <- request @ApiTxId ctx (method, endpoint) headers payload
expectResponseCode @IO HTTP.status405 r
expectErrorMessage errMsg405 r
Expand Down
Loading

0 comments on commit d9bcf54

Please sign in to comment.