create-prisma-php-app
Version:
Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM
69 lines (62 loc) • 1.8 kB
text/typescript
import swaggerJsdoc from "swagger-jsdoc";
import { writeFileSync } from "fs";
import { join } from "path";
import chalk from "chalk";
import { getFileMeta } from "./utils.js";
import bsConfigJson from "./bs-config.json";
import prismaPhpConfigJson from "../prisma-php.json";
const { __dirname } = getFileMeta();
export async function swaggerConfig(): Promise<void> {
const outputPath = join(
__dirname,
"../src/app/swagger-docs/apis/pp-swagger.json"
);
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "Prisma PHP API Documentation",
version: "1.0.0",
description: "API documentation for the Prisma PHP project",
},
servers: [
{
url: bsConfigJson.local,
description: "Development Server",
},
{
url: "your-production-domain",
description: "Production Server",
},
],
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
},
},
security: [
{
bearerAuth: [],
},
],
},
apis: [join(__dirname, "../src/app/swagger-docs/apis/**/*.js")],
};
const swaggerSpec = JSON.stringify(swaggerJsdoc(options), null, 2);
try {
writeFileSync(outputPath, swaggerSpec, "utf-8");
console.log(
`Swagger JSON has been generated and saved to ${chalk.blue(
"src/app/swagger-docs/apis/pp-swagger.json"
)}`
);
} catch (error) {
console.error("Error saving Swagger JSON:", error);
}
}
if (prismaPhpConfigJson.swaggerDocs && !prismaPhpConfigJson.prisma)
swaggerConfig();