feat: customize html title for swagger-ui (#845)

* feat: customize html title for swagger-ui

* chore: add changeset
pull/848/head
rwv 2024-11-26 07:21:30 +08:00 committed by GitHub
parent c063c66a55
commit 934b3932c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
'@hono/swagger-ui': minor
---
customize html title for swagger-ui

View File

@ -35,6 +35,7 @@ type OriginalSwaggerUIOptions = {
* ```
*/
manuallySwaggerUIHtml?: (asset: AssetURLs) => string
title?: string
}
type SwaggerUIOptions = OriginalSwaggerUIOptions & DistSwaggerUIOptions
@ -68,13 +69,14 @@ const SwaggerUI = (options: SwaggerUIOptions) => {
const middleware =
<E extends Env>(options: SwaggerUIOptions): MiddlewareHandler<E> =>
async (c) => {
const title = options?.title ?? "SwaggerUI"
return c.html(/* html */ `
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="SwaggerUI" />
<title>SwaggerUI</title>
<title>${title}</title>
</head>
<body>
${SwaggerUI(options)}