Skip to content

Commit

Permalink
feat: add openAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
yamashita-kenngo committed May 10, 2024
1 parent db718e4 commit c4c9062
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 12 deletions.
77 changes: 71 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
},
"dependencies": {
"@hono/node-server": "^1.11.1",
"@hono/zod-openapi": "^0.11.0",
"@types/jest": "^29.5.12",
"hono": "^4.2.9",
"hono": "^4.3.4",
"jest": "^29.7.0",
"ts-jest": "^29.1.2"
"ts-jest": "^29.1.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^20.11.17",
Expand Down
17 changes: 13 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { serve } from '@hono/node-server'
import { Hono } from 'hono'
import { OpenAPIHono } from '@hono/zod-openapi'
import { route } from './router'

const app = new Hono()
const app = new OpenAPIHono()

app.get('/', (c) => {
return c.json({ message: 'Hello World!'})
app.openapi(route, (c) => {
return c.json({ message: 'Hello World!' })
})

app.doc('/doc', {
openapi: '3.0.0',
info: {
title: 'My API',
version: '1.0.0'
},
})

const port = parseInt(process.env.PORT!) || 3000
Expand Down
23 changes: 23 additions & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createRoute } from "@hono/zod-openapi"

export const route = createRoute({
method: 'get',
path: '/',
responses: {
200: {
description: 'OK',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
message: {
type: 'string'
}
}
}
}
}
}
},
})

0 comments on commit c4c9062

Please sign in to comment.