Tried to add new function in the Widdershins openapi3.js file without success

In the JSON file that defines a REST API, there is the following code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>"keycloak": [
"RequestRelay#relay",
"Account#read",
"Account#write"
]
</code>
<code>"keycloak": [ "RequestRelay#relay", "Account#read", "Account#write" ] </code>
"keycloak": [
"RequestRelay#relay",
"Account#read",
"Account#write"
]

I have successfully modified the getAuthenticationStr function in the widdershins openapi.js script so that it splits the permissions part of the keycloak properties from the resource part.

This rewrite is as follows:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>function getAuthenticationStr(data) {
let list = '';
for (let s in data.security) {
let count = 0;
for (let sse in Object.keys(data.security[s])) {
let secName = Object.keys(data.security[s])[sse];
let link = '#/components/securitySchemes/' + secName;
let secDef = jptr(data.api, link);
let sep = (count > 0) ? ' & ' : ', ';
list += (list ? sep : '') /* + (secDef ? secName : data.translations.secDefNone) */ ;
let scopes = data.security[s][secName];
if (Array.isArray(scopes) && (scopes.length > 0)) {
let i = scopes.length;
for (let i = scopes.length -1; i >= 0 ; i-- ) {
let gerbil = scopes[i];
const permission = gerbil.split("#");
let j = 1;
console.log(permission[j]);
let k = 0;
/* list += '' + data.translations.secDefScopes + '';
for (let scope in scopes) {
list += permission[j] + ''; */
if (i > 1) {
list += permission[j] + ', ';
}
if (i == 1) {
list += permission[j] + ' and ';
}
if (i == 0) {
list += permission[j] + '';
}
}
}
list += '';
}
count++;
}
/* if (count === 0) { // 'null' security
list += (list ? ', ' : '') + data.translations.secDefNone;
} */
return list;
}
</code>
<code>function getAuthenticationStr(data) { let list = ''; for (let s in data.security) { let count = 0; for (let sse in Object.keys(data.security[s])) { let secName = Object.keys(data.security[s])[sse]; let link = '#/components/securitySchemes/' + secName; let secDef = jptr(data.api, link); let sep = (count > 0) ? ' & ' : ', '; list += (list ? sep : '') /* + (secDef ? secName : data.translations.secDefNone) */ ; let scopes = data.security[s][secName]; if (Array.isArray(scopes) && (scopes.length > 0)) { let i = scopes.length; for (let i = scopes.length -1; i >= 0 ; i-- ) { let gerbil = scopes[i]; const permission = gerbil.split("#"); let j = 1; console.log(permission[j]); let k = 0; /* list += '' + data.translations.secDefScopes + ''; for (let scope in scopes) { list += permission[j] + ''; */ if (i > 1) { list += permission[j] + ', '; } if (i == 1) { list += permission[j] + ' and '; } if (i == 0) { list += permission[j] + ''; } } } list += ''; } count++; } /* if (count === 0) { // 'null' security list += (list ? ', ' : '') + data.translations.secDefNone; } */ return list; } </code>
function getAuthenticationStr(data) {
    let list = '';
    for (let s in data.security) {
        let count = 0;
        for (let sse in Object.keys(data.security[s])) {
            let secName = Object.keys(data.security[s])[sse];           
            let link = '#/components/securitySchemes/' + secName;
            let secDef = jptr(data.api, link);          
            let sep = (count > 0) ? ' & ' : ', '; 
            list += (list ? sep : '') /* + (secDef ? secName : data.translations.secDefNone) */ ;
            let scopes = data.security[s][secName];
            if (Array.isArray(scopes) && (scopes.length > 0)) {
                
                let i = scopes.length;
                
                for (let i = scopes.length -1; i >= 0 ; i-- )  {
                    
                    let gerbil = scopes[i];             
                    const permission = gerbil.split("#");
                    let j = 1;
                    console.log(permission[j]);
                    let k = 0;
/*                  list += '' + data.translations.secDefScopes + '';
                    for (let scope in scopes) {
                        list += permission[j] + ''; */
                        
                    if (i > 1) { 
                    list += permission[j] + ', ';
                    }

                    if (i == 1) { 
                    list += permission[j] + ' and ';
                    }

                    if (i == 0) { 
                    list += permission[j] + '';
                    }
                    
                
                  }
                }
                list += '';
            }
            count++;
        }
/*        if (count === 0) { // 'null' security
            list += (list ? ', ' : '') + data.translations.secDefNone;
        } */
    
    return list;
}

This function is called by the authentication.def file when widdershins is run and the permissions display properly in the markdown file. This is the string in the authentication.def file that calls the function:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>{{= data.utils.getAuthenticationStr(data)}}
</code>
<code>{{= data.utils.getAuthenticationStr(data)}} </code>
{{= data.utils.getAuthenticationStr(data)}}

