| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Servant.Docs.Simple.Render
Description
Renders the intermediate structure into common documentation formats
Example scripts
Generating plaintext/JSON documentation from api types
Writing our own rendering format
Example of rendering the intermediate structure
Intermediate structure
Endpoints [Node "/hello/world"
(Details [ Node "RequestBody" (Details [ Node "Format"
(Detail "': * () ('[] *)")
, Node "ContentType"
(Detail "()")
])
, Node "RequestType" (Detail "'POST")
, Node "Response" (Details [ Node "Format"
(Detail "': * () ('[] *)")
, Node "ContentType"
(Detail "()")
])
])]JSON
{
"/hello/world": {
"Response": {
"Format": "': * () ('[] *)",
"ContentType": "()"
},
"RequestType": "'POST",
"RequestBody": {
"Format": "': * () ('[] *)",
"ContentType": "()"
}
}
}Text
/hello/world:
RequestBody:
Format: ': * () ('[] *)
ContentType: ()
RequestType: 'POST
Response:
Format: ': * () ('[] *)
ContentType: ()Synopsis
Documentation
Intermediate documentation structure, a linked-list of endpoints (Nodes)
API type:
type API = "users" :> ( "update" :> Response '[()] ()
:<|> "get" :> Response '[()] ()
)Parsed into Endpoints:
Endpoints [ Node "/users/update"
(Details [ Node "Response"
(Details [ Node "Format" (Detail "': * () ('[] *)")
, Node "ContentType" (Detail "()")
])
])
, Node "/users/get"
(Details [ Node "Response"
(Details [ Node "Format" (Detail "': * () ('[] *)")
, Node "ContentType" (Detail "()")
])
])
]For a breakdown reference Node
For more examples reference Test.Servant.Docs.Simple.Samples
Key-Value pair for endpoint parameters and their values
Example 1
An endpoint is represented as a node, with the route as its parameter and its Details as its value
Node "/users/get" <Details>
Example 2
Details of each endpoint can also be represented as nodes
Given the following:
Response '[()] ()
This can be interpreted as a Response parameter, with a value of 2 Details, Format and ContentType
In turn, this:
Format: '[()]
can be interpreted as a Format parameter with a value of '[()].
And so parsing Response '[()] () comes together as:
Node "Response" --- Parameter
(Details [ Node "Format" -- Parameter ---
(Detail "': * () ('[] *)") -- Value |
, Node "ContentType" -- Parameter | Value
(Detail "()") -- Value |
]) ---class Renderable a where Source #
Convert Endpoints into different documentation formats
Instances
Conversion to JSON using Data.Aeson
Conversion to prettyprint
Instances
| Renderable (Pretty ann) Source # | |