feat(api): replace astro openapi with hono openapi ui
All checks were successful
Build and Push Docker Image / build (push) Successful in 55s

This commit is contained in:
Lars Hampe 2024-09-28 22:20:25 +02:00
parent d7c1b0525a
commit fad940b517
7 changed files with 25 additions and 25 deletions

View File

@ -10,6 +10,7 @@
"@boring.tools/schema": "workspace:*", "@boring.tools/schema": "workspace:*",
"@hono/clerk-auth": "^2.0.0", "@hono/clerk-auth": "^2.0.0",
"@hono/zod-openapi": "^0.16.2", "@hono/zod-openapi": "^0.16.2",
"@scalar/hono-api-reference": "^0.5.149",
"hono": "^4.6.3" "hono": "^4.6.3"
}, },
"devDependencies": { "devDependencies": {

View File

@ -1,5 +1,6 @@
import type { UserOutput } from '@boring.tools/schema' import type { UserOutput } from '@boring.tools/schema'
import { OpenAPIHono, type z } from '@hono/zod-openapi' import { OpenAPIHono, type z } from '@hono/zod-openapi'
import { apiReference } from '@scalar/hono-api-reference'
import { cors } from 'hono/cors' import { cors } from 'hono/cors'
import user from './user' import user from './user'
@ -27,6 +28,17 @@ app.doc('/openapi.json', {
}, },
}) })
app.get(
'/',
apiReference({
pageTitle: 'boring.tools API',
theme: 'purple',
spec: {
url: '/openapi.json',
},
}),
)
export default { export default {
port: 3000, port: 3000,
fetch: app.fetch, fetch: app.fetch,

View File

@ -1,6 +1,5 @@
import starlight from '@astrojs/starlight' import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config' import { defineConfig } from 'astro/config'
import starlightOpenAPI, { openAPISidebarGroups } from 'starlight-openapi'
export default defineConfig({ export default defineConfig({
outDir: '../../build/website', outDir: '../../build/website',
@ -20,31 +19,18 @@ export default defineConfig({
social: { social: {
github: 'https://github.com/boring-tools/boring.tools', github: 'https://github.com/boring-tools/boring.tools',
}, },
favicon: '/public/favicon.svg', favicon: '/favicon.svg',
sidebar: [ sidebar: [
{ {
label: 'Guides', label: 'Guides',
items: [{ label: 'Getting started', slug: 'guides/getting-started' }], items: [{ label: 'Getting started', slug: 'guides/getting-started' }],
}, },
...openAPISidebarGroups, { label: 'API', link: 'https://api.boring.tools' },
// { // {
// label: 'Reference', // label: 'Reference',
// autogenerate: { directory: 'reference' }, // autogenerate: { directory: 'reference' },
// }, // },
], ],
plugins: [
// Generate the OpenAPI documentation pages.
starlightOpenAPI([
{
base: 'api',
label: 'API',
schema:
import.meta.env.NODE_ENV !== 'production'
? 'http://localhost:3000/openapi.json'
: 'https://api.boring.tools/openapi.json',
},
]),
],
}), }),
], ],
}) })

View File

@ -14,7 +14,6 @@
"@astrojs/starlight": "^0.28.2", "@astrojs/starlight": "^0.28.2",
"astro": "^4.15.3", "astro": "^4.15.3",
"sharp": "^0.32.5", "sharp": "^0.32.5",
"starlight-openapi": "^0.7.0",
"typescript": "^5.6.2" "typescript": "^5.6.2"
} }
} }

BIN
bun.lockb

Binary file not shown.

View File

@ -1,9 +1,11 @@
import { z } from '@hono/zod-openapi' import { z } from '@hono/zod-openapi'
export const UserOutput = z.object({ export const UserOutput = z
id: z.string().openapi({ .object({
example: 'user_2metCkqOhUhHN1jEhLyh8wMODu7', id: z.string().openapi({
}), example: 'user_2metCkqOhUhHN1jEhLyh8wMODu7',
name: z.string(), }),
email: z.string().email(), name: z.string(),
}) email: z.string().email(),
})
.openapi('User')

View File

@ -27,4 +27,4 @@ export const UserWebhookInput = z
examples: ['user.created', 'user.updated'], examples: ['user.created', 'user.updated'],
}), }),
}) })
.openapi('User') .openapi('User Webhook')