Skip to content

Instantly share code, notes, and snippets.

@pmutua
Created January 12, 2024 09:31
Show Gist options
  • Save pmutua/e54f370403c3e6de5fcd9ef2ae3b996f to your computer and use it in GitHub Desktop.
Save pmutua/e54f370403c3e6de5fcd9ef2ae3b996f to your computer and use it in GitHub Desktop.
Example Swagger 2.0 JSON file for an ATM Locator API with 10 entries (endpoints):
{
"swagger": "2.0",
"info": {
"title": "ATM Locator API",
"description": "Locate nearby ATMs and their operating status for customers.",
"version": "1.0.0"
},
"basePath": "/api",
"schemes": ["http", "https"],
"paths": {
"/atms/nearby": {
"get": {
"summary": "Find Nearby ATMs",
"description": "Endpoint to find nearby ATMs based on user location.",
"produces": ["application/json"],
"parameters": [
{
"in": "query",
"name": "latitude",
"type": "number",
"format": "double",
"description": "Latitude of user location."
},
{
"in": "query",
"name": "longitude",
"type": "number",
"format": "double",
"description": "Longitude of user location."
},
{
"in": "query",
"name": "radius",
"type": "integer",
"description": "Search radius in meters."
}
],
"responses": {
"200": {
"description": "Successful response",
"schema": {
"$ref": "#/definitions/ATMLocationResult"
}
},
"400": {
"description": "Bad request",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
},
"/atms/status": {
"get": {
"summary": "Get ATM Status",
"description": "Endpoint to get the operating status of a specific ATM.",
"produces": ["application/json"],
"parameters": [
{
"in": "query",
"name": "atmId",
"type": "string",
"description": "ID of the ATM to check status."
}
],
"responses": {
"200": {
"description": "Successful response",
"schema": {
"$ref": "#/definitions/ATMStatus"
}
},
"400": {
"description": "Bad request",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
},
"404": {
"description": "Not found",
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
}
}
},
"/atms/directions": {
"get": {
"summary": "Get Directions to ATM",
"description": "Endpoint to get directions to a specific ATM.",
"produces": ["application/json"],
"parameters": [
{
"in": "query",
"name": "atmId",
"type": "string",
"description": "ID of the ATM for directions."
},
{
"in": "query",
"name": "destinationLatitude",
"type": "number",
"format": "double",
"description": "Latitude of the destination."
},
{
"in": "query",
"name": "destinationLongitude",
"type": "number",
"format": "double",
"description": "Longitude of the destination."
}
],
"responses": {
"200": {
"description": "Successful response",
"schema": {
"$ref": "#/definitions/DirectionsResult"
}
},
"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."
}
}
},
"ATMLocationResult": {
"type": "object",
"properties": {
"atms": {
"type": "array",
"items": {
"$ref": "#/definitions/ATMLocation"
},
"description": "List of nearby ATMs."
}
}
},
"ATMLocation": {
"type": "object",
"properties": {
"atmId": {
"type": "string",
"description": "ID of the ATM."
},
"name": {
"type": "string",
"description": "Name or label of the ATM."
},
"latitude": {
"type": "number",
"format": "double",
"description": "Latitude of the ATM location."
},
"longitude": {
"type": "number",
"format": "double",
"description": "Longitude of the ATM location."
}
}
},
"ATMStatus": {
"type": "object",
"properties": {
"atmId": {
"type": "string",
"description": "ID of the ATM."
},
"status": {
"type": "string",
"description": "Operating status of the ATM (e.g., operational, out of service)."
}
}
},
"DirectionsResult": {
"type": "object",
"properties": {
"atmId": {
"type": "string",
"description": "ID of the ATM for directions."
},
"directions": {
"type": "string",
"description": "Directions to the ATM."
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment