Enable Scalar + OpenAPI spec for user posting

This commit is contained in:
Kevin Puig
2025-09-27 13:20:15 -04:00
parent 3d79c9cf4f
commit b9982b626f
4 changed files with 36 additions and 0 deletions

View File

@@ -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;

View File

@@ -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 {