Skip to content

Instantly share code, notes, and snippets.

@pmutua
Created January 12, 2024 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmutua/55a30f345ea01f91c952c0f42d9b99f7 to your computer and use it in GitHub Desktop.
Save pmutua/55a30f345ea01f91c952c0f42d9b99f7 to your computer and use it in GitHub Desktop.
Example Swagger 2.0 JSON file for a Credit Card Rewards API with 10 entries (endpoints):
{
"swagger": "2.0",
"info": {
"title": "Credit Card Rewards API",
"description": "Manage credit card rewards programs and redeem points.",
"version": "1.0.0"
},
"basePath": "/api",
"schemes": ["http", "https"],
"paths": {
"/rewards/catalog": {
"get": {
"summary": "Get Rewards Catalog",
"description": "Endpoint to get the catalog of available rewards.",
"produces": ["application/json"],
"responses": {
"200": {
"description": "Successful response",
"schema": {
"$ref": "#/definitions/RewardsCatalog"
}
},
"400": {
"description": "Bad request",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
},
"/rewards/earnings/{customerId}": {
"get": {
"summary": "Get Reward Earnings",
"description": "Endpoint to get the reward points earnings for a specific customer.",
"produces": ["application/json"],
"parameters": [
{
"in": "path",
"name": "customerId",
"type": "string",
"description": "ID of the customer for reward earnings retrieval."
}
],
"responses": {
"200": {
"description": "Successful response",
"schema": {
"$ref": "#/definitions/RewardEarnings"
}
},
"400": {
"description": "Bad request",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
},
"404": {
"description": "Not found",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
},
"/rewards/redeem": {
"post": {
"summary": "Redeem Reward Points",
"description": "Endpoint to redeem reward points for a specific reward item.",
"consumes": ["application/json"],
"produces": ["application/json"],
"parameters": [
{
"in": "body",
"name": "redemptionData",
"description": "Reward redemption data",
"schema": {
"$ref": "#/definitions/RewardRedemptionData"
}
}
],
"responses": {
"200": {
"description": "Reward points redeemed successfully",
"schema": {
"$ref": "#/definitions/RewardRedemptionResult"
}
},
"400": {
"description": "Bad request",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
},
"404": {
"description": "Reward item not found",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
},
"/rewards/history/{customerId}": {
"get": {
"summary": "Get Reward Redemption History",
"description": "Endpoint to get the history of reward points redemption for a specific customer.",
"produces": ["application/json"],
"parameters": [
{
"in": "path",
"name": "customerId",
"type": "string",
"description": "ID of the customer for reward redemption history retrieval."
}
],
"responses": {
"200": {
"description": "Successful response",
"schema": {
"$ref": "#/definitions/RewardRedemptionHistory"
}
},
"400": {
"description": "Bad request",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
},
"404": {
"description": "Not found",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
}
},
"definitions": {
"ErrorModel": {
"type": "object",
"properties": {
"error": {
"type": "string",
"description": "Error message."
}
}
},
"RewardsCatalog": {
"type": "object",
"properties": {
"rewardItems": {
"type": "array",
"items": {
"$ref": "#/definitions/RewardItem"
},
"description": "List of available reward items in the catalog."
}
}
},
"RewardItem": {
"type": "object",
"properties": {
"itemId": {
"type": "string",
"description": "ID of the reward item."
},
"name": {
"type": "string",
"description": "Name of the reward item."
},
"pointsRequired": {
"type": "integer",
"description": "Number of reward points required to redeem the item."
}
}
},
"RewardEarnings": {
"type": "object",
"properties": {
"customerId": {
"type": "string",
"description": "ID of the customer for reward earnings retrieval."
},
"totalPoints": {
"type": "integer",
"description": "Total reward points earned by the customer."
}
}
},
"RewardRedemptionData": {
"type": "object",
"properties": {
"customerId": {
"type": "string",
"description": "ID of the customer redeeming reward points."
},
"itemId": {
"type": "string",
"description": "ID of the reward item to be redeemed."
}
},
"required": ["customerId", "itemId"]
},
"RewardRedemptionResult": {
"type": "object",
"properties": {
"redemptionId": {
"type": "string",
"description": "ID of the reward points redemption."
},
"item": {
"type": "string",
"description": "Name of the redeemed reward item."
},
"pointsUsed": {
"type": "integer",
"description": "Number of reward points used for redemption."
}
}
},
"RewardRedemptionHistory": {
"type": "object",
"properties": {
"customerId": {
"type": "string",
"description": "ID of the customer for reward redemption history retrieval."
},
"redemptions": {
"type": "array",
"items": {
"$ref": "#/definitions/RewardRedemptionResult"
},
"description": "List of reward points redemption history entries."
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment