mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Insert spaces in snake_case/camelCase request/folder names
This commit is contained in:
22
lib/util.js
22
lib/util.js
@@ -399,6 +399,23 @@ module.exports = {
|
||||
return queryString;
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts Title/Camel case to a space-separated string
|
||||
* @param {*} string - string in snake/camelCase
|
||||
* @returns {string} string
|
||||
*/
|
||||
insertSpacesInName: function (string) {
|
||||
// convert createUser to create User
|
||||
string = string.replace(/([a-z])([A-Z])/g, '$1 $2');
|
||||
|
||||
// convert NASAMission to NASA Mission
|
||||
string = string.replace(/([A-Z])([A-Z][a-z])/g, '$1 $2');
|
||||
|
||||
// convert create_user to create user
|
||||
string = string.replace(/(_)([A-Za-z0-9])/g, ' $2');
|
||||
return string;
|
||||
},
|
||||
|
||||
/**
|
||||
* convert childItem to postman itemGroup if requestCount(no of requests inside childitem)>1
|
||||
* otherwies return postman request
|
||||
@@ -418,7 +435,7 @@ module.exports = {
|
||||
if (resource.requestCount > 1) {
|
||||
// the resource should be a folder
|
||||
itemGroup = new sdk.ItemGroup({
|
||||
name: resource.name
|
||||
name: this.insertSpacesInName(resource.name)
|
||||
// have to add auth here (first auth to be put in the tree)
|
||||
});
|
||||
|
||||
@@ -1054,7 +1071,8 @@ module.exports = {
|
||||
|
||||
switch (this.options.requestNameSource) {
|
||||
case 'fallback' : {
|
||||
reqName = operation.summary || operation.operationId || reqUrl;
|
||||
// operationId is usually camelcase or snake case
|
||||
reqName = operation.summary || this.insertSpacesInName(operation.operationId) || reqUrl;
|
||||
break;
|
||||
}
|
||||
case 'url' : {
|
||||
|
||||
Reference in New Issue
Block a user