Enable Scalar + OpenAPI spec for user posting
This commit is contained in:
@@ -3,6 +3,8 @@ import { cors } from "hono/cors";
|
||||
import { Server as Engine } from "@socket.io/bun-engine";
|
||||
import { Server } from "socket.io";
|
||||
import routes from "./routes/index";
|
||||
import { Scalar } from "@scalar/hono-api-reference";
|
||||
import { openAPIRouteHandler } from "hono-openapi";
|
||||
|
||||
//initialize socket.io server
|
||||
const io = new Server();
|
||||
@@ -50,4 +52,22 @@ app.use(
|
||||
|
||||
app.route("/api", routes);
|
||||
|
||||
app.get(
|
||||
'/openapi',
|
||||
openAPIRouteHandler(app, {
|
||||
documentation: {
|
||||
info: {
|
||||
title: 'Hono API',
|
||||
version: '1.0.0',
|
||||
description: 'Greeting API',
|
||||
},
|
||||
servers: [
|
||||
{ url: 'http://localhost:3000', description: 'Local Server' },
|
||||
],
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
app.get('/scalar', Scalar({ url: '/openapi' }))
|
||||
|
||||
export default app;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Hono } from "hono";
|
||||
import { fetchAllUsers, fetchUserData, createNewUser } from "../controller/userController";
|
||||
import { createUserSchema } from "../validators/userValidator";
|
||||
import { zValidator } from "@hono/zod-validator";
|
||||
import { describeRoute, resolver } from "hono-openapi";
|
||||
const actions = new Hono();
|
||||
|
||||
actions.get("user/:id", async (c) => {
|
||||
@@ -30,6 +31,17 @@ actions.get("user", async (c) => {
|
||||
|
||||
actions.post(
|
||||
"user",
|
||||
describeRoute({
|
||||
description: "Create a new user",
|
||||
responses: {
|
||||
201: {
|
||||
description: "Success",
|
||||
content: {
|
||||
'application/json': { schema: resolver(createUserSchema) },
|
||||
},
|
||||
}
|
||||
}
|
||||
}),
|
||||
zValidator('json', createUserSchema),
|
||||
async (c) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user