Spaces:
Runtime error
Runtime error
File size: 1,971 Bytes
fb38ec5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | import { FastifyPluginAsync } from "fastify";
import fp from "fastify-plugin";
import fastifySwagger from "@fastify/swagger";
import fastifyScalar from "@scalar/fastify-api-reference";
import { titleCase } from "../utils/text.js";
import actionSchemas from "../modules/actions/actions.schema.js";
import cdpSchemas from "../modules/cdp/cdp.schemas.js";
import logsSchemas from "../modules/logs/logs.schema.js";
import browserSchemas from "../modules/sessions/sessions.schema.js";
import seleniumSchemas from "../modules/selenium/selenium.schema.js";
import scalarTheme from "./scalar-theme.js";
import { buildJsonSchemas } from "../utils/schema.js";
import filesSchemas from "../modules/files/files.schema.js";
import { getBaseUrl } from "../utils/url.js";
const SCHEMAS = {
...actionSchemas,
...browserSchemas,
...logsSchemas,
...cdpSchemas,
...seleniumSchemas,
...filesSchemas,
};
export const { schemas, $ref } = buildJsonSchemas(SCHEMAS);
const schemaPlugin: FastifyPluginAsync = async (fastify) => {
for (const schema of schemas) {
fastify.addSchema(schema);
}
await fastify.register(fastifySwagger, {
openapi: {
info: {
title: "Steel Browser Instance API",
description: "Documentation for controlling a single instance of Steel Browser",
version: "0.0.1",
},
servers: [
{
url: getBaseUrl(),
description: "Local server",
},
],
paths: {}, // paths must be included even if it's an empty object
components: {
securitySchemes: {},
},
},
refResolver: {
buildLocalReference: (json, baseUri, fragment, i) => {
return titleCase(json.$id as string) || `Fragment${i}`;
},
},
});
await fastify.register(fastifyScalar as any, {
// scalar still uses fastify v4
routePrefix: "/documentation",
configuration: {
customCss: scalarTheme,
},
});
};
export default fp(schemaPlugin);
|