feat: Add some openapi spec stuff

This commit is contained in:
Wanjohi
2025-10-26 00:26:37 +03:00
parent f8f6aae64b
commit a3ad061c25
2 changed files with 65 additions and 23 deletions

View File

@@ -1,6 +1,7 @@
{
"name": "@nestri/function",
"type": "module",
"version":"0.0.1",
"private": true,
"devDependencies": {
"@cloudflare/workers-types": "catalog:",

View File

@@ -1,9 +1,11 @@
import { Hono } from "hono";
import { auth } from "./utils/auth";
import { logger } from "hono/logger";
import { openAPIRouteHandler } from "hono-openapi";
import { Log } from "@nestri/core/utils/log";
import { HTTPException } from "hono/http-exception";
import { VisibleError, ErrorCodes } from "@nestri/core/error";
import packageJson from "../../package.json" assert { type: "json" };
const log = Log.create({ service: "api" });
@@ -16,7 +18,11 @@ app
})
.use(auth);
app.onError((error, c) => {
export const routes = app
.get("/", async (c) => {
return c.text("ok");
})
.onError((error, c) => {
// Handle our custom VisibleError
if (error instanceof VisibleError) {
return c.json(error.toResponse(), error.statusCode());
@@ -46,3 +52,38 @@ app.onError((error, c) => {
500,
);
});
app.get(
"/doc",
openAPIRouteHandler(routes, {
documentation: {
info: {
title: "Nestri API",
termsOfService: "https://nestri.io/terms",
description:
"The Nestri API gives you the power deploy and stream games/apps in the cloud. Run on our GPUs or bring your own.",
version: packageJson.version ?? "1.0.0",
},
components: {
securitySchemes: {
Bearer: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
MemberID: {
type: "apiKey",
description: "The member ID to use for this query",
in: "header",
name: "x-nestri-member",
},
},
},
security: [{ Bearer: [], MemberID: [] }],
servers: [
{ description: "Production", url: "https://api.nestri.io" },
{ description: "Sandbox", url: "https://api.dev.nestri.io" },
],
},
}),
);