mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 22:45:25 +00:00
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:
@@ -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++;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user