Added very basic api doc chooser

ref #52
This commit is contained in:
Nicolai Ort 2020-12-23 15:11:04 +01:00
parent d8e38f404d
commit ebedea97ed
8 changed files with 383 additions and 5 deletions

2
.gitignore vendored
View File

@ -132,5 +132,5 @@ build
*.sqlite
*.sqlite-jurnal
docs
/docs
lib

View File

@ -1,5 +1,6 @@
import { validationMetadatasToSchemas } from "class-validator-jsonschema";
import { Application } from "express";
import express, { Application } from "express";
import path from 'path';
import { getMetadataArgsStorage } from "routing-controllers";
import { routingControllersToSpec } from "routing-controllers-openapi";
import * as swaggerUiExpress from "swagger-ui-express";
@ -51,12 +52,13 @@ export default async (app: Application) => {
explorer: true,
};
app.use(
"/api/docs",
"/api/docs/swagger",
swaggerUiExpress.serve,
swaggerUiExpress.setup(spec, options)
);
app.get(["/api/openapi.json", "/api/swagger.json"], (req, res) => {
app.get(["/api/docs/openapi.json", "/api/docs/swagger.json"], (req, res) => {
res.json(spec);
});
app.use('/api/docs', express.static(path.join(__dirname, '../static/docs'), { index: "index.html", extensions: ['html'] }));
return app;
};

View File

@ -36,7 +36,14 @@ const spec = routingControllersToSpec(
"AuthToken": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
"bearerFormat": "JWT",
description: "A JWT based access token. Use /api/auth/login or /api/auth/refresh to get one."
},
"RefreshTokenCookie": {
"type": "apiKey",
"in": "cookie",
"name": "lfk_backend__refresh_token",
description: "A cookie containing a JWT based refreh token. Attention: Doesn't work in swagger-ui. Use /api/auth/login or /api/auth/refresh to get one."
}
}
},

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<h1>Pick your poison</h1>
<ul>
<li>
<a href="./redoc">ReDoc</a>
</li>
<li>
<a href="./swagger">SwaggerUI</a>
</li>
<li>
<a href="./rapidoc">RapiDoc</a>
</li>
<li>
<a href="./openapi.json">Raw Spec (json)</a>
</li>
</ul>

220
src/static/docs/rapidoc-min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="module" src="./rapidoc-min.js"></script>
</head>
<body>
<rapi-doc
spec-url="/api/docs/openapi.json"
> </rapi-doc>
</body>
</html>

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<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>
</head>
<body>
<redoc spec-url='/api/docs/openapi.json'></redoc>
<script src="./redoc.standalone.js"> </script>
</body>
</html>

File diff suppressed because one or more lines are too long