run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<int> run() async {
await buildOpenapiDocumentProgress(logger, CancellationToken());
final specs =
await getPathFromRoot(path.join(".reedmace", "api_specs.json"))
.readAsString();
var swaggerPage = """<html>
<head>
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@3/swagger-ui.css"/>
<title>API Docs</title>
</head>
<body>
<div id="swagger-ui"></div> <!-- Div to hold the UI component -->
<script>
window.onload = function () {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
})
window.ui = ui
}
</script>
</body>
</html>""";
var router = Router();
router.get(
"/",
(Request request) =>
Response.ok(swaggerPage, headers: {"Content-Type": "text/html"}));
router.get(
"/swagger.json",
(Request request) =>
Response.ok(specs, headers: {"Content-Type": "application/json"}));
logger.success(
"Serving OpenAPI documentation on http://localhost:${argResults!["port"]!}");
var server = await io.serve(
router, argResults!["address"]!, int.parse(argResults!["port"]!));
await ProcessSignal.sigint.watch().first;
logger.info("Exiting...");
server.close(force: true);
return 0;
}