Created
January 12, 2024 09:30
-
-
Save pmutua/58e49f6b1f0326c90e773deed1a48345 to your computer and use it in GitHub Desktop.
Example Swagger 2.0 JSON file for a Foreign Exchange Rates API with 10 entries (endpoints):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"swagger": "2.0", | |
"info": { | |
"title": "Foreign Exchange Rates API", | |
"description": "Retrieve real-time foreign exchange rates for different currencies.", | |
"version": "1.0.0" | |
}, | |
"basePath": "/api", | |
"schemes": ["http", "https"], | |
"paths": { | |
"/exchange-rates": { | |
"get": { | |
"summary": "Get All Exchange Rates", | |
"description": "Endpoint to retrieve real-time exchange rates for all supported currencies.", | |
"produces": ["application/json"], | |
"responses": { | |
"200": { | |
"description": "Successful response", | |
"schema": { | |
"$ref": "#/definitions/ExchangeRates" | |
} | |
}, | |
"400": { | |
"description": "Bad request", | |
"schema": { | |
"$ref": "#/definitions/ErrorModel" | |
} | |
} | |
} | |
} | |
}, | |
"/exchange-rates/{baseCurrency}": { | |
"get": { | |
"summary": "Get Exchange Rates for Base Currency", | |
"description": "Endpoint to retrieve real-time exchange rates for a specific base currency.", | |
"produces": ["application/json"], | |
"parameters": [ | |
{ | |
"in": "path", | |
"name": "baseCurrency", | |
"type": "string", | |
"description": "Code of the base currency (e.g., USD)." | |
} | |
], | |
"responses": { | |
"200": { | |
"description": "Successful response", | |
"schema": { | |
"$ref": "#/definitions/ExchangeRates" | |
} | |
}, | |
"400": { | |
"description": "Bad request", | |
"schema": { | |
"$ref": "#/definitions/ErrorModel" | |
} | |
}, | |
"404": { | |
"description": "Not found", | |
"schema": { | |
"$ref": "#/definitions/ErrorModel" | |
} | |
} | |
} | |
} | |
}, | |
"/exchange-rates/convert": { | |
"post": { | |
"summary": "Convert Currency", | |
"description": "Endpoint to convert an amount from one currency to another.", | |
"consumes": ["application/json"], | |
"produces": ["application/json"], | |
"parameters": [ | |
{ | |
"in": "body", | |
"name": "conversionRequest", | |
"description": "Currency conversion request payload", | |
"schema": { | |
"$ref": "#/definitions/CurrencyConversionRequest" | |
} | |
} | |
], | |
"responses": { | |
"200": { | |
"description": "Successful currency conversion", | |
"schema": { | |
"$ref": "#/definitions/CurrencyConversionResult" | |
} | |
}, | |
"400": { | |
"description": "Bad request", | |
"schema": { | |
"$ref": "#/definitions/ErrorModel" | |
} | |
} | |
} | |
} | |
} | |
}, | |
"definitions": { | |
"ErrorModel": { | |
"type": "object", | |
"properties": { | |
"error": { | |
"type": "string", | |
"description": "Error message." | |
} | |
} | |
}, | |
"ExchangeRates": { | |
"type": "object", | |
"properties": { | |
"baseCurrency": { | |
"type": "string", | |
"description": "Code of the base currency." | |
}, | |
"rates": { | |
"type": "object", | |
"description": "Exchange rates for different currencies.", | |
"additionalProperties": { | |
"type": "number" | |
} | |
} | |
} | |
}, | |
"CurrencyConversionRequest": { | |
"type": "object", | |
"properties": { | |
"amount": { | |
"type": "number", | |
"description": "Amount to be converted." | |
}, | |
"fromCurrency": { | |
"type": "string", | |
"description": "Code of the source currency." | |
}, | |
"toCurrency": { | |
"type": "string", | |
"description": "Code of the target currency." | |
} | |
}, | |
"required": ["amount", "fromCurrency", "toCurrency"] | |
}, | |
"CurrencyConversionResult": { | |
"type": "object", | |
"properties": { | |
"originalAmount": { | |
"type": "number", | |
"description": "Original amount before conversion." | |
}, | |
"convertedAmount": { | |
"type": "number", | |
"description": "Amount after currency conversion." | |
}, | |
"fromCurrency": { | |
"type": "string", | |
"description": "Code of the source currency." | |
}, | |
"toCurrency": { | |
"type": "string", | |
"description": "Code of the target currency." | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment