This is a guide for adding the test target API path or functions that the user wants.
The CQA Test App uses the flask library and is easy to modify.
Please refer to the guide below when adding and modifying the code required for the test :)
## A. How to Add Basic API
1. Add 'app.route' for adding basic API path in "run_cqa_test_app.py"
- As in the example below, Add 'app.route' annotation for adding API path
- format : @app.route({api_path}, methods=[{method name}]
- API Path cannot duplicate an existing path.
2. Add 'method' to the line below 'app.route' annotation.
- Add api method after adding 'app.route'
- A method name must not overlap with another method name.
- Add "api_function.make_common_response" to return to complete basic API addition.
- make_common_response is a method that returns a basic response.
- ex : `{"client":"127.0.0.1","code":200,"host":"localhost:10345","method":"GET","msg":"Test OK","path":"/example"}`
## B. How to Add API with function
1. First, refer to the 'How to Add Basic API' guide to add the desired API path and method.
- Add 'app.route' and api method for adding basic API interface
- ref : [How To Add Basic API](https://git.linecorp.com/Cloud-QA/cqa-test-app/wiki/3.-How-to-Add-API-&-Function-for-CQA-Test-App#a-how-to-add-basic-api)
2. Add API Function method to implement additional function
- Add your function method in "functions/APIFunctions.py"
- Implement codes in the method that your logics to running on CQA Test App
- example code is just run 'df' command & return result
3. Add Code call API Function on added new api method
- Call "the function method" added in the api method like below.
- Then, when the api is called, the function works.
## C. How to Add Swagger API spec
In order to connect the added API to swagger ui, it is necessary to add API Spec.
1. Add new API's spec on 'resources/swagger_api_spec.json'
- Write API specs by referencing or copying other existing API spec formats.
- API path and method must be written according to the added API on code.
2. Check if new API Spec is well applied to Swagger UI on CQA Test App.
- After add new API spec, Run CQA Test App server.
- Access '/swagger' and Check new API spec is applied to UI
- In local, You can access swagger through 'http://localhost:10345/swagger'
### References
For more detailed information on API implementation and specification writing, refer to the documents below.
- Flask Document : https://flask.palletsprojects.com/en/2.3.x/#user-s-guide
- Swagger API Spec : https://swagger.io/specification/