I would to add a new function – almost identical to the one above – that inserts the names of the Keycloak resources into the markdown file.

To do this, I added the following code to openapi3.js:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>function getResourcessStr(data) {
let list = '';
for (let s in data.security) {
let count = 0;
for (let sse in Object.keys(data.security[s])) {
let secName = Object.keys(data.security[s])[sse];
let link = '#/components/securitySchemes/' + secName;
let secDef = jptr(data.api, link);
/* let sep = (count > 0) ? ' & ' : ', '; */
let sep = (count > 0) ? ' & ' : ', ';
list += (list ? sep : '') /* + (secDef ? secName : data.translations.secDefNone) */ ;
let scopes = data.security[s][secName];
/* const gerbil = scopes.split("#");
let permission = gerbil[1];
console.log(scopes); */
if (Array.isArray(scopes) && (scopes.length > 0)) {
let i = scopes.length;
for (let i = scopes.length -1; i >= 0 ; i-- ) {
let gerbil = scopes[i];
const permission = gerbil.split("#");
let j = 1;
console.log(permission[j]);
let k = 0;
/* list += '' + data.translations.secDefScopes + '';
for (let scope in scopes) {
list += permission[j] + ''; */
if (i > 1) {
list += permission[k] + ', ';
}
if (i == 1) {
list += permission[k] + ' and ';
}
if (i == 0) {
list += permission[k] + '';
}
}
}
list += '';
}
count++;
}
/* if (count === 0) { // 'null' security
list += (list ? ', ' : '') + data.translations.secDefNone;
} */
return list;
}
</code>
<code>function getResourcessStr(data) { let list = ''; for (let s in data.security) { let count = 0; for (let sse in Object.keys(data.security[s])) { let secName = Object.keys(data.security[s])[sse]; let link = '#/components/securitySchemes/' + secName; let secDef = jptr(data.api, link); /* let sep = (count > 0) ? ' & ' : ', '; */ let sep = (count > 0) ? ' & ' : ', '; list += (list ? sep : '') /* + (secDef ? secName : data.translations.secDefNone) */ ; let scopes = data.security[s][secName]; /* const gerbil = scopes.split("#"); let permission = gerbil[1]; console.log(scopes); */ if (Array.isArray(scopes) && (scopes.length > 0)) { let i = scopes.length; for (let i = scopes.length -1; i >= 0 ; i-- ) { let gerbil = scopes[i]; const permission = gerbil.split("#"); let j = 1; console.log(permission[j]); let k = 0; /* list += '' + data.translations.secDefScopes + ''; for (let scope in scopes) { list += permission[j] + ''; */ if (i > 1) { list += permission[k] + ', '; } if (i == 1) { list += permission[k] + ' and '; } if (i == 0) { list += permission[k] + ''; } } } list += ''; } count++; } /* if (count === 0) { // 'null' security list += (list ? ', ' : '') + data.translations.secDefNone; } */ return list; } </code>
function getResourcessStr(data) {
    let list = '';
    for (let s in data.security) {
        let count = 0;
        for (let sse in Object.keys(data.security[s])) {
            let secName = Object.keys(data.security[s])[sse];           
            let link = '#/components/securitySchemes/' + secName;
            let secDef = jptr(data.api, link);          
/*          let sep = (count > 0) ? ' & ' : ', '; */
            let sep = (count > 0) ? ' & ' : ', '; 
            list += (list ? sep : '') /* + (secDef ? secName : data.translations.secDefNone) */ ;
            let scopes = data.security[s][secName];
/*          const gerbil = scopes.split("#");
            let permission = gerbil[1]; 
            console.log(scopes);  */
            if (Array.isArray(scopes) && (scopes.length > 0)) {
                
                let i = scopes.length;
                
                for (let i = scopes.length -1; i >= 0 ; i-- )  {
                    
                    let gerbil = scopes[i];             
                    const permission = gerbil.split("#");
                    let j = 1;
                    console.log(permission[j]);
                    let k = 0;
/*                  list += '' + data.translations.secDefScopes + '';
                    for (let scope in scopes) {
                        list += permission[j] + ''; */
                        
                    if (i > 1) { 
                    list += permission[k] + ', ';
                    }

                    if (i == 1) { 
                    list += permission[k] + ' and ';
                    }

                    if (i == 0) { 
                    list += permission[k] + '';
                    }
                    
                
                  }
                }
                list += '';
            }
            count++;
        }
/*        if (count === 0) { // 'null' security
            list += (list ? ', ' : '') + data.translations.secDefNone;
        } */
    
    return list;
}

