The current checks that run in the code repo does not validate the resulting API names which leads to some downstream errors in the last mile of install via marketplace. Ideally this gets checked and will output the same warnings or errors in the code repo.
2 Likes
We have the same problem.
1 Like
Hey, thanks for the signal. We are actively working on more comprehensive compilation checks and will make sure to add an explicit error for this.
1 Like
If anyone needs an interim solution I vibe coed a small api name checker (it only checks api names) that includes the max char limit. I hand rolled the validation function but vibed out the rest, so this is definitely use at your own risk. But I ran it over an ontology with over 80 objects and got good results.
#!/usr/bin/env node
const fs = require("node:fs");
const path = require("node:path");
const FILE_PATH = path.resolve(process.cwd(), "./src/index.mts");
function validateApiName(apiName) {
const RESERVED_KEYWORDS = new Set([
"ontology",
"object",
"property",
"link",
"relation",
"rid",
"primarykey",
"typeid",
"ontologyobject",
]);
const OBJECT_API_NAME_PATTERN = /^([a-zA-Z][a-zA-Z0-9]*)$/;
const API_NAME_PATTERN = /^([a-zA-Z][a-zA-Z0-9_]*)$/;
function isValidApiName(value) {
return (
API_NAME_PATTERN.test(value) &&
!RESERVED_KEYWORDS.has(value.toLowerCase()) &&
value.length <= 100
);
}
function isValidObjectApiName(value) {
return (
OBJECT_API_NAME_PATTERN.test(value) &&
!RESERVED_KEYWORDS.has(value.toLowerCase()) &&
value.length <= 100
);
}
return isValidApiName(apiName) && isValidObjectApiName(apiName);
}
function getApiNames(sourceText) {
const apiNames = [];
const regex = /\bapiName\s*:\s*"([^"]+)"/g;
let match;
while ((match = regex.exec(sourceText)) !== null) {
apiNames.push({
apiName: match[1],
index: match.index,
});
}
return apiNames;
}
function getLineNumber(sourceText, charIndex) {
return sourceText.slice(0, charIndex).split("\n").length;
}
function main() {
if (!fs.existsSync(FILE_PATH)) {
console.error(`File not found: ${FILE_PATH}`);
process.exit(1);
}
const content = fs.readFileSync(FILE_PATH, "utf8");
const apiNameEntries = getApiNames(content);
const counts = new Map();
for (const entry of apiNameEntries) {
counts.set(entry.apiName, (counts.get(entry.apiName) || 0) + 1);
}
const failures = [];
for (const entry of apiNameEntries) {
const occurrences = counts.get(entry.apiName) || 0;
const isUnique = occurrences === 1;
const isValid = validateApiName(entry.apiName);
if (!isUnique || !isValid) {
failures.push({
apiName: entry.apiName,
line: getLineNumber(content, entry.index),
occurrences,
isUnique,
isValid,
length: entry.apiName.length,
});
}
}
const uniqueApiNameCount = counts.size;
const duplicateApiNames = [...counts.entries()]
.filter(([, count]) => count > 1)
.map(([apiName, count]) => ({ apiName, count }));
console.log("=== API NAME TEST RESULTS ===");
console.log(`File: ${FILE_PATH}`);
console.log(`Total apiName entries found: ${apiNameEntries.length}`);
console.log(`Unique apiName values found: ${uniqueApiNameCount}`);
console.log(`Duplicate apiName values found: ${duplicateApiNames.length}`);
console.log(`Failing apiName entries found: ${failures.length}`);
console.log("");
if (duplicateApiNames.length > 0) {
console.log("=== DUPLICATE API NAMES ===");
for (const dup of duplicateApiNames) {
console.log(`- ${dup.apiName} (occurrences: ${dup.count})`);
}
console.log("");
}
if (failures.length > 0) {
console.log("=== FAILING API NAME ENTRIES ===");
for (const failure of failures) {
console.log(
[
`- apiName: ${failure.apiName}`,
`line: ${failure.line}`,
`occurrences: ${failure.occurrences}`,
`unique: ${failure.isUnique}`,
`valid: ${failure.isValid}`,
`length: ${failure.length}`,
].join(" | ")
);
}
process.exitCode = 1;
return;
}
console.log("All apiNames are unique and passed validation.");
}
main();
Output should look like:
=== API NAME TEST RESULTS ===
File: /home/user/repo/src/index.mts
Total apiName entries found: 685
Unique apiName values found: 685
Duplicate apiName values found: 0
Failing apiName entries found: 0
All apiNames are unique and passed validation.