-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from asim/api-docs
Add generated api docs
- Loading branch information
Showing
9 changed files
with
326 additions
and
0 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,128 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type Api struct { | ||
Endpoints []*Endpoint | ||
} | ||
|
||
type Endpoint struct { | ||
Name string | ||
Path string | ||
Params []*Param | ||
Response []*Value | ||
} | ||
|
||
type Param struct { | ||
Name string | ||
Value string | ||
Description string | ||
} | ||
|
||
type Value struct { | ||
Type string | ||
Params []*Param | ||
} | ||
|
||
var Endpoints = []*Endpoint{ | ||
{ | ||
Name: "Quran", | ||
Path: "/api/quran", | ||
Params: nil, | ||
Response: []*Value{{Type: "JSON"}}, | ||
}, | ||
{ | ||
Name: "Hadith", | ||
Path: "/api/hadith", | ||
Params: nil, | ||
Response: []*Value{{Type: "JSON"}}, | ||
}, | ||
{ | ||
Name: "Names", | ||
Path: "/api/names", | ||
Params: nil, | ||
Response: []*Value{{Type: "JSON"}}, | ||
}, | ||
{ | ||
Name: "Search", | ||
Path: "/api/search", | ||
Params: []*Param{ | ||
{ | ||
Name: "q", | ||
Value: "string", | ||
Description: "The question to ask", | ||
}, | ||
}, | ||
Response: []*Value{{ | ||
Type: "JSON", | ||
Params: []*Param{ | ||
{Name: "q", Value: "string", Description: "The question asked"}, | ||
{Name: "answer", Value: "string", Description: "Answer to the question"}, | ||
{Name: "references", Value: "array", Description: "A list of references used"}, | ||
}, | ||
}}, | ||
}, | ||
} | ||
|
||
func (a *Api) Markdown() string { | ||
var data string | ||
|
||
data += "# Endpoints" | ||
data += fmt.Sprintln() | ||
data += fmt.Sprintln("A list of API endpoints") | ||
data += fmt.Sprintln() | ||
|
||
for _, endpoint := range a.Endpoints { | ||
data += fmt.Sprintln() | ||
data += "## " + endpoint.Name | ||
data += fmt.Sprintln() | ||
data += fmt.Sprintln("___") | ||
data += fmt.Sprintln("\\") | ||
data += fmt.Sprintln() | ||
data += fmt.Sprintln() | ||
data += fmt.Sprintf("Path: `%s`", endpoint.Path) | ||
data += fmt.Sprintln() | ||
|
||
if endpoint.Params != nil { | ||
data += fmt.Sprintln("#### Request") | ||
data += fmt.Sprintln() | ||
data += fmt.Sprintln("Format `JSON`") | ||
data += fmt.Sprintln() | ||
for _, param := range endpoint.Params { | ||
data += fmt.Sprintf("- `%s`: `%s` - %s", param.Name, param.Value, param.Description) | ||
data += fmt.Sprintln() | ||
} | ||
data += fmt.Sprintln() | ||
data += fmt.Sprintln("\\") | ||
data += fmt.Sprintln() | ||
} | ||
|
||
if endpoint.Response != nil { | ||
data += fmt.Sprintln("#### Response") | ||
data += fmt.Sprintln() | ||
for _, resp := range endpoint.Response { | ||
data += fmt.Sprintf("Format `%s`", resp.Type) | ||
data += fmt.Sprintln() | ||
for _, param := range resp.Params { | ||
data += fmt.Sprintf("- `%s`: `%s` - %s", param.Name, param.Value, param.Description) | ||
data += fmt.Sprintln() | ||
} | ||
} | ||
|
||
data += fmt.Sprintln() | ||
} | ||
|
||
data += fmt.Sprintln() | ||
data += fmt.Sprintln() | ||
} | ||
|
||
return data | ||
} | ||
|
||
func Load() *Api { | ||
a := new(Api) | ||
a.Endpoints = Endpoints | ||
return a | ||
} |
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,116 @@ | ||
|
||
<html> | ||
<head> | ||
<title>API | Reminder</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<style> | ||
html, body { height: 100%; width: 100%; margin: 0; padding: 0;} | ||
#head { margin-bottom: 2.5em; } | ||
#head a { margin-right: 10px; color: black; font-weight: bold; text-decoration: none; } | ||
#container { height: 100%; max-width: 1024px; margin: 0 auto; padding: 25px;} | ||
#content { padding-bottom: 100px; } | ||
#content p { padding: 0 0 25px 0; margin: 0; } | ||
@font-face { | ||
font-family: 'arabic'; | ||
src: url('/files/arabic.otf') format('opentype'); | ||
font-weight: normal; | ||
font-style: normal; | ||
} | ||
.arabic { | ||
font-family: 'arabic'; | ||
font-size: 1.5em; | ||
} | ||
.chapter { | ||
margin: 10px; | ||
border: 1px solid grey; | ||
padding: 10px; | ||
display: inline-block; | ||
} | ||
code { | ||
background: whitesmoke; | ||
padding: 5px; | ||
border-radius: 5px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<div id="head"> | ||
<a href="/">[Reminder]</a> | ||
<a href="/api">API</a> | ||
<a href="/quran">Quran</a> | ||
<a href="/names">Names</a> | ||
<a href="/hadith">Hadith</a> | ||
<a href="/search">Search</a> | ||
</div> | ||
<div id="content"><h1 id="endpoints">Endpoints</h1> | ||
|
||
<p>A list of API endpoints</p> | ||
|
||
<h2 id="quran">Quran</h2> | ||
|
||
<hr> | ||
|
||
<p></p> | ||
|
||
<p>Path: <code>/api/quran</code></p> | ||
|
||
<h4 id="response">Response</h4> | ||
|
||
<p>Format <code>JSON</code></p> | ||
|
||
<h2 id="hadith">Hadith</h2> | ||
|
||
<hr> | ||
|
||
<p></p> | ||
|
||
<p>Path: <code>/api/hadith</code></p> | ||
|
||
<h4 id="response-1">Response</h4> | ||
|
||
<p>Format <code>JSON</code></p> | ||
|
||
<h2 id="names">Names</h2> | ||
|
||
<hr> | ||
|
||
<p></p> | ||
|
||
<p>Path: <code>/api/names</code></p> | ||
|
||
<h4 id="response-2">Response</h4> | ||
|
||
<p>Format <code>JSON</code></p> | ||
|
||
<h2 id="search">Search</h2> | ||
|
||
<hr> | ||
|
||
<p></p> | ||
|
||
<p>Path: <code>/api/search</code></p> | ||
|
||
<h4 id="request">Request</h4> | ||
|
||
<p>Format <code>JSON</code></p> | ||
|
||
<ul> | ||
<li><code>q</code>: <code>string</code> - The question to ask</li> | ||
</ul> | ||
|
||
<p></p> | ||
|
||
<h4 id="response-3">Response</h4> | ||
|
||
<p>Format <code>JSON</code></p> | ||
|
||
<ul> | ||
<li><code>q</code>: <code>string</code> - The question asked</li> | ||
<li><code>answer</code>: <code>string</code> - Answer to the question</li> | ||
<li><code>references</code>: <code>array</code> - A list of references used</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
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
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
Oops, something went wrong.