I also redefined the authentication.def file as follows:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>**Required Keycloak resource permission**
This endpoint requires the {{= data.utils.getAuthenticationStr(data)}} <a href="https://doc.wyden.io/docs/configuring_AT_accounts#creating-a-permission-and-applying-it-to-a-group-policy">scope permission(s)</a> on, respectively, the {{= data.utils.getResourcessStr(data)}} <a href="https://doc.wyden.io/docs/configuring_AT_accounts#resource">resource(s)</a>.
</code>
<code>**Required Keycloak resource permission** This endpoint requires the {{= data.utils.getAuthenticationStr(data)}} <a href="https://doc.wyden.io/docs/configuring_AT_accounts#creating-a-permission-and-applying-it-to-a-group-policy">scope permission(s)</a> on, respectively, the {{= data.utils.getResourcessStr(data)}} <a href="https://doc.wyden.io/docs/configuring_AT_accounts#resource">resource(s)</a>. </code>
**Required Keycloak resource permission**

This endpoint requires the {{= data.utils.getAuthenticationStr(data)}} <a href="https://doc.wyden.io/docs/configuring_AT_accounts#creating-a-permission-and-applying-it-to-a-group-policy">scope permission(s)</a> on, respectively, the {{= data.utils.getResourcessStr(data)}} <a href="https://doc.wyden.io/docs/configuring_AT_accounts#resource">resource(s)</a>.

When I added the new function – getResourcessStr – however, and then ran widdershins, the following message was displayed:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>TypeError: data.utils.getResourcessStr is not a function
at Object.eval [as operation] (eval at doT.template (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinsnode_modulesdotdoT.js:133:11), <anonymous>:3:7933)
at Object.eval [as main] (eval at doT.template (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinsnode_modulesdotdoT.js:133:11), <anonymous>:3:3805)
at C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibopenapi3.js:801:34
at new Promise (<anonymous>)
at convertInner (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibopenapi3.js:690:12)
at Object.convert (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibopenapi3.js:827:16)
at Object.convert (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibindex.js:20:25)
at doit (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinswiddershins.js:115:38)
at Object.<anonymous> (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinswiddershins.js:212:5)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
</code>
<code>TypeError: data.utils.getResourcessStr is not a function at Object.eval [as operation] (eval at doT.template (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinsnode_modulesdotdoT.js:133:11), <anonymous>:3:7933) at Object.eval [as main] (eval at doT.template (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinsnode_modulesdotdoT.js:133:11), <anonymous>:3:3805) at C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibopenapi3.js:801:34 at new Promise (<anonymous>) at convertInner (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibopenapi3.js:690:12) at Object.convert (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibopenapi3.js:827:16) at Object.convert (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibindex.js:20:25) at doit (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinswiddershins.js:115:38) at Object.<anonymous> (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinswiddershins.js:212:5) at Module._compile (node:internal/modules/cjs/loader:1369:14) </code>
TypeError: data.utils.getResourcessStr is not a function
    at Object.eval [as operation] (eval at doT.template (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinsnode_modulesdotdoT.js:133:11), <anonymous>:3:7933)
    at Object.eval [as main] (eval at doT.template (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinsnode_modulesdotdoT.js:133:11), <anonymous>:3:3805)
    at C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibopenapi3.js:801:34
    at new Promise (<anonymous>)
    at convertInner (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibopenapi3.js:690:12)
    at Object.convert (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibopenapi3.js:827:16)
    at Object.convert (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinslibindex.js:20:25)
    at doit (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinswiddershins.js:115:38)
    at Object.<anonymous> (C:UsersKevinDonovanAppDataRoamingnpmnode_moduleswiddershinswiddershins.js:212:5)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)

After running widdershins, I was expecting a markdown file with text such as the following:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>**Required Keycloak resource permission**
This endpoint requires the write, read and relay <a href="https://doc.wyden.io/docs/configuring_AT_accounts#creating-a-permission-and-applying-it-to-a-group-policy">scope permission(s)</a> on, respectively, the Account, Account and RequestRelay <a href="https://doc.wyden.io/docs/configuring_AT_accounts#resource">resource(s)</a>.
</code>
<code>**Required Keycloak resource permission** This endpoint requires the write, read and relay <a href="https://doc.wyden.io/docs/configuring_AT_accounts#creating-a-permission-and-applying-it-to-a-group-policy">scope permission(s)</a> on, respectively, the Account, Account and RequestRelay <a href="https://doc.wyden.io/docs/configuring_AT_accounts#resource">resource(s)</a>. </code>
**Required Keycloak resource permission**

This endpoint requires the write, read and relay <a href="https://doc.wyden.io/docs/configuring_AT_accounts#creating-a-permission-and-applying-it-to-a-group-policy">scope permission(s)</a> on, respectively, the Account, Account and RequestRelay <a href="https://doc.wyden.io/docs/configuring_AT_accounts#resource">resource(s)</a>.

Does anyone know what to do to add a function successfully to widdershins? Thanks!

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật