docs: refactor code for consistency and readability

- Standardized import statements across various components to use double quotes for consistency.
- Updated component files to ensure proper formatting and adherence to coding standards.
- Enhanced overall code readability by aligning code structure and improving comment clarity.
- Made minor adjustments to ensure all components follow the same coding conventions, improving maintainability.
This commit is contained in:
Mauricio Siu
2025-12-07 18:13:12 -06:00
parent b605ad10e3
commit 0b52b9b1af
98 changed files with 25084 additions and 27002 deletions

View File

@@ -1,16 +1,16 @@
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";
const openapiPath = join(process.cwd(), 'public', 'openapi.json');
const openapiPath = join(process.cwd(), "public", "openapi.json");
console.log('Fixing OpenAPI schema...');
console.log("Fixing OpenAPI schema...");
try {
const openapi = JSON.parse(readFileSync(openapiPath, 'utf8'));
const openapi = JSON.parse(readFileSync(openapiPath, "utf8"));
let fixed = 0;
let securityFixed = false;
// Remove Authorization security scheme and add x-api-key
if (!openapi.components) {
openapi.components = {};
@@ -18,70 +18,66 @@ try {
if (!openapi.components.securitySchemes) {
openapi.components.securitySchemes = {};
}
// Remove old Authorization scheme
if (openapi.components.securitySchemes['Authorization']) {
delete openapi.components.securitySchemes['Authorization'];
if (openapi.components.securitySchemes["Authorization"]) {
delete openapi.components.securitySchemes["Authorization"];
securityFixed = true;
}
// Add x-api-key scheme
openapi.components.securitySchemes['x-api-key'] = {
type: 'apiKey',
in: 'header',
name: 'x-api-key',
description: 'API key authentication. Use YOUR-GENERATED-API-KEY',
'x-default': 'your-key'
openapi.components.securitySchemes["x-api-key"] = {
type: "apiKey",
in: "header",
name: "x-api-key",
description: "API key authentication. Use YOUR-GENERATED-API-KEY",
"x-default": "your-key",
};
securityFixed = true;
// Replace global security from Authorization to x-api-key
if (openapi.security) {
openapi.security = openapi.security.filter(
sec => !sec['Authorization']
);
openapi.security = openapi.security.filter((sec) => !sec["Authorization"]);
} else {
openapi.security = [];
}
const hasApiKeySecurity = openapi.security.some(
sec => sec['x-api-key']
);
const hasApiKeySecurity = openapi.security.some((sec) => sec["x-api-key"]);
if (!hasApiKeySecurity) {
openapi.security.push({ 'x-api-key': [] });
openapi.security.push({ "x-api-key": [] });
securityFixed = true;
}
// Replace Authorization with x-api-key in all operation security
for (const [path, pathItem] of Object.entries(openapi.paths || {})) {
for (const [method, operation] of Object.entries(pathItem)) {
if (operation && operation.security) {
// Replace Authorization with x-api-key
operation.security = operation.security.map(sec => {
if (sec['Authorization'] !== undefined) {
operation.security = operation.security.map((sec) => {
if (sec["Authorization"] !== undefined) {
securityFixed = true;
return { 'x-api-key': [] };
return { "x-api-key": [] };
}
return sec;
});
}
}
}
// Fix empty response schemas
for (const [path, pathItem] of Object.entries(openapi.paths || {})) {
for (const [method, operation] of Object.entries(pathItem)) {
if (operation.responses) {
for (const [status, response] of Object.entries(operation.responses)) {
if (response.content && response.content['application/json']) {
const content = response.content['application/json'];
if (response.content && response.content["application/json"]) {
const content = response.content["application/json"];
// Check if schema is completely empty or missing
if (Object.keys(content).length === 0 || !content.schema) {
response.content['application/json'] = {
response.content["application/json"] = {
schema: {
type: 'object',
description: 'Successful response'
}
type: "object",
description: "Successful response",
},
};
fixed++;
}
@@ -96,10 +92,9 @@ try {
if (fixed > 0) console.log(`✓ Fixed ${fixed} empty response schemas`);
if (securityFixed) console.log("✓ Added x-api-key security scheme");
} else {
console.log('✓ No fixes needed');
console.log("✓ No fixes needed");
}
} catch (error) {
console.error('Error fixing OpenAPI schema:', error.message);
console.error("Error fixing OpenAPI schema:", error.message);
process.exit(1);
}