boredgame/src/lib/server/api/configure-open-api.ts

43 lines
956 B
TypeScript
Raw Normal View History

2024-12-01 23:34:04 +00:00
import { apiReference } from '@scalar/hono-api-reference';
import { createOpenApiDocument } from 'hono-zod-openapi';
import packageJSON from '../../../../package.json';
2024-12-01 23:34:04 +00:00
import type { AppOpenAPI } from './common/utils/hono';
export default function configureOpenAPI(app: AppOpenAPI) {
2024-12-01 23:34:04 +00:00
createOpenApiDocument(app, {
info: {
title: 'Bored Game API',
description: 'Bored Game API',
version: packageJSON.version,
},
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
},
cookieAuth: {
type: 'apiKey',
name: 'session',
in: 'cookie',
},
},
},
});
2024-12-01 23:34:04 +00:00
app.get(
'/reference',
apiReference({
theme: 'kepler',
layout: 'classic',
defaultHttpClient: {
targetKey: 'javascript',
clientKey: 'fetch',
},
spec: {
url: '/api/doc',
},
}),
);
}