Skip to content

Commit

Permalink
Merge pull request #54 from hanspagel/main
Browse files Browse the repository at this point in the history
feat: add scalar as an alternative UI
  • Loading branch information
ad-on-is authored Mar 14, 2024
2 parents 43106ab + d6e0b8c commit ed438a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ router.get("/swagger", async () => {
// Renders Swagger-UI and passes YAML-output of /swagger
router.get("/docs", async () => {
return AutoSwagger.default.ui("/swagger", swagger);
// return AutoSwagger.default.scalar("/swagger", swagger); to use Scalar instead
// return AutoSwagger.default.rapidoc("/swagger", swagger); to use RapiDoc instead
});
```
Expand Down
24 changes: 24 additions & 0 deletions src/autoswagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,30 @@ export class AutoSwagger {
);
}

scalar(url: string) {
return (
`
<!doctype html>
<html>
<head>
<title>API Reference</title>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1" />
</head>
<body>
<script
id="api-reference"
data-url="${url}"
data-proxy-url="https://api.scalar.com/request-proxy"></script>
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
</body>
</html>
`
);
}

async writeFile(routes: any, options: options) {
const contents = await this.generate(routes, options);
const filePath = options.path + "swagger.yml";
Expand Down

0 comments on commit ed438a2

Please sign in to comment.