[update]: Swagger documentation and responses

This commit is contained in:
VivianDee
2025-03-25 08:52:33 +01:00
parent 3e18c2b1cc
commit 0d87c82e3b
19 changed files with 153 additions and 99 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ Then, open the `.env` file and add the following:
```ini
# Environment Variables
BASIC_AUTH_USERNAME=admin
BASIC_AUTH_USERNAME=user
BASIC_AUTH_PASSWORD=password
SWAGGER_URL="/documentation"
API_URL="/swagger.json"
+7 -7
View File
@@ -3,7 +3,7 @@ from app.api.services import (
EligibilityCheckService,
SelectOfferService,
ProvideLoanService,
LoanInformationService,
LoanStatusService,
RepaymentService,
CustomerConsentService,
NotificationCallbackService
@@ -65,13 +65,13 @@ def provide_loan():
return response
# LoanInformation Endpoint
@api.route('/LoanInformation', methods=['GET'])
# LoanStatus Endpoint
@api.route('/LoanStatus', methods=['POST'])
@require_auth
def loan_information():
data = request.args.to_dict()
# logger.info(f"LoanInformation request received: {data}")
response = LoanInformationService.process_request(data)
def loan_status():
data = request.get_json()
# logger.info(f"LoanStatus request received: {data}")
response = LoanStatusService.process_request(data)
return response
-5
View File
@@ -1,5 +0,0 @@
from marshmallow import Schema, fields
# Loan Information Schema
class LoanInformationSchema(Schema):
loan_id = fields.Str(required=True)
+8
View File
@@ -0,0 +1,8 @@
from marshmallow import Schema, fields
# Loan Information Schema
class LoanStatusSchema(Schema):
transactionId = fields.Str(required=True)
customerId = fields.Str(required=True)
msisdn = fields.Str(required=False)
channel = fields.Str(required=True)
+1 -1
View File
@@ -2,7 +2,7 @@ from marshmallow import Schema, fields
# Provide Loan Schema
class ProvideLoanSchema(Schema):
type = fields.Str(required=True)
type = fields.Str(required=False)
requestId = fields.Str(required=True)
transactionId = fields.Str(required=True)
customerId = fields.Str(required=True)
+1 -1
View File
@@ -1,7 +1,7 @@
from app.api.services.eligibility_check import EligibilityCheckService
from app.api.services.select_offer import SelectOfferService
from app.api.services.provide_loan import ProvideLoanService
from app.api.services.loan_information import LoanInformationService
from app.api.services.loan_status import LoanStatusService
from app.api.services.repayment import RepaymentService
from app.api.services.customer_consent import CustomerConsentService
from app.api.services.notification_callback import NotificationCallbackService
@@ -1,9 +1,9 @@
from flask import request, jsonify
from marshmallow import ValidationError
from app.utils.logger import logger
from app.api.schemas.loan_information import LoanInformationSchema
from app.api.schemas.loan_status import LoanStatusSchema
class LoanInformationService:
class LoanStatusService:
@staticmethod
def process_request(data):
"""
@@ -16,27 +16,31 @@ class LoanInformationService:
dict: A standardized response.
"""
try:
logger.info("Processing LoanInformation request")
logger.info("Processing LoanStatus request")
# Validate input data using the imported schema
schema = LoanInformationSchema()
schema = LoanStatusSchema()
validated_data = schema.load(data) # Raises ValidationError if invalid
loans = [
{
"debtId": "123456789",
"loanDate": "2019-10-18 14:26:21.063",
"dueDate": "2019-11-20 14:26:21.063",
"currentLoanAmount": 8500,
"initialLoanAmount": 10000,
"defaultPenaltyFee": 0,
"continuousFee": 0,
"productId": "101"
}
]
# Simulated processing logic
response_data = {
"customerId": "CN621868",
"loans": [
{
"debtId": "123456789",
"loanDate": "2019-10-18 14:26:21.063",
"dueDate": "2019-11-20 14:26:21.063",
"currentLoanAmount": 8500.0,
"initialLoanAmount": 10000.0,
"defaultFee": 0.0,
"continuousFee": 0.0,
"productId": "101"
}
],
"transactionId": "Tr201712RK9232P115",
"loans": loans,
"totalDebtAmount": 8500,
"resultCode": "00",
"resultDescription": "Successful"
}
+1 -1
View File
@@ -23,7 +23,7 @@ class ProvideLoanService:
validated_data = schema.load(data) # Raises ValidationError if invalid
# Business logic - providing a loan
response_data ={
response_data = {
"requestId": "202111170001371256908",
"transactionId": "Tr201712RK9232P115",
"customerId": "CN621868",
+1 -1
View File
@@ -13,5 +13,5 @@ class Config:
DEBUG = True
VALID_APP_ID = os.getenv("VALID_APP_ID", "app1")
VALID_API_KEY = os.getenv("VALID_API_KEY", "test-api-key-12345")
BASIC_AUTH_USERNAME = os.environ.get("BASIC_AUTH_USERNAME", "admin")
BASIC_AUTH_USERNAME = os.environ.get("BASIC_AUTH_USERNAME", "user")
BASIC_AUTH_PASSWORD = os.environ.get("BASIC_AUTH_PASSWORD", "password")
+7 -7
View File
@@ -44,7 +44,7 @@
}
},
{
"name": "LoanInformation",
"name": "LoanStatus",
"description": "Loan Information Request.",
"externalDocs": {
"description": "Find out more",
@@ -86,8 +86,8 @@
"/ProvideLoan": {
"$ref": "swagger/paths/ProvideLoan.json"
},
"/LoanInformation": {
"$ref": "swagger/paths/LoanInformation.json"
"/LoanStatus": {
"$ref": "swagger/paths/LoanStatus.json"
},
"/Repayment": {
"$ref": "swagger/paths/Repayment.json"
@@ -113,11 +113,11 @@
"SelectOfferResponse": {
"$ref": "swagger/schemas/SelectOfferResponse.json"
},
"LoanInformationRequest": {
"$ref": "swagger/schemas/LoanInformationRequest.json"
"LoanStatusRequest": {
"$ref": "swagger/schemas/LoanStatusRequest.json"
},
"LoanInformationResponse": {
"$ref": "swagger/schemas/LoanInformationResponse.json"
"LoanStatusResponse": {
"$ref": "swagger/schemas/LoanStatusResponse.json"
},
"RepaymentRequest": {
"$ref": "swagger/schemas/RepaymentRequest.json"
@@ -1,27 +1,27 @@
{
"get": {
"post": {
"tags": [
"LoanInformation"
"LoanStatus"
],
"summary": "Loan Information Request ",
"description": "Loan Information Request",
"operationId": "LoanInformation",
"operationId": "LoanStatus",
"requestBody": {
"description": "Post JSON to conduct eligibility tests",
"content": {
"application/json": {
"schema": {
"$ref": "../schemas/LoanInformationRequest.json"
"$ref": "../schemas/LoanStatusRequest.json"
}
},
"application/xml": {
"schema": {
"$ref": "../schemas/LoanInformationRequest.json"
"$ref": "../schemas/LoanStatusRequest.json"
}
},
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "../schemas/LoanInformationRequest.json"
"$ref": "../schemas/LoanStatusRequest.json"
}
}
},
@@ -33,12 +33,12 @@
"content": {
"application/json": {
"schema": {
"$ref": "../schemas/LoanInformationResponse.json"
"$ref": "../schemas/LoanStatusResponse.json"
}
},
"application/xml": {
"schema": {
"$ref": "../schemas/LoanInformationResponse.json"
"$ref": "../schemas/LoanStatusResponse.json"
}
}
}
+5 -5
View File
@@ -11,17 +11,17 @@
"content": {
"application/json": {
"schema": {
"$ref": "../schemas/LoanInformationRequest.json"
"$ref": "../schemas/NotificationCallbackRequest.json"
}
},
"application/xml": {
"schema": {
"$ref": "../schemas/LoanInformationRequest.json"
"$ref": "../schemas/NotificationCallbackRequest.json"
}
},
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "../schemas/LoanInformationRequest.json"
"$ref": "../schemas/NotificationCallbackRequest.json"
}
}
},
@@ -33,12 +33,12 @@
"content": {
"application/json": {
"schema": {
"$ref": "../schemas/LoanInformationResponse.json"
"$ref": "../schemas/NotificationCallbackResponse.json"
}
},
"application/xml": {
"schema": {
"$ref": "../schemas/LoanInformationResponse.json"
"$ref": "../schemas/NotificationCallbackResponse.json"
}
}
}
+5 -5
View File
@@ -11,17 +11,17 @@
"content": {
"application/json": {
"schema": {
"$ref": "../schemas/EligibilityCheckRequest.json"
"$ref": "../schemas/ProvideLoanRequest.json"
}
},
"application/xml": {
"schema": {
"$ref": "../schemas/EligibilityCheckRequest.json"
"$ref": "../schemas/ProvideLoanRequest.json"
}
},
"application/x-www-form-urlencoded": {
"schema": {
"$ref": "../schemas/EligibilityCheckRequest.json"
"$ref": "../schemas/ProvideLoanRequest.json"
}
}
},
@@ -33,12 +33,12 @@
"content": {
"application/json": {
"schema": {
"$ref": "../schemas/EligibilityCheckResponse.json"
"$ref": "../schemas/ProvideLoanResponse.json"
}
},
"application/xml": {
"schema": {
"$ref": "../schemas/EligibilityCheckResponse.json"
"$ref": "../schemas/ProvideLoanResponse.json"
}
}
}
@@ -1,7 +1,7 @@
{
"type": "object",
"properties": {
"$type": {
"type": {
"type": "string",
"example": "CustomerConsentRequest"
},
@@ -1,28 +0,0 @@
{
"type": "object",
"properties": {
"transactionId": {
"type": "string",
"example": "Tr201712RK9232P115"
},
"resultDescription": {
"type": "string",
"example": "Successful"
},
"resultCode": {
"type": "string",
"example": "00"
},
"customerId": {
"type": "string",
"example": "CN621868"
},
"loan": {
"type": "string",
"example": "Arrray of loans"
}
},
"xml": {
"name": "LoanInformationResponse"
}
}
@@ -5,10 +5,6 @@
"type": "string",
"example": "Tr201712RK9232P115"
},
"resultDescription": {
"type": "string",
"example": "Successful"
},
"customerId": {
"type": "string",
"example": "CN621868"
@@ -23,6 +19,6 @@
}
},
"xml": {
"name": "LoanInformationRequest"
"name": "LoanStatusRequest"
}
}
@@ -0,0 +1,70 @@
{
"type": "object",
"properties": {
"customerId": {
"type": "string",
"example": "CN621868"
},
"transactionId": {
"type": "string",
"example": "Tr201712RK9232P115"
},
"loans": {
"type": "array",
"items": {
"type": "object",
"properties": {
"debtId": {
"type": "string",
"example": "123456789"
},
"loanDate": {
"type": "string",
"format": "date-time",
"example": "2019-10-18 14:26:21.063"
},
"dueDate": {
"type": "string",
"format": "date-time",
"example": "2019-11-20 14:26:21.063"
},
"currentLoanAmount": {
"type": "integer",
"example": 8500
},
"initialLoanAmount": {
"type": "integer",
"example": 10000
},
"defaultPenaltyFee": {
"type": "integer",
"example": 0
},
"continuousFee": {
"type": "integer",
"example": 0
},
"productId": {
"type": "string",
"example": "101"
}
}
}
},
"totalDebtAmount": {
"type": "integer",
"example": 8500
},
"resultCode": {
"type": "string",
"example": "00"
},
"resultDescription": {
"type": "string",
"example": "Successful"
}
},
"xml": {
"name": "LoanStatusResponse"
}
}
+15 -6
View File
@@ -1,26 +1,35 @@
{
"type": "object",
"properties": {
"transactionId": {
"requestId": {
"type": "string",
"example": "202111170001371256908"
},
"accountId": {
"transactionId": {
"type": "string",
"example": "ACN8263457"
"example": "Tr201712RK9232P115"
},
"customerId": {
"type": "string",
"example": "CN621868"
},
"accountId": {
"type": "string",
"example": "ACN8263457"
},
"msisdn": {
"type": "string",
"example": "9012345678"
"example": "3451342"
},
"productId": {
"type": "string",
"example": "101"
},
"lienAmount": {
"type": "number",
"format": "decimal",
"example": 400
},
"requestedAmount": {
"type": "number",
"format": "decimal",
@@ -30,13 +39,13 @@
"type": "integer",
"example": 1
},
"offerID": {
"loanType": {
"type": "integer",
"example": 0
},
"channel": {
"type": "string",
"example": "100"
"example": "USSD"
}
},
"xml": {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"type": "object",
"properties": {
"$type": {
"type": {
"type": "string",
"example": "RepaymentRequest"
},