Skip to content

Commit

Permalink
feat: impl OAS API Document exporter (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
laminne authored May 12, 2024
1 parent 1f27755 commit 1993eeb
Show file tree
Hide file tree
Showing 4 changed files with 1,860 additions and 12 deletions.
11 changes: 11 additions & 0 deletions apidoc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { writeFileSync } from 'fs';
import { testClient } from 'hono/testing';

import { app } from './main.js';

const client = testClient(app);
const res = await client.doc.$get();
const schema = await res.json();
writeFileSync('./resources/schema.json', JSON.stringify(schema, null, 2));
console.log('API Schema has been generated successfully.');
process.exit(0);
20 changes: 9 additions & 11 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ import { Hono } from 'hono';
import { accounts } from './pkg/accounts/mod.js';
import { noteHandlers } from './pkg/notes/mod.js';

const app = new Hono();

/*
All routes must be "/"
(The "/" account cannot be written in the library specification.
*/
app.route('/', noteHandlers);
app.route('/', accounts);

app.get('/doc.json', async (c) => {
export const app = new Hono().get('/doc', async (c) => {
const modulePath: string[] = ['accounts', 'notes'];
const basePath = 'http://localhost:3000/';
const openAPIBase = {
Expand Down Expand Up @@ -51,12 +42,19 @@ app.get('/doc.json', async (c) => {
return c.json(openAPIBase);
});

/*
All routes must be "/"
(The "/" account cannot be written in the library specification.
*/
app.route('/', noteHandlers);
app.route('/', accounts);

app.get(
'/reference',
apiReference({
pageTitle: 'Pulsate API',
spec: {
url: '/doc.json',
url: '/doc',
},
}),
);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"format:check": "prettier --check \"./**/*.{js,ts,md}\"",
"lint": "eslint . ",
"prepare": "pnpm run build:prisma",
"postinstall": "lefthook install"
"postinstall": "lefthook install",
"docs:api": "node ./build/apidoc.js"
},
"dependencies": {
"@hono/node-server": "^1.7.0",
Expand Down
Loading

0 comments on commit 1993eeb

Please sign in to comment.