mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
- Added @readme/openapi-parser as a dependency in Scripts/package.json. - Introduced a new script command "generate-openapi-spec" in package.json for generating OpenAPI specifications. - Removed the obsolete test_schema_permissions.js file. - Created a new script (GenerateSpec.ts) to generate and validate the OpenAPI spec, saving it to openapi.json.
25 lines
767 B
TypeScript
25 lines
767 B
TypeScript
import OpenAPI from "Common/Server/Utils/OpenAPI";
|
|
import fs from "fs";
|
|
import { validate, ValidationResult } from "@readme/openapi-parser";
|
|
import JSONFunctions from "Common/Types/JSONFunctions";
|
|
import BadDataException from "Common/Types/Exception/BadDataException";
|
|
|
|
const spec = OpenAPI.generateOpenAPISpec();
|
|
|
|
const validationResult: ValidationResult = await validate(
|
|
JSONFunctions.toString(spec)
|
|
);
|
|
|
|
if (validationResult.valid) {
|
|
console.log("OpenAPI spec is valid.");
|
|
} else {
|
|
throw new BadDataException("OpenAPI spec validation failed.");
|
|
}
|
|
|
|
// Write the OpenAPI spec to a file
|
|
|
|
const outputPath = "./openapi.json";
|
|
fs.writeFileSync(outputPath, JSON.stringify(spec, null, 2), "utf8");
|
|
|
|
console.log(`OpenAPI spec generated and saved to ${outputPath}`);
|