Switch to redoc and update API description

This commit is contained in:
Alex Ling 2020-12-20 14:31:17 +00:00
parent d3e5691478
commit 84d4b0c529
4 changed files with 30 additions and 32 deletions

View File

@ -6,6 +6,8 @@ require "koa"
class APIRouter < Router class APIRouter < Router
@@api_json : String? @@api_json : String?
API_VERSION = "0.1.0"
macro s(fields) macro s(fields)
{ {
{% for field in fields %} {% for field in fields %}
@ -15,16 +17,20 @@ class APIRouter < Router
end end
def initialize def initialize
Koa.init "Mango API", version: MANGO_VERSION, desc: <<-MD Koa.init "Mango API", version: API_VERSION, desc: <<-MD
## Terminalogies # A Word of Caution
This API was designed for internal use only, and the design doesn't comply with the resources convention of a RESTful API. Because of this, most of the API endpoints listed here will soon be updated and removed in future versions of Mango, so use them at your own risk!
# Authentication
All endpoints require authentication. After logging in, your session ID would be stored as a cookie named `mango-sessid-#{Config.current.port}`, which can be used to authenticate the API access. Note that all admin API endpoints (`/api/admin/...`) require the logged in user to have admin access.
# Terminologies
- Entry: An entry is a `cbz`/`cbr` file in your library. Depending on how you organize your manga collection, an entry can contain a chapter, a volume or even an entire manga. - Entry: An entry is a `cbz`/`cbr` file in your library. Depending on how you organize your manga collection, an entry can contain a chapter, a volume or even an entire manga.
- Title: A title contains a list of entries and optionally some sub-titles. For example, your can have a title to store a manga, and it contains a list of sub-titles representing the volumes in the manga. Each sub-title would then contain a list of entries representing the chapters in the volume. - Title: A title contains a list of entries and optionally some sub-titles. For example, you can have a title to store a manga, and it contains a list of sub-titles representing the volumes in the manga. Each sub-title would then contain a list of entries representing the chapters in the volume.
- Library: The library is a collection of the top-level titles, and it does not contain entries (though the titles do). A Mango instance can only have one library. - Library: The library is a collection of top-level titles, and it does not contain entries (though the titles do). A Mango instance can only have one library.
## Authentication
All endpoints require authentication. After logging in, your session ID would be stored as a cookie named `mango-sessid-#{Config.current.port}`, which can be used to authenticate the API access. Note that all admin API enpoints (`/api/admin/...`) require the logged in user to have admin access.
MD MD
Koa.cookie_auth "cookie", "mango-sessid-#{Config.current.port}" Koa.cookie_auth "cookie", "mango-sessid-#{Config.current.port}"
@ -635,7 +641,7 @@ class APIRouter < Router
end end
end end
Koa.describe "Returns the image dimention of all pages in an entry" Koa.describe "Returns the image dimensions of all pages in an entry"
Koa.path "tid", desc: "A title ID" Koa.path "tid", desc: "A title ID"
Koa.path "eid", desc: "An entry ID" Koa.path "eid", desc: "An entry ID"
Koa.response 200, ref: "$dimensionResult" Koa.response 200, ref: "$dimensionResult"

View File

@ -114,8 +114,8 @@ class MainRouter < Router
end end
end end
get "/swagger" do |env| get "/api" do |env|
render "src/views/swagger.html.ecr" render "src/views/api.html.ecr"
end end
end end
end end

14
src/views/api.html.ecr Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="X-UA-Compatible" content="IE=edge">
<title>Mango API Documentation</title>
<meta name="description" content="Mango - Manga Server and Web Reader">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<redoc spec-url="/openapi.json"></redoc>
<script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"></script>
</body>
</html>

View File

@ -1,22 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="X-UA-Compatible" content="IE=edge">
<title>Mango Swagger-UI</title>
<meta name="description" content="Mango - Manga Server and Web Reader">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@3/swagger-ui.css">
</head>
<body>
<div id="swagger"></div>
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js" charset="UTF-8"></script>
<script>
SwaggerUIBundle({
url: "/openapi.json",
dom_id: '#swagger',
});
</script>
</body>
</html>