Remove JIRA_SCHEMA_ID from entire application

- Remove JIRA_SCHEMA_ID from all documentation, config files, and scripts
- Update generate-schema.ts to always auto-discover schemas dynamically
- Runtime application already discovers schemas via /objectschema/list API
- Build script now automatically selects schema with most objects
- Remove JIRA_SCHEMA_ID from docker-compose.yml, Azure setup scripts, and all docs
- Application is now fully schema-agnostic and discovers schemas automatically
This commit is contained in:
2026-01-22 22:56:29 +01:00
parent f4399a8e4e
commit 57e4adc69c
14 changed files with 63 additions and 47 deletions

View File

@@ -10,6 +10,11 @@
* and their attributes, ensuring the data model is always in sync with the
* actual CMDB configuration.
*
* Schema Discovery:
* - Automatically discovers available schemas via /objectschema/list
* - Selects the schema with the most objects (or the first one if counts unavailable)
* - The runtime application also discovers schemas dynamically
*
* Usage: npm run generate-schema
*/
@@ -38,7 +43,6 @@ for (const envPath of envPaths) {
// Configuration
const JIRA_HOST = process.env.JIRA_HOST || '';
const JIRA_PAT = process.env.JIRA_PAT || '';
const JIRA_SCHEMA_ID = process.env.JIRA_SCHEMA_ID || '';
const OUTPUT_DIR = path.resolve(__dirname, '../src/generated');
@@ -255,6 +259,36 @@ class JiraSchemaFetcher {
}
}
/**
* List all available schemas
*/
async listSchemas(): Promise<JiraObjectSchema[]> {
try {
const response = await fetch(`${this.baseUrl}/objectschema/list`, {
headers: this.headers,
});
if (!response.ok) {
console.error(`Failed to list schemas: ${response.status} ${response.statusText}`);
return [];
}
const result = await response.json();
// Handle both array and object responses
if (Array.isArray(result)) {
return result;
} else if (result && typeof result === 'object' && 'objectschemas' in result) {
return result.objectschemas || [];
}
return [];
} catch (error) {
console.error(`Error listing schemas:`, error);
return [];
}
}
/**
* Test the connection
*/
@@ -819,17 +853,10 @@ async function main() {
process.exit(1);
}
if (!JIRA_SCHEMA_ID) {
console.error('❌ ERROR: JIRA_SCHEMA_ID environment variable is required');
console.error(' Set this in your .env file: JIRA_SCHEMA_ID=6');
process.exit(1);
}
if (envLoaded) {
console.log(`🔧 Environment: ${envLoaded}`);
}
console.log(`📡 Jira Host: ${JIRA_HOST}`);
console.log(`📋 Schema ID: ${JIRA_SCHEMA_ID}`);
console.log(`📁 Output Dir: ${OUTPUT_DIR}`);
console.log('');
@@ -852,20 +879,41 @@ async function main() {
console.log('✅ Connection successful');
console.log('');
// Fetch schema info
console.log('📋 Fetching schema information...');
const schema = await fetcher.fetchSchema(JIRA_SCHEMA_ID);
if (!schema) {
console.error(`❌ Failed to fetch schema ${JIRA_SCHEMA_ID}`);
// Discover schema automatically
console.log('📋 Discovering available schemas...');
const schemas = await fetcher.listSchemas();
if (schemas.length === 0) {
console.error('❌ No schemas found');
console.error(' Please ensure Jira Assets is configured and accessible');
process.exit(1);
}
// Select the schema with the most objects (or the first one if counts unavailable)
const schema = schemas.reduce((prev, current) => {
const prevCount = prev.objectCount || 0;
const currentCount = current.objectCount || 0;
return currentCount > prevCount ? current : prev;
});
const selectedSchemaId = schema.id.toString();
console.log(` Found ${schemas.length} schema(s)`);
if (schemas.length > 1) {
console.log(' Available schemas:');
schemas.forEach(s => {
const marker = s.id === schema.id ? ' → ' : ' ';
console.log(`${marker}${s.id}: ${s.name} (${s.objectSchemaKey}) - ${s.objectCount || 0} objects`);
});
console.log(` Using schema: ${schema.name} (ID: ${selectedSchemaId})`);
}
console.log(` Schema: ${schema.name} (${schema.objectSchemaKey})`);
console.log(` Total objects: ${schema.objectCount || 'unknown'}`);
console.log('');
// Fetch ALL object types from the schema
console.log('📦 Fetching all object types from schema...');
const allObjectTypes = await fetcher.fetchAllObjectTypes(JIRA_SCHEMA_ID);
const allObjectTypes = await fetcher.fetchAllObjectTypes(selectedSchemaId);
if (allObjectTypes.length === 0) {
console.error('❌ No object types found in schema');