[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 ```ini
# Environment Variables # Environment Variables
BASIC_AUTH_USERNAME=admin BASIC_AUTH_USERNAME=user
BASIC_AUTH_PASSWORD=password BASIC_AUTH_PASSWORD=password
SWAGGER_URL="/documentation" SWAGGER_URL="/documentation"
API_URL="/swagger.json" API_URL="/swagger.json"
+7 -7
View File
@@ -3,7 +3,7 @@ from app.api.services import (
EligibilityCheckService, EligibilityCheckService,
SelectOfferService, SelectOfferService,
ProvideLoanService, ProvideLoanService,
LoanInformationService, LoanStatusService,
RepaymentService, RepaymentService,
CustomerConsentService, CustomerConsentService,
NotificationCallbackService NotificationCallbackService
@@ -65,13 +65,13 @@ def provide_loan():
return response return response
# LoanInformation Endpoint # LoanStatus Endpoint
@api.route('/LoanInformation', methods=['GET']) @api.route('/LoanStatus', methods=['POST'])
@require_auth @require_auth
def loan_information(): def loan_status():
data = request.args.to_dict() data = request.get_json()
# logger.info(f"LoanInformation request received: {data}") # logger.info(f"LoanStatus request received: {data}")
response = LoanInformationService.process_request(data) response = LoanStatusService.process_request(data)
return response 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 # Provide Loan Schema
class ProvideLoanSchema(Schema): class ProvideLoanSchema(Schema):
type = fields.Str(required=True) type = fields.Str(required=False)
requestId = fields.Str(required=True) requestId = fields.Str(required=True)
transactionId = fields.Str(required=True) transactionId = fields.Str(required=True)
customerId = 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.eligibility_check import EligibilityCheckService
from app.api.services.select_offer import SelectOfferService from app.api.services.select_offer import SelectOfferService
from app.api.services.provide_loan import ProvideLoanService 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.repayment import RepaymentService
from app.api.services.customer_consent import CustomerConsentService from app.api.services.customer_consent import CustomerConsentService
from app.api.services.notification_callback import NotificationCallbackService from app.api.services.notification_callback import NotificationCallbackService
@@ -1,9 +1,9 @@
from flask import request, jsonify from flask import request, jsonify
from marshmallow import ValidationError from marshmallow import ValidationError
from app.utils.logger import logger 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 @staticmethod
def process_request(data): def process_request(data):
""" """
@@ -16,27 +16,31 @@ class LoanInformationService:
dict: A standardized response. dict: A standardized response.
""" """
try: try:
logger.info("Processing LoanInformation request") logger.info("Processing LoanStatus request")
# Validate input data using the imported schema # Validate input data using the imported schema
schema = LoanInformationSchema() schema = LoanStatusSchema()
validated_data = schema.load(data) # Raises ValidationError if invalid 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 # Simulated processing logic
response_data = { response_data = {
"customerId": "CN621868", "customerId": "CN621868",
"loans": [ "transactionId": "Tr201712RK9232P115",
{ "loans": loans,
"debtId": "123456789", "totalDebtAmount": 8500,
"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"
}
],
"resultCode": "00", "resultCode": "00",
"resultDescription": "Successful" "resultDescription": "Successful"
} }
+1 -1
View File
@@ -23,7 +23,7 @@ class ProvideLoanService:
validated_data = schema.load(data) # Raises ValidationError if invalid validated_data = schema.load(data) # Raises ValidationError if invalid
# Business logic - providing a loan # Business logic - providing a loan
response_data ={ response_data = {
"requestId": "202111170001371256908", "requestId": "202111170001371256908",
"transactionId": "Tr201712RK9232P115", "transactionId": "Tr201712RK9232P115",
"customerId": "CN621868", "customerId": "CN621868",
+1 -1
View File
@@ -13,5 +13,5 @@ class Config:
DEBUG = True DEBUG = True
VALID_APP_ID = os.getenv("VALID_APP_ID", "app1") VALID_APP_ID = os.getenv("VALID_APP_ID", "app1")
VALID_API_KEY = os.getenv("VALID_API_KEY", "test-api-key-12345") 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") 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.", "description": "Loan Information Request.",
"externalDocs": { "externalDocs": {
"description": "Find out more", "description": "Find out more",
@@ -86,8 +86,8 @@
"/ProvideLoan": { "/ProvideLoan": {
"$ref": "swagger/paths/ProvideLoan.json" "$ref": "swagger/paths/ProvideLoan.json"
}, },
"/LoanInformation": { "/LoanStatus": {
"$ref": "swagger/paths/LoanInformation.json" "$ref": "swagger/paths/LoanStatus.json"
}, },
"/Repayment": { "/Repayment": {
"$ref": "swagger/paths/Repayment.json" "$ref": "swagger/paths/Repayment.json"
@@ -113,11 +113,11 @@
"SelectOfferResponse": { "SelectOfferResponse": {
"$ref": "swagger/schemas/SelectOfferResponse.json" "$ref": "swagger/schemas/SelectOfferResponse.json"
}, },
"LoanInformationRequest": { "LoanStatusRequest": {
"$ref": "swagger/schemas/LoanInformationRequest.json" "$ref": "swagger/schemas/LoanStatusRequest.json"
}, },
"LoanInformationResponse": { "LoanStatusResponse": {
"$ref": "swagger/schemas/LoanInformationResponse.json" "$ref": "swagger/schemas/LoanStatusResponse.json"
}, },
"RepaymentRequest": { "RepaymentRequest": {
"$ref": "swagger/schemas/RepaymentRequest.json" "$ref": "swagger/schemas/RepaymentRequest.json"
@@ -1,27 +1,27 @@
{ {
"get": { "post": {
"tags": [ "tags": [
"LoanInformation" "LoanStatus"
], ],
"summary": "Loan Information Request ", "summary": "Loan Information Request ",
"description": "Loan Information Request", "description": "Loan Information Request",
"operationId": "LoanInformation", "operationId": "LoanStatus",
"requestBody": { "requestBody": {
"description": "Post JSON to conduct eligibility tests", "description": "Post JSON to conduct eligibility tests",
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "../schemas/LoanInformationRequest.json" "$ref": "../schemas/LoanStatusRequest.json"
} }
}, },
"application/xml": { "application/xml": {
"schema": { "schema": {
"$ref": "../schemas/LoanInformationRequest.json" "$ref": "../schemas/LoanStatusRequest.json"
} }
}, },
"application/x-www-form-urlencoded": { "application/x-www-form-urlencoded": {
"schema": { "schema": {
"$ref": "../schemas/LoanInformationRequest.json" "$ref": "../schemas/LoanStatusRequest.json"
} }
} }
}, },
@@ -33,12 +33,12 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "../schemas/LoanInformationResponse.json" "$ref": "../schemas/LoanStatusResponse.json"
} }
}, },
"application/xml": { "application/xml": {
"schema": { "schema": {
"$ref": "../schemas/LoanInformationResponse.json" "$ref": "../schemas/LoanStatusResponse.json"
} }
} }
} }
+5 -5
View File
@@ -11,17 +11,17 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "../schemas/LoanInformationRequest.json" "$ref": "../schemas/NotificationCallbackRequest.json"
} }
}, },
"application/xml": { "application/xml": {
"schema": { "schema": {
"$ref": "../schemas/LoanInformationRequest.json" "$ref": "../schemas/NotificationCallbackRequest.json"
} }
}, },
"application/x-www-form-urlencoded": { "application/x-www-form-urlencoded": {
"schema": { "schema": {
"$ref": "../schemas/LoanInformationRequest.json" "$ref": "../schemas/NotificationCallbackRequest.json"
} }
} }
}, },
@@ -33,12 +33,12 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "../schemas/LoanInformationResponse.json" "$ref": "../schemas/NotificationCallbackResponse.json"
} }
}, },
"application/xml": { "application/xml": {
"schema": { "schema": {
"$ref": "../schemas/LoanInformationResponse.json" "$ref": "../schemas/NotificationCallbackResponse.json"
} }
} }
} }
+5 -5
View File
@@ -11,17 +11,17 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "../schemas/EligibilityCheckRequest.json" "$ref": "../schemas/ProvideLoanRequest.json"
} }
}, },
"application/xml": { "application/xml": {
"schema": { "schema": {
"$ref": "../schemas/EligibilityCheckRequest.json" "$ref": "../schemas/ProvideLoanRequest.json"
} }
}, },
"application/x-www-form-urlencoded": { "application/x-www-form-urlencoded": {
"schema": { "schema": {
"$ref": "../schemas/EligibilityCheckRequest.json" "$ref": "../schemas/ProvideLoanRequest.json"
} }
} }
}, },
@@ -33,12 +33,12 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "../schemas/EligibilityCheckResponse.json" "$ref": "../schemas/ProvideLoanResponse.json"
} }
}, },
"application/xml": { "application/xml": {
"schema": { "schema": {
"$ref": "../schemas/EligibilityCheckResponse.json" "$ref": "../schemas/ProvideLoanResponse.json"
} }
} }
} }
@@ -1,7 +1,7 @@
{ {
"type": "object", "type": "object",
"properties": { "properties": {
"$type": { "type": {
"type": "string", "type": "string",
"example": "CustomerConsentRequest" "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", "type": "string",
"example": "Tr201712RK9232P115" "example": "Tr201712RK9232P115"
}, },
"resultDescription": {
"type": "string",
"example": "Successful"
},
"customerId": { "customerId": {
"type": "string", "type": "string",
"example": "CN621868" "example": "CN621868"
@@ -23,6 +19,6 @@
} }
}, },
"xml": { "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", "type": "object",
"properties": { "properties": {
"transactionId": { "requestId": {
"type": "string", "type": "string",
"example": "202111170001371256908" "example": "202111170001371256908"
}, },
"accountId": { "transactionId": {
"type": "string", "type": "string",
"example": "ACN8263457" "example": "Tr201712RK9232P115"
}, },
"customerId": { "customerId": {
"type": "string", "type": "string",
"example": "CN621868" "example": "CN621868"
}, },
"accountId": {
"type": "string",
"example": "ACN8263457"
},
"msisdn": { "msisdn": {
"type": "string", "type": "string",
"example": "9012345678" "example": "3451342"
}, },
"productId": { "productId": {
"type": "string", "type": "string",
"example": "101" "example": "101"
}, },
"lienAmount": {
"type": "number",
"format": "decimal",
"example": 400
},
"requestedAmount": { "requestedAmount": {
"type": "number", "type": "number",
"format": "decimal", "format": "decimal",
@@ -30,13 +39,13 @@
"type": "integer", "type": "integer",
"example": 1 "example": 1
}, },
"offerID": { "loanType": {
"type": "integer", "type": "integer",
"example": 0 "example": 0
}, },
"channel": { "channel": {
"type": "string", "type": "string",
"example": "100" "example": "USSD"
} }
}, },
"xml": { "xml": {
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"type": "object", "type": "object",
"properties": { "properties": {
"$type": { "type": {
"type": "string", "type": "string",
"example": "RepaymentRequest" "example": "RepaymentRequest"
}, },