-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added new api provisioning functionality * Add unit tests * Changed the UI version in docker-compose file * Postponed the audits * Added documentation for provisioning new API * Changed some docs
- Loading branch information
Showing
20 changed files
with
16,572 additions
and
16,044 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Mojaloop Testing Toolkit | ||
|
||
## _API Provisioning_ | ||
|
||
**Table of Contents** | ||
|
||
1. [Overview](#1-overview) | ||
|
||
2. [Synchronous API](#1-synchronous-api) | ||
|
||
3. [Asynchronous API](#2-asynchronous-api) | ||
|
||
4. [Provisioning through UI](#3-api-provisioning-through-ui) | ||
|
||
|
||
## 1. Overview | ||
|
||
The Testing Toolkit is highly configurable and any API can be provisioned into TTK easily. | ||
TTK supports two kinds of APIs | ||
|
||
* Synchronous API | ||
* Asynchronous API | ||
|
||
## 2. Synchronous API | ||
|
||
You just need to provide the **Swagger / OpenAPI** specification file of your synchronous API to the TTK. | ||
|
||
- Please copy the specification file in yaml format into the following folder | ||
``` | ||
spec_files/<your-api-folder-name>/api_spec.yaml | ||
``` | ||
- Add a new entry to the property **API_DEFINITIONS** in _spec_files/system_config.json_ | ||
``` | ||
{ | ||
"type": "<your-api-name>", | ||
"version": "<major_version.minor_version", | ||
"folderPath": "<your-api-folder-name>" | ||
} | ||
``` | ||
- Restart the testing toolkit service and that's it. You are all set. | ||
|
||
You should be able to send your API requests to TTK and the TTK will validate them against the specification. You can monitor them in the TTK UI. | ||
|
||
And also you can go ahead to create your own response rules to get customized responses from TTK through TTK UI. | ||
|
||
## 3. Asynchronous API | ||
|
||
You should follow the same procedure as Synchronous API and some additional steps are there to provision an Asynchronous API. | ||
|
||
- Please copy the specification file in yaml format into the following file | ||
``` | ||
spec_files/<your-api-folder-name>/api_spec.yaml | ||
``` | ||
- Add a new entry to the property **API_DEFINITIONS** in _spec_files/system_config.json_. Please observe the additional _asynchronous_ flag here. | ||
``` | ||
{ | ||
"type": "<your-api-name>", | ||
"version": "<major_version.minor_version", | ||
"folderPath": "<your-api-folder-name>", | ||
"asynchronous": true | ||
} | ||
``` | ||
- Additionally you should provide some information about callback mappings to associate the asynchronous callbacks to the respective requests. You can add that information into the following file. You can refer the sample files provided for FSPIOP api in the repository. | ||
``` | ||
spec_files/<your-api-folder-name>/callback_map.json | ||
``` | ||
- Restart the testing toolkit service and that's it. You are all set. | ||
|
||
You should be able to send your API requests to TTK and the TTK will validate them against the specification. You can monitor them in the TTK UI. | ||
|
||
And also you can go ahead to create your own validation rules, callback rules and response rules to get customized / mock callbacks and responses from TTK through TTK UI. | ||
|
||
## 4. Provisioning through UI | ||
|
||
 | ||
|
||
- You can go to _**API Management**_ navigation tab. Below is the default view of this API Management page. | ||
|
||
 | ||
|
||
- Click on **Add new API** button, a popup window will be opened and you should drag / select your API specification yaml file there. | ||
|
||
 | ||
|
||
- After your file is been processed and validated by TTK, you can find the information about your API in the window. You can verify the details and change the name and other details populated there. | ||
|
||
 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/***** | ||
License | ||
-------------- | ||
Copyright © 2017 Bill & Melinda Gates Foundation | ||
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
Contributors | ||
-------------- | ||
This is the official list of the Mojaloop project contributors for this file. | ||
Names of the original copyright holders (individuals or organizations) | ||
should be listed with a '*' in the first column. People who have | ||
contributed from an organization can be listed under the organization | ||
that actually holds the copyright for their contributions (see the | ||
Gates Foundation organization for an example). Those individuals should have | ||
their names indented and be marked with a '-'. Email address can be added | ||
optionally within square brackets <email>. | ||
* Gates Foundation | ||
* ModusBox | ||
* Vijaya Kumar Guthi <[email protected]> (Original Author) | ||
-------------- | ||
******/ | ||
|
||
const OpenApiBackend = require('openapi-backend').default | ||
const Utils = require('./utils') | ||
const path = require('path') | ||
const Config = require('./config') | ||
const OpenApiDefinitionsModel = require('./mocking/openApiDefinitionsModel') | ||
const OpenApiMockHandler = require('./mocking/openApiMockHandler') | ||
|
||
const apiDefinitionsPath = 'spec_files/api_definitions/' | ||
|
||
const validateDefinition = async (apiFilePath) => { | ||
const newApi = new OpenApiBackend({ | ||
definition: path.join(apiFilePath), | ||
strict: true, | ||
quick: true | ||
}) | ||
await newApi.loadDocument() | ||
newApi.validateDefinition() | ||
return newApi.document | ||
} | ||
|
||
const addDefinition = async (apiFilePath, name, version, asynchronous) => { | ||
// Validate the definition first | ||
await validateDefinition(apiFilePath) | ||
// Create a folder with api name and copy the uploaded file there | ||
await Utils.makeDirectoryAsync(apiDefinitionsPath + name) | ||
await Utils.renameFileAsync(apiFilePath, apiDefinitionsPath + name + '/api_spec.yaml') | ||
// Add the entry to system config | ||
const apiDefinitions = Config.getSystemConfig().API_DEFINITIONS | ||
apiDefinitions.push({ | ||
type: name, | ||
version, | ||
folderPath: name, | ||
asynchronous: asynchronous === 'true' || asynchronous === 'TRUE', | ||
additionalApi: true | ||
}) | ||
await Config.setSystemConfig({ API_DEFINITIONS: apiDefinitions }) | ||
|
||
// Reload the opneapi definitions model | ||
await OpenApiDefinitionsModel.refreshApiDefinitions() | ||
|
||
// Reload the openapimock handlers | ||
OpenApiMockHandler.initilizeMockHandler() | ||
} | ||
|
||
const deleteDefinition = async (name, version) => { | ||
// Make sure the requested API is not an inbuilt API | ||
const apiDefinitions = Config.getSystemConfig().API_DEFINITIONS | ||
const matchedApiIndex = apiDefinitions.findIndex(item => { | ||
return item.type === name && item.version === version | ||
}) | ||
|
||
if (matchedApiIndex === -1) { | ||
throw new Error('Requested API is not found') | ||
} | ||
const matchedApi = apiDefinitions[matchedApiIndex] | ||
if (!matchedApi.additionalApi) { | ||
throw new Error('Requested API is an inbuilt API and can not be deleted') | ||
} | ||
|
||
// Remove entry in system config file | ||
apiDefinitions.splice(matchedApiIndex, 1) | ||
await Config.setSystemConfig({ API_DEFINITIONS: apiDefinitions }) | ||
|
||
// Remove the folder from spec_files | ||
await Utils.rmdirAsync(apiDefinitionsPath + name, { recursive: true }) | ||
|
||
// Refresh openapi Definitions | ||
await OpenApiDefinitionsModel.refreshApiDefinitions() | ||
|
||
// Reload the openapimock handlers | ||
OpenApiMockHandler.initilizeMockHandler() | ||
|
||
return true | ||
} | ||
|
||
module.exports = { | ||
validateDefinition, | ||
addDefinition, | ||
deleteDefinition | ||
} |
Oops, something went wrong.