Skip to content

Commit

Permalink
feat: generate jans-config-api client from multiple swagger specs #426
Browse files Browse the repository at this point in the history
  • Loading branch information
duttarnab committed Sep 12, 2022
1 parent d323076 commit bc2b602
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 2 deletions.
14 changes: 14 additions & 0 deletions admin-ui/openapi-merge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"inputs": [
{
"inputURL": "https://raw.githubusercontent.com/JanssenProject/jans/main/jans-config-api/docs/jans-config-api-swagger-auto.yaml"
},
{
"inputURL": "https://raw.githubusercontent.com/JanssenProject/jans/main/jans-config-api/plugins/docs/jans-admin-ui-plugin-swagger.yaml"
},
{
"inputURL": "https://raw.githubusercontent.com/JanssenProject/jans/main/jans-config-api/plugins/docs/user-mgt-plugin-swagger.yaml"
}
],
"output": "./configApiSpecs.yaml"
}
4 changes: 2 additions & 2 deletions admin-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"start:dev": "node ./build/cli-tools.js --clear dist --create dist && webpack serve --config ./build/webpack.config.client.dev.js",
"start:prod": "node ./build/cli-tools.js --clear dist --create dist && webpack-dev-server --config ./build/webpack.config.client.prod.js",
"lint": "eslint app/ --ext .js,jsx --fix",
"api": "rm -rf jans_config_api && openapi-generator-cli generate -i https://raw.githubusercontent.com/JanssenProject/jans/main/jans-config-api/docs/jans-config-api-swagger.yaml --skip-validate-spec -g javascript -o jans_config_api && cd jans_config_api && npm install && npm run build",
"api-win": "del /f jans_config_api && openapi-generator-cli generate -i https://raw.githubusercontent.com/JanssenProject/jans/main/jans-config-api/docs/jans-config-api-swagger.yaml -g javascript -o jans_config_api && cd jans_config_api && npm install && npm run build",
"api": "rm -rf jans_config_api && openapi-merge-cli && openapi-generator-cli generate -i ./configApiSpecs.yaml --skip-validate-spec -g javascript -o jans_config_api && cd jans_config_api && npm install && npm run build",
"api-win": "del /f jans_config_api && openapi-merge-cli && openapi-generator-cli generate -i ./configApiSpecs.yaml -g javascript -o jans_config_api && cd jans_config_api && npm install && npm run build",
"plugin:showAll": "node ./build/plugin-cli.js --showAllPlugins",
"plugin:add": "node ./build/plugin-cli.js --addPlugin",
"plugin:remove": "node ./build/plugin-cli.js --removePlugin",
Expand Down
41 changes: 41 additions & 0 deletions admin-ui/plugins/admin/components/Mapping/MappingApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class MappingApi {
constructor(api) {
this.api = api
}
getMappings = () => {
return new Promise((resolve, reject) => {
this.api.getAdminuiRolePermissions((error, data) => {
handleResponse(error, reject, resolve, data)
})
})
}

updateMapping = (data) => {
const options = {}
options['rolePermissionMapping'] = data
return new Promise((resolve, reject) => {
this.api.mapPermissionsToRole(options, (error, options) => {
handleResponse(error, reject, resolve, data)
})
})
}

addMapping = (data) => {
const options = {}
options['rolePermissionMapping'] = data
return new Promise((resolve, reject) => {
this.api.mapPermissionsToRole(options, (error, options) => {
handleResponse(error, reject, resolve, data)
})
})
}
deleteMapping = (data) => {
return new Promise((resolve, reject) => {
this.api.removeRolePermissionsPermission(data.role, (error, options) => {
handleResponse(error, reject, resolve, data)
})
})
}
}
42 changes: 42 additions & 0 deletions admin-ui/plugins/admin/components/Permissions/PermissionApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class PermissionApi {
constructor(api) {
this.api = api
}
getPermissions = () => {
return new Promise((resolve, reject) => {
this.api.getAdminuiPermissions((error, data) => {
handleResponse(error, reject, resolve, data)
})
})
}

addPermission = (data) => {
const options = {}
options['adminPermission'] = data
return new Promise((resolve, reject) => {
this.api.addAdminuiPermission(options, (error, data) => {
handleResponse(error, reject, resolve, data)
})
})
}

editPermission = (data) => {
const options = {}
options['adminPermission'] = data
return new Promise((resolve, reject) => {
this.api.editAdminuiPermission(options, (error, data) => {
handleResponse(error, reject, resolve, data)
})
})
}

deletePermission = async (data) => {
return new Promise((resolve, reject) => {
this.api.deleteAdminuiPermission(data.permission, (error, data) => {
handleResponse(error, reject, resolve, data)
})
})
}
}
42 changes: 42 additions & 0 deletions admin-ui/plugins/admin/components/Roles/RoleApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class RoleApi {
constructor(api) {
this.api = api
}
getRoles = () => {
return new Promise((resolve, reject) => {
this.api.getAdminuiRoles((error, data) => {
handleResponse(error, reject, resolve, data)
})
})
}

addRole = (data) => {
const options = {}
options['adminRole'] = data
return new Promise((resolve, reject) => {
this.api.addAdminuiRole(options, (error, data) => {
handleResponse(error, reject, resolve, data)
})
})
}

editRole = (data) => {
const options = {}
options['adminRole'] = data
return new Promise((resolve, reject) => {
this.api.editAdminuiRole(options, (error, data) => {
handleResponse(error, reject, resolve, data)
})
})
}

deleteRole = async (data) => {
return new Promise((resolve, reject) => {
this.api.deleteAdminuiRole(data.role, (error, data) => {
handleResponse(error, reject, resolve, data)
})
})
}
}

0 comments on commit bc2b602

Please sign in to comment.