OpenAI - Test API Generation#
In this notebook, we create a fresh REST API specification. APIGeneration models are thought to generate a new API based on similar APIs.
APIGenerator and APIFormatter and thought to perform together but are not exclusive.
1. Data Preparation - API Examples and instructions.#
The examples in the api_examples
folder are APIs along with their descriptions, enabling a search based on similarity.
The variable instructions
pertains to specific criteria we want the generated API to meet. This could involve specifying that it should be entirely in English or include certain types of responses.
[1]:
import sys
sys.path.append("..")
import os
import json
from promptmeteo import APIGenerator
from promptmeteo import APIFormatter
with open("../data/api_examples/api_rest.json") as fin:
data = json.load(fin)
api_descriptions = [i["description"] for i in data]
api_codes = [i["api"] for i in data]
instructions = [
{
"rule": "Actions `get`, `post`, `update`, `delete` must have the properties `tags`, `description`, `summary`, `operationId`, `parameters`, `response`.",
"example": "```\n paths:\n /products:\nget:\n tags:\n - Products\n summary: Service to fetch the list of products.\n description: This service fetches the list of the products.\n operationId: findAllProducts\n parameters:\n - name: brand\n responses:\n '200':\n description: OK\n ```",
}
]
The following variables are essential in the inference process:
description: This is the phrase that provides meaning to the API.
protocol and version: These variables are related to the technical specification of the generated code.
additional information: This variable allows us to include custom information. This information is incorporated exactly as specified in the variable.
[2]:
description = "An API for managing my finances"
protocol = "REST"
version = "3.0.3"
additional_info = {
"servers": [
{
"url": "http://localhost:8080/",
"description": "Local environment",
}
],
}
2. APIGenerator - Generate a new API.#
API Generator is in charge of creating a new REST API based on a knowledge base and some instructions. Example APIs are search based on their descriptions matching the description of the new API.
[3]:
model_1 = APIGenerator(
language="en",
n_samples=5,
api_version=version,
api_protocol=protocol,
api_style_instructions=[i["rule"] for i in instructions],
model_provider_name="openai",
model_name="gpt-3.5-turbo-16k",
model_provider_token=os.environ.get(
"OPENAI_API_KEY",
"",
),
verbose=True,
).train(api_descriptions, api_codes)
[4]:
api = model_1.predict([description])[0]
PROMPT INPUT
You are an API Designer that has to create an API file for your company. The expected file should be OpenAPI 3.0.3 REST API YAML.
### RULES ###
The API should fulfill the following rules:
- Actions `get`, `post`, `update`, `delete` must have the properties `tags`, `description`, `summary`, `operationId`, `parameters`, `response`.
### EXAMPLES ###
For doing so take into consideration `paths`, `schemas` and `parameters` from the following API (They are not complete, they just include the scaffolding):
IBANAPI OpenApi documentation
```
openapi: 3.0.0
servers:
- description: IBANAPI Server
url: https://api.ibanapi.com/v1
info:
contact:
email: samy@ibanapi.com
description: IBANAPI OpenApi documentation
title: IBANAPI OpenApi Documentation
version: 1.0.0
x-apisguru-categories:
- financial
x-logo:
url: https://api.apis.guru/v2/cache/logo/https_ibanapi.com_assets_favicon_apple-touch-icon.png
x-origin:
- format: openapi
url: https://api.ibanapi.com/docs/api-docs.json
version: '3.0'
x-providerName: ibanapi.com
tags:
- description: API Endpoints of IBANAPI
name: IBANAPI
paths:
/balance:
get:
- description
- operationId
- responses
- security
- summary
- tags
/validate:
get:
- description
- operationId
- parameters
- responses
- security
- summary
- tags
/validate-basic:
get:
- description
- operationId
- parameters
- responses
- security
- summary
- tags
components:
parameters:
iban:
- description
- in
- name
- required
- schema
schemas:
'400':
- properties
- type
'401':
- properties
- type
'403':
- properties
- type
'422':
- properties
- type
BalanceResponse:
- properties
- type
IBANResult:
- properties
- type
IBANResultBasic:
- properties
- type
securitySchemes:
api_key_security:
- description
- in
- name
- type
```
The price is a fundamental building block for your listing on Walmart.com. You can use the price management APIs to set up and manage the price for a given item
```
openapi: 3.0.1
servers:
- description: Production URL
url: https://marketplace.walmartapis.com
- description: Sandbox URL
url: https://sandbox.walmartapis.com
info:
contact:
x-twitter: Walmart
description: The price is a fundamental building block for your listing on Walmart.com.
You can use the price management APIs to set up and manage the price for a given
item
title: Price Management
version: 1.0.0
x-apisguru-categories:
- ecommerce
x-logo:
url: https://api.apis.guru/v2/cache/logo/https_twitter.com_Walmart_profile_image.jpeg
x-origin:
- format: openapi
url: https://developer.walmart.com/api/detail
version: '3.0'
x-providerName: walmart.com
x-serviceName: price
security:
- {{}}
paths:
/v3/cppreference:
post:
- description
- externalDocs
- operationId
- parameters
- requestBody
- responses
- summary
- tags
/v3/feeds:
post:
- description
- operationId
- parameters
- requestBody
- responses
- summary
- tags
/v3/price:
put:
- description
- operationId
- parameters
- requestBody
- responses
- summary
- tags
components:
parameters:
accept:
- description
- example
- in
- name
- required
- schema
accessToken:
- description
- example
- in
- name
- required
- schema
authorization:
- description
- example
- in
- name
- required
- schema
channelType:
- description
- in
- name
- required
- schema
content-type:
- description
- example
- in
- name
- required
- schema
correlationId:
- description
- example
- in
- name
- required
- schema
svcName:
- description
- example
- in
- name
- required
- schema
schemas:
CapProgramResponse:
- properties
- type
Cause:
- properties
- type
- xml
ComparisonPrice:
- description
- properties
- type
CurrentPrice:
- properties
- type
FeedId:
- properties
- type
GatewayError:
- properties
- required
- type
- xml
ItemPriceResponse:
- properties
- type
- xml
Price:
- properties
- required
- type
Pricing:
- properties
- required
- type
StatusInfo:
- properties
- type
```
The Assets API exposes fixed asset related functions of the Xero Accounting application and can be used for a variety of purposes such as creating assets, retrieving asset valuations etc.
```
openapi: 3.0.0
servers:
- description: Xero API servers
url: https://api.xero.com/assets.xro/1.0
info:
contact:
email: api@xero.com
name: Xero Platform Team
url: https://developer.xero.com
x-twitter: XeroAPI
description: The Assets API exposes fixed asset related functions of the Xero Accounting
application and can be used for a variety of purposes such as creating assets,
retrieving asset valuations etc.
license:
name: MIT
url: https://github.com/XeroAPI/Xero-OpenAPI/blob/master/LICENSE
termsOfService: https://developer.xero.com/xero-developer-platform-terms-conditions/
title: Xero Assets API
version: 2.9.4
x-apisguru-categories:
- financial
x-origin:
- format: openapi
url: https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/master/xero_assets.yaml
version: '3.0'
x-providerName: xero.com
x-serviceName: xero_assets
x-logo:
url: https://api.apis.guru/v2/cache/logo/https_apis.guru_assets_images_no-logo.svg
paths:
/AssetTypes:
get:
- description
- operationId
- responses
- security
- summary
- tags
parameters:
- $ref: '#/components/parameters/requiredHeader'
post:
- description
- operationId
- requestBody
- responses
- security
- summary
- tags
- x-hasAssetsValidationError
/Assets:
get:
- description
- operationId
- parameters
- responses
- security
- summary
- tags
parameters:
- $ref: '#/components/parameters/requiredHeader'
post:
- description
- operationId
- requestBody
- responses
- security
- summary
- tags
- x-hasAssetsValidationError
/Assets/{{id}}:
get:
- description
- operationId
- parameters
- responses
- security
- summary
- tags
parameters:
- $ref: '#/components/parameters/requiredHeader'
/Settings:
get:
- description
- operationId
- responses
- security
- summary
- tags
parameters:
- $ref: '#/components/parameters/requiredHeader'
components:
parameters:
requiredHeader:
- description
- example
- in
- name
- required
- schema
schemas:
Asset:
- properties
- required
- type
AssetStatus:
- description
- enum
- example
- type
AssetStatusQueryParam:
- description
- enum
- example
- type
AssetType:
- properties
- required
- type
Assets:
- properties
- type
BookDepreciationDetail:
- properties
- required
BookDepreciationSetting:
- properties
- required
Error:
- externalDocs
- properties
- type
FieldValidationErrorsElement:
- externalDocs
- properties
- type
Pagination:
- properties
ResourceValidationErrorsElement:
- externalDocs
- properties
- type
Setting:
- properties
- required
- type
securitySchemes:
OAuth2:
- description
- flows
- type
```
The Vonage Business Cloud Reports API enables you to retrieve call logs for your account.
```
openapi: 3.0.0
servers:
- url: https://api.vonage.com/t/vbc.prod/reports
info:
contact:
name: Vonage Business Cloud Support
url: https://businesssupport.vonage.com/contactus
description: 'The Vonage Business Cloud Reports API enables you to retrieve call
logs for your account.
Your application must subscribe to the Reports API suite to use this API.
'
termsOfService: https://www.vonage.com/business/legal-policy-center/business-cloud/tos
title: Reports API
version: 1.0.1
x-origin:
- format: openapi
url: https://raw.githubusercontent.com/nexmo/api-specification/master/definitions/vonage-business-cloud/reports.yml
version: '3.0'
x-providerName: vonage.com
x-serviceName: reports
x-logo:
url: https://api.apis.guru/v2/cache/logo/https_apis.guru_assets_images_no-logo.svg
paths:
/accounts/{{account_id}}/call-logs:
get:
- description
- operationId
- parameters
- responses
- security
- summary
components:
parameters:
AccountID:
- description
- example
- in
- name
- required
- schema
schemas:
CallLog:
- properties
- type
CallLogsEmbeddedObject:
- properties
- type
CallLogsHalResponse:
- properties
- type
DetailedInvalidParam:
- properties
- type
ErrorResponse:
- properties
- type
FirstHref:
- description
- properties
- type
LastHref:
- description
- properties
- type
Links:
- properties
- type
NextHref:
- description
- properties
- type
PrevHref:
- description
- properties
- type
SelfHref:
- description
- properties
- type
ValidationErrorsResponse:
- properties
- type
securitySchemes:
bearerAuth:
- bearerFormat
- scheme
- type
```
The Google Play Game Management API allows developers to manage resources from the Google Play Game service.
```
openapi: 3.0.0
servers:
- url: https://gamesmanagement.googleapis.com/
info:
contact:
name: Google
url: https://google.com
x-twitter: youtube
description: The Google Play Game Management API allows developers to manage resources
from the Google Play Game service.
license:
name: Creative Commons Attribution 3.0
url: http://creativecommons.org/licenses/by/3.0/
termsOfService: https://developers.google.com/terms/
title: Google Play Game Management
version: v1management
x-apiClientRegistration:
url: https://console.developers.google.com
x-apisguru-categories:
- analytics
- media
x-logo:
url: https://api.apis.guru/v2/cache/logo/https_www.google.com_images_branding_googlelogo_2x_googlelogo_color_272x92dp.png
x-origin:
- format: google
url: https://gamesmanagement.googleapis.com/$discovery/rest?version=v1management
version: v1
x-providerName: googleapis.com
x-serviceName: gamesManagement
externalDocs:
url: https://developers.google.com/games/
tags:
- name: achievements
- name: applications
- name: events
- name: players
- name: scores
paths:
/games/v1management/achievements/reset:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- responses
- security
- tags
/games/v1management/achievements/resetAllForAllPlayers:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- responses
- security
- tags
/games/v1management/achievements/resetMultipleForAllPlayers:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- requestBody
- responses
- security
- tags
/games/v1management/achievements/{{achievementId}}/reset:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- parameters
- responses
- security
- tags
/games/v1management/achievements/{{achievementId}}/resetForAllPlayers:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- parameters
- responses
- security
- tags
/games/v1management/applications/{{applicationId}}/players/hidden:
get:
- description
- operationId
- parameters
- responses
- security
- tags
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
/games/v1management/applications/{{applicationId}}/players/hidden/{{playerId}}:
delete:
- description
- operationId
- parameters
- responses
- security
- tags
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- parameters
- responses
- security
- tags
/games/v1management/events/reset:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- responses
- security
- tags
/games/v1management/events/resetAllForAllPlayers:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- responses
- security
- tags
/games/v1management/events/resetMultipleForAllPlayers:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- requestBody
- responses
- security
- tags
/games/v1management/events/{{eventId}}/reset:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- parameters
- responses
- security
- tags
/games/v1management/events/{{eventId}}/resetForAllPlayers:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- parameters
- responses
- security
- tags
/games/v1management/leaderboards/{{leaderboardId}}/scores/reset:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- parameters
- responses
- security
- tags
/games/v1management/leaderboards/{{leaderboardId}}/scores/resetForAllPlayers:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- parameters
- responses
- security
- tags
/games/v1management/scores/reset:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- responses
- security
- tags
/games/v1management/scores/resetAllForAllPlayers:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- responses
- security
- tags
/games/v1management/scores/resetMultipleForAllPlayers:
parameters:
- $ref: '#/components/parameters/_.xgafv'
- $ref: '#/components/parameters/access_token'
- $ref: '#/components/parameters/alt'
- $ref: '#/components/parameters/callback'
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/key'
- $ref: '#/components/parameters/oauth_token'
- $ref: '#/components/parameters/prettyPrint'
- $ref: '#/components/parameters/quotaUser'
- $ref: '#/components/parameters/upload_protocol'
- $ref: '#/components/parameters/uploadType'
post:
- description
- operationId
- requestBody
- responses
- security
- tags
components:
parameters:
_.xgafv:
- description
- in
- name
- schema
access_token:
- description
- in
- name
- schema
alt:
- description
- in
- name
- schema
callback:
- description
- in
- name
- schema
fields:
- description
- in
- name
- schema
key:
- description
- in
- name
- schema
oauth_token:
- description
- in
- name
- schema
prettyPrint:
- description
- in
- name
- schema
quotaUser:
- description
- in
- name
- schema
uploadType:
- description
- in
- name
- schema
upload_protocol:
- description
- in
- name
- schema
schemas:
AchievementResetAllResponse:
- description
- properties
- type
AchievementResetMultipleForAllRequest:
- properties
- type
AchievementResetResponse:
- description
- properties
- type
EventsResetMultipleForAllRequest:
- description
- properties
- type
GamesPlayerExperienceInfoResource:
- description
- properties
- type
GamesPlayerLevelResource:
- description
- properties
- type
HiddenPlayer:
- description
- properties
- type
HiddenPlayerList:
- description
- properties
- type
Player:
- description
- properties
- type
PlayerScoreResetAllResponse:
- description
- properties
- type
PlayerScoreResetResponse:
- description
- properties
- type
ProfileSettings:
- description
- properties
- type
ScoresResetMultipleForAllRequest:
- properties
- type
securitySchemes:
Oauth2:
- description
- flows
- type
Oauth2c:
- description
- flows
- type
```
The API purpose is: "An API for managing my finances." Please create a complete API and answer just with the code, following the previous RULES and the `paths`, `schemas` and `parameters` from the EXAMPLES.
MODEL OUTPUT
openapi: 3.0.3
servers:
- description: My Finances API Server
url: https://api.myfinances.com/v1
info:
contact:
email: api@myfinances.com
description: An API for managing my finances.
title: My Finances API
version: 1.0.0
tags:
- description: API Endpoints of My Finances
name: My Finances
paths:
/balance:
get:
tags:
- My Finances
description: Get the balance of my finances.
summary: Get Balance
operationId: getBalance
parameters:
- $ref: '#/components/parameters/accessToken'
responses:
'200':
description: Successful response with the balance.
content:
application/json:
schema:
$ref: '#/components/schemas/BalanceResponse'
'401':
$ref: '#/components/schemas/401'
/transactions:
get:
tags:
- My Finances
description: Get a list of transactions.
summary: Get Transactions
operationId: getTransactions
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/startDate'
- $ref: '#/components/parameters/endDate'
responses:
'200':
description: Successful response with the list of transactions.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Transaction'
'401':
$ref: '#/components/schemas/401'
post:
tags:
- My Finances
description: Create a new transaction.
summary: Create Transaction
operationId: createTransaction
parameters:
- $ref: '#/components/parameters/accessToken'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
responses:
'201':
description: Successful response indicating the transaction was created.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'400':
$ref: '#/components/schemas/400'
'401':
$ref: '#/components/schemas/401'
/transactions/{id}:
get:
tags:
- My Finances
description: Get a specific transaction by ID.
summary: Get Transaction by ID
operationId: getTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
responses:
'200':
description: Successful response with the transaction.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'401':
$ref: '#/components/schemas/401'
put:
tags:
- My Finances
description: Update a specific transaction by ID.
summary: Update Transaction by ID
operationId: updateTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
responses:
'200':
description: Successful response indicating the transaction was updated.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'400':
$ref: '#/components/schemas/400'
'401':
$ref: '#/components/schemas/401'
delete:
tags:
- My Finances
description: Delete a specific transaction by ID.
summary: Delete Transaction by ID
operationId: deleteTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
responses:
'204':
description: Successful response indicating the transaction was deleted.
'401':
$ref: '#/components/schemas/401'
components:
parameters:
accessToken:
- description: Access token for authentication.
in: header
name: Authorization
required: true
schema:
type: string
startDate:
- description: Start date of the transaction period.
in: query
name: startDate
required: true
schema:
type: string
format: date
endDate:
- description: End date of the transaction period.
in: query
name: endDate
required: true
schema:
type: string
format: date
id:
- description: ID of the transaction.
in: path
name: id
required: true
schema:
type: string
schemas:
BalanceResponse:
type: object
properties:
balance:
type: number
Transaction:
type: object
properties:
id:
type: string
date:
type: string
format: date
description:
type: string
amount:
type: number
category:
type: string
400:
type: object
properties:
error:
type: string
401:
type: object
properties:
error:
type: string
PARSE RESULT
openapi: 3.0.3
servers:
- description: My Finances API Server
url: https://api.myfinances.com/v1
info:
contact:
email: api@myfinances.com
description: An API for managing my finances.
title: My Finances API
version: 1.0.0
tags:
- description: API Endpoints of My Finances
name: My Finances
paths:
/balance:
get:
tags:
- My Finances
description: Get the balance of my finances.
summary: Get Balance
operationId: getBalance
parameters:
- $ref: '#/components/parameters/accessToken'
responses:
'200':
description: Successful response with the balance.
content:
application/json:
schema:
$ref: '#/components/schemas/BalanceResponse'
'401':
$ref: '#/components/schemas/401'
/transactions:
get:
tags:
- My Finances
description: Get a list of transactions.
summary: Get Transactions
operationId: getTransactions
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/startDate'
- $ref: '#/components/parameters/endDate'
responses:
'200':
description: Successful response with the list of transactions.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Transaction'
'401':
$ref: '#/components/schemas/401'
post:
tags:
- My Finances
description: Create a new transaction.
summary: Create Transaction
operationId: createTransaction
parameters:
- $ref: '#/components/parameters/accessToken'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
responses:
'201':
description: Successful response indicating the transaction was created.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'400':
$ref: '#/components/schemas/400'
'401':
$ref: '#/components/schemas/401'
/transactions/{id}:
get:
tags:
- My Finances
description: Get a specific transaction by ID.
summary: Get Transaction by ID
operationId: getTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
responses:
'200':
description: Successful response with the transaction.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'401':
$ref: '#/components/schemas/401'
put:
tags:
- My Finances
description: Update a specific transaction by ID.
summary: Update Transaction by ID
operationId: updateTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
responses:
'200':
description: Successful response indicating the transaction was updated.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'400':
$ref: '#/components/schemas/400'
'401':
$ref: '#/components/schemas/401'
delete:
tags:
- My Finances
description: Delete a specific transaction by ID.
summary: Delete Transaction by ID
operationId: deleteTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
responses:
'204':
description: Successful response indicating the transaction was deleted.
'401':
$ref: '#/components/schemas/401'
components:
parameters:
accessToken:
- description: Access token for authentication.
in: header
name: Authorization
required: true
schema:
type: string
startDate:
- description: Start date of the transaction period.
in: query
name: startDate
required: true
schema:
type: string
format: date
endDate:
- description: End date of the transaction period.
in: query
name: endDate
required: true
schema:
type: string
format: date
id:
- description: ID of the transaction.
in: path
name: id
required: true
schema:
type: string
schemas:
BalanceResponse:
type: object
properties:
balance:
type: number
Transaction:
type: object
properties:
id:
type: string
date:
type: string
format: date
description:
type: string
amount:
type: number
category:
type: string
400:
type: object
properties:
error:
type: string
401:
type: object
properties:
error:
type: string
API Formatter - Correct an API#
The API Formatter processes an API specification, providing instructions to the Language Model (LLM) for correction and formatting based on the given instructions. Additionally, its parser handles schemas and parameters, replacing coincidental information with details extracted from example APIs. The objective is to maximize the reuse of information throughout the formatting process.
[5]:
model_2 = APIFormatter(
language="en",
api_version=version,
api_protocol=protocol,
api_style_instructions=["For example:\n\n".join(i.values()) for i in instructions],
model_provider_name="openai",
model_name="gpt-3.5-turbo-16k",
model_provider_token=os.environ.get(
"OPENAI_API_KEY",
"",
),
verbose=True,
).train(api_codes)
[7]:
api = model_2.predict([api], additional_info)[0]
PROMPT INPUT
I want you to complete and correct an openAPI file. The expected file should be OpenAPI 3.0.3 REST API YAML.
### RULES ###
Make sure that the API should fulfill the following requirements:
- Actions `get`, `post`, `update`, `delete` must have the properties `tags`, `description`, `summary`, `operationId`, `parameters`, `response`.For example:
```
paths:
/products:
get:
tags:
- Products
summary: Service to fetch the list of products.
description: This service fetches the list of the products.
operationId: findAllProducts
parameters:
- name: brand
responses:
'200':
description: OK
```
The API that you have to correct is:
```
openapi: 3.0.3
servers:
- url: http://localhost:8080/
description: Local environment
info:
contact:
email: api@myfinances.com
description: An API for managing my finances.
title: My Finances API
version: 1.0.0
tags:
- description: API Endpoints of My Finances
name: My Finances
paths:
/balance:
get:
tags:
- My Finances
summary: Get Balance
description: Get the balance of my finances.
operationId: getBalance
parameters:
- $ref: '#/components/parameters/accessToken'
responses:
'200':
description: Successful response with the balance.
content:
application/json:
schema:
$ref: '#/components/schemas/BalanceResponse'
'401':
$ref: '#/components/schemas/401'
/transactions:
get:
tags:
- My Finances
summary: Get Transactions
description: Get a list of transactions.
operationId: getTransactions
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/startDate'
- $ref: '#/components/parameters/endDate'
responses:
'200':
description: Successful response with the list of transactions.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Transaction'
'401':
$ref: '#/components/schemas/401'
post:
tags:
- My Finances
summary: Create Transaction
description: Create a new transaction.
operationId: createTransaction
parameters:
- $ref: '#/components/parameters/accessToken'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
responses:
'201':
description: Successful response indicating the transaction was created.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'400':
$ref: '#/components/schemas/400'
'401':
$ref: '#/components/schemas/401'
/transactions/{{id}}:
get:
tags:
- My Finances
summary: Get Transaction by ID
description: Get a specific transaction by ID.
operationId: getTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
responses:
'200':
description: Successful response with the transaction.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'401':
$ref: '#/components/schemas/401'
put:
tags:
- My Finances
summary: Update Transaction by ID
description: Update a specific transaction by ID.
operationId: updateTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
responses:
'200':
description: Successful response indicating the transaction was updated.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'400':
$ref: '#/components/schemas/400'
'401':
$ref: '#/components/schemas/401'
delete:
tags:
- My Finances
summary: Delete Transaction by ID
description: Delete a specific transaction by ID.
operationId: deleteTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
responses:
'204':
description: Successful response indicating the transaction was deleted.
'401':
$ref: '#/components/schemas/401'
components:
parameters:
accessToken:
description: The access token retrieved in the Token API call
example: eyJraWQiOiIzZjVhYTFmNS1hYWE5LTQzM.....
in: header
name: WM_SEC.ACCESS_TOKEN
required: true
schema:
type: string
startDate:
description: Start date of the transaction period.
in: query
name: startDate
required: true
schema:
type: string
format: date
endDate:
description: End date of the transaction period.
in: query
name: endDate
required: true
schema:
type: string
format: date
id:
description: ID of the record you are acting upon.
in: path
name: id
required: true
schema:
type: string
schemas:
BalanceResponse:
properties:
data:
example:
bank_balance: 100
basic_balance: 2000
expiry_date: 2021-05-16
type: object
message:
example: SUCCESS
type: string
result:
example: '200'
type: integer
type: object
Transaction:
allOf:
- properties:
accountId:
description: The unique identifier of the bank account.
minLength: 1
type: string
amount:
description: The amount of the bank transaction.
type: number
authorizedDate:
$ref: '#/components/schemas/DateTime'
description: The date the bank transaction was authorized.
code:
$ref: '#/components/schemas/Transaction/definitions/transactionCode'
currency:
description: The currency of the bank transaction.
minLength: 1
type: string
description:
description: The description of the bank transaction.
nullable: true
type: string
id:
description: The unique identifier of the bank transaction.
minLength: 1
type: string
merchantName:
description: The name of the merchant.
nullable: true
type: string
postedDate:
$ref: '#/components/schemas/DateTime'
description: The date the bank transaction was cleared.
transactionCategoryRef:
$ref: '#/components/schemas/TransactionCategory/definitions/transactionCategoryRef'
type: object
- $ref: '#/components/schemas/ModifiedDates'
definitions:
transactionCode:
description: Code to identify the underlying transaction.
enum:
- Unknown
- Fee
- Payment
- Cash
- Transfer
- Interest
- Cashback
- Cheque
- DirectDebit
- Purchase
- StandingOrder
- Adjustment
- Credit
- Other
- NotSupported
type: string
x-internal: true
description: 'The Banking Transactions data type provides an immutable source
of up-to-date information on income and expenditure.
Responses are paged, so you should provide `page` and `pageSize` query parameters
in your request.
View the coverage for banking transactions in the [Data Coverage Explorer](https://knowledge.codat.io/supported-features/banking?view=tab-by-data-type&dataType=banking-transactions).'
examples:
- accountId: 1703194f-7805-4da8-bac0-2ba5da4a4216
amount: 5062.39
authorizedDate: 2021-07-06 00:00:00
currency: GBP
description: Payments for direct income ce149943-c157-43fc-aac7-42a716b655b6
id: 0130b5bb-1419-40f6-8a27-7362d0381229
merchantName: New Look
modifiedDate: 2022-05-23 16:32:50+00:00
postedDate: 2021-07-06 00:00:00
sourceModifiedDate: 2021-06-28 10:48:12
transactionCategoryRef:
id: health-and-fitness-sports
required:
- id
- accountId
- currency
title: Transaction
type: object
'400':
properties:
data:
example: '{{}}'
type: object
message:
example: Your balance is exhausted
type: string
result:
example: '400'
type: integer
type: object
'401':
properties:
data:
example: '{{}}'
type: object
message:
example: Your package has expired
type: string
result:
example: '401'
type: integer
type: object
DateTime:
description: "In Codat's data model, dates and times are represented using the\
\ <a class=\"external\" href=\"https://en.wikipedia.org/wiki/ISO_8601\" target=\"\
_blank\">ISO 8601 standard</a>. Date and time fields are formatted as strings;\
\ for example:\n\n```\n2020-10-08T22:40:50Z\n2021-01-01T00:00:00\n```\n\n\n\
\nWhen syncing data that contains `DateTime` fields from Codat, make sure\
\ you support the following cases when reading time information:\n\n- Coordinated\
\ Universal Time (UTC): `2021-11-15T06:00:00Z`\n- Unqualified local time:\
\ `2021-11-15T01:00:00`\n- UTC time offsets: `2021-11-15T01:00:00-05:00`\n\
\n> Time zones\n> \n> Not all dates from Codat will contain information about\
\ time zones. \n> Where it is not available from the underlying platform,\
\ Codat will return these as times local to the business whose data has been\
\ synced."
example: 2022-10-23 00:00:00+00:00
title: Date time
type: string
TransactionCategory:
allOf:
- description: Status of the bank transaction category.
properties:
hasChildren:
description: A Boolean indicating whether there are other bank transaction
categories beneath this one in the hierarchy.
type: boolean
id:
description: The unique identifier of the bank transaction category.
minLength: 1
type: string
name:
description: The name of the bank transaction category.
minLength: 1
type: string
parentId:
description: The unique identifier of the parent bank transaction category.
nullable: true
type: string
status:
$ref: '#/components/schemas/TransactionCategory/definitions/transactionCategoryStatus'
type: object
- $ref: '#/components/schemas/ModifiedDates'
definitions:
transactionCategoryRef:
description: An object of bank transaction category reference data.
properties:
id:
description: The unique category reference id for the bank transaction.
minLength: 1
type: string
name:
description: The category name reference for the bank transaction.
nullable: true
type: string
required:
- id
type: object
x-internal: true
transactionCategoryStatus:
enum:
- Unknown
- Active
- Archived
type: string
x-internal: true
description: 'The Banking Transaction Categories data type provides a list of
hierarchical categories associated with a transaction for greater contextual
meaning to transaction activity.
Responses are paged, so you should provide `page` and `pageSize` query parameters
in your request.'
examples:
- hasChildren: true
id: auto-and-transport
modifiedDate: 2022-05-23 16:32:50
name: Auto & Transport
sourceModifiedDate: 2021-04-24 07:59:10
status: Active
required:
- id
- name
title: Transaction Category
type: object
ModifiedDates:
allOf:
- $ref: '#/components/schemas/ModifiedDate'
- $ref: '#/components/schemas/SourceModifiedDate'
x-internal: true
ModifiedDate:
properties:
modifiedDate:
$ref: '#/components/schemas/DateTime'
description: The date on which this record was last modified in Codat.
title: ModifiedDate
type: object
x-internal: true
SourceModifiedDate:
properties:
sourceModifiedDate:
$ref: '#/components/schemas/DateTime'
description: The date on which this record was last modified in the originating
system
title: Source Modified Date
type: object
x-internal: true
```
MODEL OUTPUT
openapi: 3.0.3
servers:
- url: http://localhost:8080/
description: Local environment
info:
contact:
email: api@myfinances.com
description: An API for managing my finances.
title: My Finances API
version: 1.0.0
tags:
- description: API Endpoints of My Finances
name: My Finances
paths:
/balance:
get:
tags:
- My Finances
summary: Get Balance
description: Get the balance of my finances.
operationId: getBalance
parameters:
- $ref: '#/components/parameters/accessToken'
responses:
'200':
description: Successful response with the balance.
content:
application/json:
schema:
$ref: '#/components/schemas/BalanceResponse'
'401':
$ref: '#/components/schemas/401'
/transactions:
get:
tags:
- My Finances
summary: Get Transactions
description: Get a list of transactions.
operationId: getTransactions
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/startDate'
- $ref: '#/components/parameters/endDate'
responses:
'200':
description: Successful response with the list of transactions.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Transaction'
'401':
$ref: '#/components/schemas/401'
post:
tags:
- My Finances
summary: Create Transaction
description: Create a new transaction.
operationId: createTransaction
parameters:
- $ref: '#/components/parameters/accessToken'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
responses:
'201':
description: Successful response indicating the transaction was created.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'400':
$ref: '#/components/schemas/400'
'401':
$ref: '#/components/schemas/401'
/transactions/{id}:
get:
tags:
- My Finances
summary: Get Transaction by ID
description: Get a specific transaction by ID.
operationId: getTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
responses:
'200':
description: Successful response with the transaction.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'401':
$ref: '#/components/schemas/401'
put:
tags:
- My Finances
summary: Update Transaction by ID
description: Update a specific transaction by ID.
operationId: updateTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
responses:
'200':
description: Successful response indicating the transaction was updated.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'400':
$ref: '#/components/schemas/400'
'401':
$ref: '#/components/schemas/401'
delete:
tags:
- My Finances
summary: Delete Transaction by ID
description: Delete a specific transaction by ID.
operationId: deleteTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
responses:
'204':
description: Successful response indicating the transaction was deleted.
'401':
$ref: '#/components/schemas/401'
components:
parameters:
accessToken:
description: The access token retrieved in the Token API call
example: eyJraWQiOiIzZjVhYTFmNS1hYWE5LTQzM.....
in: header
name: WM_SEC.ACCESS_TOKEN
required: true
schema:
type: string
startDate:
description: Start date of the transaction period.
in: query
name: startDate
required: true
schema:
type: string
format: date
endDate:
description: End date of the transaction period.
in: query
name: endDate
required: true
schema:
type: string
format: date
id:
description: ID of the record you are acting upon.
in: path
name: id
required: true
schema:
type: string
schemas:
BalanceResponse:
properties:
data:
example:
bank_balance: 100
basic_balance: 2000
expiry_date: 2021-05-16
type: object
message:
example: SUCCESS
type: string
result:
example: '200'
type: integer
type: object
Transaction:
allOf:
- properties:
accountId:
description: The unique identifier of the bank account.
minLength: 1
type: string
amount:
description: The amount of the bank transaction.
type: number
authorizedDate:
$ref: '#/components/schemas/DateTime'
description: The date the bank transaction was authorized.
code:
$ref: '#/components/schemas/Transaction/definitions/transactionCode'
currency:
description: The currency of the bank transaction.
minLength: 1
type: string
description:
description: The description of the bank transaction.
nullable: true
type: string
id:
description: The unique identifier of the bank transaction.
minLength: 1
type: string
merchantName:
description: The name of the merchant.
nullable: true
type: string
postedDate:
$ref: '#/components/schemas/DateTime'
description: The date the bank transaction was cleared.
transactionCategoryRef:
$ref: '#/components/schemas/TransactionCategory/definitions/transactionCategoryRef'
type: object
- $ref: '#/components/schemas/ModifiedDates'
definitions:
transactionCode:
description: Code to identify the underlying transaction.
enum:
- Unknown
- Fee
- Payment
- Cash
- Transfer
- Interest
- Cashback
- Cheque
- DirectDebit
- Purchase
- StandingOrder
- Adjustment
- Credit
- Other
- NotSupported
type: string
x-internal: true
description: 'The Banking Transactions data type provides an immutable source
of up-to-date information on income and expenditure.
Responses are paged, so you should provide `page` and `pageSize` query parameters
in your request.
View the coverage for banking transactions in the [Data Coverage Explorer](https://knowledge.codat.io/supported-features/banking?view=tab-by-data-type&dataType=banking-transactions).'
examples:
- accountId: 1703194f-7805-4da8-bac0-2ba5da4a4216
amount: 5062.39
authorizedDate: 2021-07-06 00:00:00
currency: GBP
description: Payments for direct income ce149943-c157-43fc-aac7-42a716b655b6
id: 0130b5bb-1419-40f6-8a27-7362d0381229
merchantName: New Look
modifiedDate: 2022-05-23 16:32:50+00:00
postedDate: 2021-07-06 00:00:00
sourceModifiedDate: 2021-06-28 10:48:12
transactionCategoryRef:
id: health-and-fitness-sports
required:
- id
- accountId
- currency
title: Transaction
type: object
'400':
properties:
data:
example: '{{}}'
type: object
message:
example: Your balance is exhausted
type: string
result:
example: '400'
type: integer
type: object
'401':
properties:
data:
example: '{{}}'
type: object
message:
example: Your package has expired
type: string
result:
example: '401'
type: integer
type: object
DateTime:
description: "In Codat's data model, dates and times are represented using the\
\ <a class=\"external\" href=\"https://en.wikipedia.org/wiki/ISO_8601\" target=\"\
_blank\">ISO 8601 standard</a>. Date and time fields are formatted as strings;\
\ for example:\n\n```\n2020-10-08T22:40:50Z\n2021-01-01T00:00:00\n```\n\n\n\
\nWhen syncing data that contains `DateTime` fields from Codat, make sure\
\ you support the following cases when reading time information:\n\n- Coordinated\
\ Universal Time (UTC): `2021-11-15T06:00:00Z`\n- Unqualified local time:\
\ `2021-11-15T01:00:00`\n- UTC time offsets: `2021-11-15T01:00:00-05:00`\n\
\n> Time zones\n> \n> Not all dates from Codat will contain information about\
\ time zones. \n> Where it is not available from the underlying platform,\
\ Codat will return these as times local to the business whose data has been\
\ synced."
example: 2022-10-23 00:00:00+00:00
title: Date time
type: string
TransactionCategory:
allOf:
- description: Status of the bank transaction category.
properties:
hasChildren:
description: A Boolean indicating whether there are other bank transaction
categories beneath this one in the hierarchy.
type: boolean
id:
description: The unique identifier of the bank transaction category.
minLength: 1
type: string
name:
description: The name of the bank transaction category.
minLength: 1
type: string
parentId:
description: The unique identifier of the parent bank transaction category.
nullable: true
type: string
status:
$ref: '#/components/schemas/TransactionCategory/definitions/transactionCategoryStatus'
type: object
- $ref: '#/components/schemas/ModifiedDates'
definitions:
transactionCategoryRef:
description: An object of bank transaction category reference data.
properties:
id:
description: The unique category reference id for the bank transaction.
minLength: 1
type: string
name:
description: The category name reference for the bank transaction.
nullable: true
type: string
required:
- id
type: object
x-internal: true
transactionCategoryStatus:
enum:
- Unknown
- Active
- Archived
type: string
x-internal: true
description: 'The Banking Transaction Categories data type provides a list of
hierarchical categories associated with a transaction for greater contextual
meaning to transaction activity.
Responses are paged, so you should provide `page` and `pageSize` query parameters
in your request.'
examples:
- hasChildren: true
id: auto-and-transport
modifiedDate: 2022-05-23 16:32:50
name: Auto & Transport
sourceModifiedDate: 2021-04-24 07:59:10
status: Active
required:
- id
- name
title: Transaction Category
type: object
ModifiedDates:
allOf:
- $ref: '#/components/schemas/ModifiedDate'
- $ref: '#/components/schemas/SourceModifiedDate'
x-internal: true
ModifiedDate:
properties:
modifiedDate:
$ref: '#/components/schemas/DateTime'
description: The date on which this record was last modified in Codat.
title: ModifiedDate
type: object
x-internal: true
SourceModifiedDate:
properties:
sourceModifiedDate:
$ref: '#/components/schemas/DateTime'
description: The date on which this record was last modified in the originating
system
title: Source Modified Date
type: object
x-internal: true
PARSE RESULT
\n2020-10-08T22:40:50Z\n2021-01-01T00:00:00\n
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[7], line 1
----> 1 api = model_2.predict([api], additional_info)[0]
File ~/Documents/Promptmeteo/examples/../promptmeteo/api_formatter.py:286, in APIFormatter.predict(self, api_codes, external_info)
284 _api_codes = deepcopy(api_codes)
285 _api_codes = super(APIFormatter, self).predict(examples=_api_codes)
--> 286 _api_codes = [self._replace(api) for api in _api_codes]
287 _api_codes = [
288 self._add_external_information(api, external_info)
289 for api in _api_codes
290 ]
291 return _api_codes
File ~/Documents/Promptmeteo/examples/../promptmeteo/api_formatter.py:286, in <listcomp>(.0)
284 _api_codes = deepcopy(api_codes)
285 _api_codes = super(APIFormatter, self).predict(examples=_api_codes)
--> 286 _api_codes = [self._replace(api) for api in _api_codes]
287 _api_codes = [
288 self._add_external_information(api, external_info)
289 for api in _api_codes
290 ]
291 return _api_codes
File ~/Documents/Promptmeteo/examples/../promptmeteo/api_formatter.py:304, in APIFormatter._replace(self, api)
302 # Replace entities
303 api = yaml.load(api, Loader=yaml.FullLoader)
--> 304 for entity in api.get("components", {}).get("schemas", {}).keys():
305 if entity in self._entities:
306 api["components"]["schemas"][entity] = yaml.load(
307 self._entities[entity], Loader=yaml.FullLoader
308 )
AttributeError: 'str' object has no attribute 'get'
[8]:
print(api)
openapi: 3.0.3
servers:
- url: http://localhost:8080/
description: Local environment
info:
contact:
email: api@myfinances.com
description: An API for managing my finances.
title: My Finances API
version: 1.0.0
tags:
- description: API Endpoints of My Finances
name: My Finances
paths:
/balance:
get:
tags:
- My Finances
summary: Get Balance
description: Get the balance of my finances.
operationId: getBalance
parameters:
- $ref: '#/components/parameters/accessToken'
responses:
'200':
description: Successful response with the balance.
content:
application/json:
schema:
$ref: '#/components/schemas/BalanceResponse'
'401':
$ref: '#/components/schemas/401'
/transactions:
get:
tags:
- My Finances
summary: Get Transactions
description: Get a list of transactions.
operationId: getTransactions
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/startDate'
- $ref: '#/components/parameters/endDate'
responses:
'200':
description: Successful response with the list of transactions.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Transaction'
'401':
$ref: '#/components/schemas/401'
post:
tags:
- My Finances
summary: Create Transaction
description: Create a new transaction.
operationId: createTransaction
parameters:
- $ref: '#/components/parameters/accessToken'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
responses:
'201':
description: Successful response indicating the transaction was created.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'400':
$ref: '#/components/schemas/400'
'401':
$ref: '#/components/schemas/401'
/transactions/{id}:
get:
tags:
- My Finances
summary: Get Transaction by ID
description: Get a specific transaction by ID.
operationId: getTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
responses:
'200':
description: Successful response with the transaction.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'401':
$ref: '#/components/schemas/401'
put:
tags:
- My Finances
summary: Update Transaction by ID
description: Update a specific transaction by ID.
operationId: updateTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
responses:
'200':
description: Successful response indicating the transaction was updated.
content:
application/json:
schema:
$ref: '#/components/schemas/Transaction'
'400':
$ref: '#/components/schemas/400'
'401':
$ref: '#/components/schemas/401'
delete:
tags:
- My Finances
summary: Delete Transaction by ID
description: Delete a specific transaction by ID.
operationId: deleteTransactionById
parameters:
- $ref: '#/components/parameters/accessToken'
- $ref: '#/components/parameters/id'
responses:
'204':
description: Successful response indicating the transaction was deleted.
'401':
$ref: '#/components/schemas/401'
components:
parameters:
accessToken:
description: The access token retrieved in the Token API call
example: eyJraWQiOiIzZjVhYTFmNS1hYWE5LTQzM.....
in: header
name: WM_SEC.ACCESS_TOKEN
required: true
schema:
type: string
startDate:
description: Start date of the transaction period.
in: query
name: startDate
required: true
schema:
type: string
format: date
endDate:
description: End date of the transaction period.
in: query
name: endDate
required: true
schema:
type: string
format: date
id:
description: ID of the record you are acting upon.
in: path
name: id
required: true
schema:
type: string
schemas:
BalanceResponse:
properties:
data:
example:
bank_balance: 100
basic_balance: 2000
expiry_date: 2021-05-16
type: object
message:
example: SUCCESS
type: string
result:
example: '200'
type: integer
type: object
Transaction:
allOf:
- properties:
accountId:
description: The unique identifier of the bank account.
minLength: 1
type: string
amount:
description: The amount of the bank transaction.
type: number
authorizedDate:
$ref: '#/components/schemas/DateTime'
description: The date the bank transaction was authorized.
code:
$ref: '#/components/schemas/Transaction/definitions/transactionCode'
currency:
description: The currency of the bank transaction.
minLength: 1
type: string
description:
description: The description of the bank transaction.
nullable: true
type: string
id:
description: The unique identifier of the bank transaction.
minLength: 1
type: string
merchantName:
description: The name of the merchant.
nullable: true
type: string
postedDate:
$ref: '#/components/schemas/DateTime'
description: The date the bank transaction was cleared.
transactionCategoryRef:
$ref: '#/components/schemas/TransactionCategory/definitions/transactionCategoryRef'
type: object
- $ref: '#/components/schemas/ModifiedDates'
definitions:
transactionCode:
description: Code to identify the underlying transaction.
enum:
- Unknown
- Fee
- Payment
- Cash
- Transfer
- Interest
- Cashback
- Cheque
- DirectDebit
- Purchase
- StandingOrder
- Adjustment
- Credit
- Other
- NotSupported
type: string
x-internal: true
description: 'The Banking Transactions data type provides an immutable source
of up-to-date information on income and expenditure.
Responses are paged, so you should provide `page` and `pageSize` query parameters
in your request.
View the coverage for banking transactions in the [Data Coverage Explorer](https://knowledge.codat.io/supported-features/banking?view=tab-by-data-type&dataType=banking-transactions).'
examples:
- accountId: 1703194f-7805-4da8-bac0-2ba5da4a4216
amount: 5062.39
authorizedDate: 2021-07-06 00:00:00
currency: GBP
description: Payments for direct income ce149943-c157-43fc-aac7-42a716b655b6
id: 0130b5bb-1419-40f6-8a27-7362d0381229
merchantName: New Look
modifiedDate: 2022-05-23 16:32:50+00:00
postedDate: 2021-07-06 00:00:00
sourceModifiedDate: 2021-06-28 10:48:12
transactionCategoryRef:
id: health-and-fitness-sports
required:
- id
- accountId
- currency
title: Transaction
type: object
'400':
properties:
data:
example: '{}'
type: object
message:
example: Your balance is exhausted
type: string
result:
example: '400'
type: integer
type: object
'401':
properties:
data:
example: '{}'
type: object
message:
example: Your package has expired
type: string
result:
example: '401'
type: integer
type: object
DateTime:
description: "In Codat's data model, dates and times are represented using the\
\ <a class=\"external\" href=\"https://en.wikipedia.org/wiki/ISO_8601\" target=\"\
_blank\">ISO 8601 standard</a>. Date and time fields are formatted as strings;\
\ for example:\n\n```\n2020-10-08T22:40:50Z\n2021-01-01T00:00:00\n```\n\n\n\
\nWhen syncing data that contains `DateTime` fields from Codat, make sure\
\ you support the following cases when reading time information:\n\n- Coordinated\
\ Universal Time (UTC): `2021-11-15T06:00:00Z`\n- Unqualified local time:\
\ `2021-11-15T01:00:00`\n- UTC time offsets: `2021-11-15T01:00:00-05:00`\n\
\n> Time zones\n> \n> Not all dates from Codat will contain information about\
\ time zones. \n> Where it is not available from the underlying platform,\
\ Codat will return these as times local to the business whose data has been\
\ synced."
example: 2022-10-23 00:00:00+00:00
title: Date time
type: string
TransactionCategory:
allOf:
- description: Status of the bank transaction category.
properties:
hasChildren:
description: A Boolean indicating whether there are other bank transaction
categories beneath this one in the hierarchy.
type: boolean
id:
description: The unique identifier of the bank transaction category.
minLength: 1
type: string
name:
description: The name of the bank transaction category.
minLength: 1
type: string
parentId:
description: The unique identifier of the parent bank transaction category.
nullable: true
type: string
status:
$ref: '#/components/schemas/TransactionCategory/definitions/transactionCategoryStatus'
type: object
- $ref: '#/components/schemas/ModifiedDates'
definitions:
transactionCategoryRef:
description: An object of bank transaction category reference data.
properties:
id:
description: The unique category reference id for the bank transaction.
minLength: 1
type: string
name:
description: The category name reference for the bank transaction.
nullable: true
type: string
required:
- id
type: object
x-internal: true
transactionCategoryStatus:
enum:
- Unknown
- Active
- Archived
type: string
x-internal: true
description: 'The Banking Transaction Categories data type provides a list of
hierarchical categories associated with a transaction for greater contextual
meaning to transaction activity.
Responses are paged, so you should provide `page` and `pageSize` query parameters
in your request.'
examples:
- hasChildren: true
id: auto-and-transport
modifiedDate: 2022-05-23 16:32:50
name: Auto & Transport
sourceModifiedDate: 2021-04-24 07:59:10
status: Active
required:
- id
- name
title: Transaction Category
type: object
ModifiedDates:
allOf:
- $ref: '#/components/schemas/ModifiedDate'
- $ref: '#/components/schemas/SourceModifiedDate'
x-internal: true
ModifiedDate:
properties:
modifiedDate:
$ref: '#/components/schemas/DateTime'
description: The date on which this record was last modified in Codat.
title: ModifiedDate
type: object
x-internal: true
SourceModifiedDate:
properties:
sourceModifiedDate:
$ref: '#/components/schemas/DateTime'
description: The date on which this record was last modified in the originating
system
title: Source Modified Date
type: object
x-internal: true