In the JSON file that defines a REST API, there is the following 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:
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:
{{= 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:
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:
**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:
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:
**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