Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add openAPI #13

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!' })
})
yamashita-kenngo marked this conversation as resolved.
Show resolved Hide resolved

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'
}
}
}
}
}
}
},
})
yamashita-kenngo marked this conversation as resolved.
Show resolved Hide resolved
Loading