mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
feat: Update package dependencies and add OpenAPI spec generation
- 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.
This commit is contained in:
24
Scripts/OpenAPI/GenerateSpec.ts
Normal file
24
Scripts/OpenAPI/GenerateSpec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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}`);
|
||||
853
Scripts/package-lock.json
generated
853
Scripts/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -6,9 +6,8 @@
|
||||
"compile": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@readme/openapi-parser": "^4.1.0",
|
||||
"Common": "file:../Common",
|
||||
|
||||
|
||||
"ejs": "^3.1.10",
|
||||
"ts-node": "^10.9.2"
|
||||
},
|
||||
@@ -21,4 +20,4 @@
|
||||
},
|
||||
"author": "OneUptime <hello@oneuptime.com> (https://oneuptime.com/)",
|
||||
"license": "Apache-2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,8 @@
|
||||
"deploy-test": "kubectl config use-context oneuptime-test && helm upgrade oneuptime ./HelmChart/Public/oneuptime -f ./HelmChart/Public/oneuptime/values.yaml -f ./HelmChart/Values/test.values.yaml",
|
||||
"template-deploy-test": "kubectl config use-context oneuptime-test && helm template oneuptime ./HelmChart/Public/oneuptime -f ./HelmChart/Public/oneuptime/values.yaml -f ./HelmChart/Values/test.values.yaml --debug",
|
||||
"deploy-prod": "kubectl config use-context oneuptime-prod && helm upgrade oneuptime ./HelmChart/Public/oneuptime -f ./HelmChart/Public/oneuptime/values.yaml -f ./HelmChart/Values/prod.values.yaml",
|
||||
"generate-postgres-migration": "export $(grep -v '^#' config.env | xargs) && node --require ts-node/register ./node_modules/typeorm/cli.js migration:generate ./Common/Server/Infrastructure/Postgres/SchemaMigrations/MigrationName -d ./Common/Server/Infrastructure/Postgres/LocalMigrationGenerationDataSource.ts"
|
||||
"generate-postgres-migration": "export $(grep -v '^#' config.env | xargs) && node --require ts-node/register ./node_modules/typeorm/cli.js migration:generate ./Common/Server/Infrastructure/Postgres/SchemaMigrations/MigrationName -d ./Common/Server/Infrastructure/Postgres/LocalMigrationGenerationDataSource.ts",
|
||||
"generate-openapi-spec": "node --require ts-node/register ./Scripts/OpenAPI/GenerateSpec.ts"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Simple test script to validate schema generation with permission filtering
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
console.log('Testing schema permission filtering...');
|
||||
|
||||
// Check if the ModelSchema.ts file has the correct changes
|
||||
const modelSchemaPath = path.join(__dirname, 'Common/Utils/Schema/ModelSchema.ts');
|
||||
|
||||
if (fs.existsSync(modelSchemaPath)) {
|
||||
const content = fs.readFileSync(modelSchemaPath, 'utf8');
|
||||
|
||||
// Check for the updated formatPermissionsForSchema method
|
||||
const hasCorrectPermissionMessage = content.includes('No access - restricted access only');
|
||||
console.log('✓ formatPermissionsForSchema updated:', hasCorrectPermissionMessage ? 'PASS' : 'FAIL');
|
||||
|
||||
// Check for permission filtering in getModelSchema
|
||||
const hasGeneralSchemaFiltering = content.includes('// Get column access control for permission filtering') &&
|
||||
content.includes('const columnAccessControl: Dictionary<ColumnAccessControl> = model.getColumnAccessControlForAllColumns();') &&
|
||||
content.includes('hasReadPermissions');
|
||||
console.log('✓ getModelSchema permission filtering:', hasGeneralSchemaFiltering ? 'PASS' : 'FAIL');
|
||||
|
||||
// Check for permission filtering in buildModelSchema
|
||||
const hasBuildSchemaFiltering = content.includes('// Filter out columns with no permissions (root-only access)') &&
|
||||
content.includes('hasPermissions = true;');
|
||||
console.log('✓ buildModelSchema permission filtering:', hasBuildSchemaFiltering ? 'PASS' : 'FAIL');
|
||||
|
||||
if (hasCorrectPermissionMessage && hasGeneralSchemaFiltering && hasBuildSchemaFiltering) {
|
||||
console.log('\n🎉 All permission filtering changes implemented successfully!');
|
||||
console.log('\nSummary of changes:');
|
||||
console.log('1. formatPermissionsForSchema now returns "No access - restricted access only" for empty permissions');
|
||||
console.log('2. getModelSchema now filters out columns with no read permissions');
|
||||
console.log('3. buildModelSchema filters columns based on operation-specific permissions (create/read/update)');
|
||||
console.log('\nColumns with empty permission arrays will now be excluded from OpenAPI schemas entirely.');
|
||||
} else {
|
||||
console.log('\n❌ Some changes are missing. Please review the implementation.');
|
||||
}
|
||||
} else {
|
||||
console.log('❌ ModelSchema.ts file not found at expected location.');
|
||||
}
|
||||
Reference in New Issue
Block a user