Fix/example naming (#6002)

* fix: example naming

* fix: request not being saved when initialized with empty url

* remove check for method

* fix: improve the logic for get initial name

* fix test
This commit is contained in:
sanish chirayath
2025-11-05 22:56:03 +05:30
committed by GitHub
parent 7b183887ce
commit f3cb0d4bae
5 changed files with 35 additions and 53 deletions

View File

@@ -1393,3 +1393,27 @@ export const transformExampleToDraft = (example, newExample) => {
return exampleToDraft;
};
/**
* Generate an initial name for a new response example
* @param {Object} item - The request item that will contain the example
* @returns {string} - The suggested name for the new example
*/
export const getInitialExampleName = (item) => {
const baseName = 'example';
const existingExamples = item.draft?.examples || item.examples || [];
const existingNames = new Set(existingExamples.map((example) => example.name || '').filter(Boolean));
if (!existingNames.has(baseName)) {
return baseName;
}
let counter = 1;
while (true) {
const candidateName = `${baseName} (${counter})`;
if (!existingNames.has(candidateName)) {
return candidateName;
}
counter++;
}
};