This repository was archived by the owner on Aug 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 631
Node API Documentation Server #3925
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
df32ae0
Qualify imports
parsonsmatt a77c374
Start getting those docs together
parsonsmatt 26df663
check
parsonsmatt 0b1a788
Overlapping :(
parsonsmatt 40d27c1
liberate the instance
parsonsmatt e292ea5
pkgs
parsonsmatt 6c59ba6
Take doc address from CLI
parsonsmatt 37d130d
serveDocImpl
parsonsmatt e2c25fa
Merge develop
parsonsmatt f3f85de
Use the right commit
parsonsmatt 6952a94
stylish
parsonsmatt 7de5853
Merge branch 'develop' into matt/node-api-docs
parsonsmatt 31e1e91
stylin
parsonsmatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
{-# LANGUAGE QuasiQuotes #-} | ||
|
||
module Pos.Util.Swagger where | ||
|
||
import Universum | ||
|
||
import Data.Swagger | ||
import NeatInterpolation (text) | ||
import Servant.Server (Handler, Server) | ||
import Servant.Swagger.UI.Core (SwaggerSchemaUI', | ||
swaggerSchemaUIServerImpl) | ||
import Servant.Swagger.UI.ReDoc (redocFiles) | ||
|
||
-- | Provide an alternative UI (ReDoc) for rendering Swagger documentation. | ||
swaggerSchemaUIServer | ||
:: (Server api ~ Handler Swagger) | ||
=> Swagger -> Server (SwaggerSchemaUI' dir api) | ||
swaggerSchemaUIServer = | ||
swaggerSchemaUIServerImpl redocIndexTemplate redocFiles | ||
where | ||
redocIndexTemplate :: Text | ||
redocIndexTemplate = [text| | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<title>ReDoc</title> | ||
<meta charset="utf-8"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<style> | ||
body { margin: 0; padding: 0; } | ||
</style> | ||
<script> | ||
// Force Strict-URL Routing for assets relative paths | ||
(function onload() { | ||
if (!window.location.href.endsWith("/")) { | ||
window.location.href += "/"; | ||
} | ||
}()); | ||
</script> | ||
</head> | ||
<body> | ||
<redoc spec-url="../SERVANT_SWAGGER_UI_SCHEMA"></redoc> | ||
<script src="redoc.min.js"> </script> | ||
</body> | ||
</html>|] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOTE: upstream PR has been accepted some weeks ago and the default template has been fixed. So, using |
||
|
This file contains hidden or 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 hidden or 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 hidden or 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,77 @@ | ||
-- necessary for `ToParamSchema Core.EpochIndex` | ||
{-# OPTIONS_GHC -fno-warn-orphans #-} | ||
|
||
module Cardano.Node.API.Swagger where | ||
|
||
import Universum | ||
|
||
import Control.Lens ((?~), at) | ||
import Data.Swagger | ||
import Servant | ||
import Servant.Swagger | ||
import Servant.Swagger.UI (SwaggerSchemaUI) | ||
|
||
import Pos.Chain.Txp (TxIn, TxOutAux, TxOut) | ||
import Pos.Chain.Update (SoftwareVersion) | ||
import Pos.Util.Swagger (swaggerSchemaUIServer) | ||
import Pos.Web (serveDocImpl, CConfirmedProposalState) | ||
import Pos.Web.Types (TlsParams) | ||
|
||
forkDocServer | ||
:: HasSwagger a | ||
=> Proxy a | ||
-> SoftwareVersion | ||
-> String | ||
-> Word16 | ||
-> Maybe TlsParams | ||
-> IO () | ||
forkDocServer prxy swVersion ip port' tlsParams = | ||
serveDocImpl | ||
(pure app) | ||
ip | ||
port' | ||
tlsParams | ||
Nothing | ||
Nothing | ||
where | ||
app = | ||
serve | ||
(Proxy @("docs" :> "v1" :> SwaggerSchemaUI "index" "swagger.json")) | ||
(swaggerSchemaUIServer (documentationApi swVersion prxy)) | ||
|
||
documentationApi | ||
:: HasSwagger a | ||
=> SoftwareVersion | ||
-> Proxy a | ||
-> Swagger | ||
documentationApi curSoftwareVersion prxy = toSwagger prxy | ||
& info.title .~ "Cardano Node API" | ||
& info.version .~ fromString (show curSoftwareVersion) | ||
& host ?~ "127.0.0.1:8083" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π€ Any ways to take that from the doc -- though quite anecdotal |
||
& info.license ?~ ("MIT" & url ?~ URL "https://raw.githubusercontent.com/input-output-hk/cardano-sl/develop/lib/LICENSE") | ||
|
||
instance ToParamSchema TxIn where | ||
toParamSchema _ = mempty | ||
& type_ .~ SwaggerString | ||
|
||
instance ToSchema TxIn where | ||
declareNamedSchema = pure . paramSchemaToNamedSchema defaultSchemaOptions | ||
|
||
instance ToSchema TxOut where | ||
declareNamedSchema _ = | ||
pure $ NamedSchema (Just "TxOut") $ mempty | ||
& type_ .~ SwaggerObject | ||
& required .~ ["coin", "address"] | ||
& properties .~ (mempty | ||
& at "coin" ?~ (Inline $ mempty | ||
& type_ .~ SwaggerNumber | ||
) | ||
& at "address" ?~ (Inline $ mempty | ||
& type_ .~ SwaggerString | ||
) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder, don't we have schema for |
||
|
||
instance ToSchema TxOutAux | ||
|
||
instance ToSchema CConfirmedProposalState | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be defaulting to
8080
(api) and8180
(doc) as this is the current default in our wallet backend:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then there will be a clash for the case when the node and wallet are running on the same host
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's okay, we won't expose the monitoring API from the node anymore!