Skip to content

Commit

Permalink
Add redoc. Move yaml to separate folder
Browse files Browse the repository at this point in the history
  • Loading branch information
tolyo committed Nov 20, 2023
1 parent b1f68cc commit b3f9b77
Show file tree
Hide file tree
Showing 31 changed files with 601 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build stage
FROM golang:1.20 AS build
FROM golang:1.21 AS build

# Set the working directory
WORKDIR /app
Expand Down
23 changes: 16 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,39 @@ DBDSN:="host=$(POSTGRES_HOST) user=$(POSTGRES_USER) password=$(POSTGRES_PASSWORD
MIGRATE_OPTIONS=-allow-missing -dir="./pkg/db/migrations"

db-update: ## Migrate down on database
goose -v $(MIGRATE_OPTIONS) postgres $(DBDSN) up
@goose -v $(MIGRATE_OPTIONS) postgres $(DBDSN) up

db-downgrade: ## Migrate up on database
echo "$(MIGRATE_OPTIONS)"
goose -v $(MIGRATE_OPTIONS) postgres $(DBDSN) reset
@goose -v $(MIGRATE_OPTIONS) postgres $(DBDSN) reset

db-rebuild: ## Reset the database
$(MAKE) db-downgrade
$(MAKE) db-update
@make db-downgrade
@make db-update

validate-api: ## Validate api
npx @openapitools/openapi-generator-cli validate \
-i pkg/openapi.yaml \
--recommend

bundle-api:
@npx @redocly/cli bundle \
pkg/api/openapi.yaml \
--output ./pkg/api.yaml \

validate-api:
@npx @redocly/cli lint \
./pkg/api.yaml \
--format=checkstyle

generate-api: ## Generate server bindings, move model files, fix imports
npx @openapitools/openapi-generator-cli generate \
-i pkg/openapi.yaml \
-i pkg/api.yaml \
-g go-server \
-o pkg/rest \
--additional-properties=packageName=api \
--additional-properties=sourceFolder=api \
--additional-properties=outputAsLibrary=true
$(MAKE) lint
@make lint

help:
grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"private": true,
"scripts": {},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.7.0"
"@openapitools/openapi-generator-cli": "^2.7.0",
"@redocly/cli": "^1.4.1"
}
}
221 changes: 221 additions & 0 deletions pkg/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
openapi: 3.1.0
info:
description: |
# Introduction
This API is documented in **OpenAPI 3.0 format**.
This API the following operations:
* Retrieve a list of available instruments
* Retrieve a list of executed trades
# Basics
* API calls have to be secured with HTTPS.
* All data has to be submitted UTF-8 encoded.
* The reply is sent JSON encoded.
version: 1.0.0
title: OPEN OUTCRY API
servers:
- url: https://your.public.url
security:
- basicAuth: []
paths:
/currencies:
get:
tags:
- currencies
summary: currencies list
description: Returns list of available currencies
operationId: getCurrencies
responses:
'200':
description: currencies list
content:
application/json:
schema:
$ref: '#/components/schemas/CurrencyList'
'500':
description: Error
/instruments:
get:
tags:
- instruments
summary: instrument list
description: Returns list of available instruments
operationId: getInstruments
responses:
'200':
description: instruments list
content:
application/json:
schema:
$ref: '#/components/schemas/InstrumentList'
'500':
description: Error
/order_books/{instrument_name}:
get:
tags:
- order_books
summary: get order books
description: Return an order book for an instrument
operationId: getOrderBook
parameters:
- in: path
name: instrument_name
required: true
schema:
$ref: '#/components/schemas/InstrumentName'
responses:
'200':
description: order book
content:
application/json:
schema:
$ref: '#/components/schemas/OrderBook'
'500':
description: Error
/trades:
get:
tags:
- trades
summary: trades list
description: Returns list of user's trades
operationId: getTrades
responses:
'200':
description: trades list
content:
application/json:
schema:
$ref: '#/components/schemas/TradeList'
'500':
description: Error
/trade_orders:
get:
tags:
- trade_order
summary: trade order list
description: Returns list of user's active trade orders
operationId: getTradeOrders
responses:
'200':
description: trades orders list
content:
application/json:
schema:
$ref: '#/components/schemas/TradeOrderList'
'500':
description: Error
components:
securitySchemes:
basicAuth:
type: http
scheme: basic
schemas:
CurrencyName:
type: string
description: ISO 4217 Currency symbol
example: USD
Currency:
type: object
description: Currency of payment account
properties:
name:
$ref: '#/components/schemas/CurrencyName'
precision:
type: integer
description: Currency precision as number of decimal points
example: 2
CurrencyList:
type: array
description: List of currencies supported by app
items:
$ref: '#/components/schemas/Currency'
Id:
type: string
format: uuid
InstrumentName:
type: string
description: Ticker-like name of the instrument. For monetary instruments, a currency pair is used.
Instrument:
type: object
properties:
id:
$ref: '#/components/schemas/Id'
name:
$ref: '#/components/schemas/InstrumentName'
base_currency:
$ref: '#/components/schemas/CurrencyName'
quote_currency:
$ref: '#/components/schemas/CurrencyName'
enabled:
type: boolean
description: Availability for trading
InstrumentList:
type: array
items:
$ref: '#/components/schemas/Instrument'
PriceVolume:
type: object
properties:
price:
type: number
volume:
type: number
OrderBook:
type: object
properties:
sell:
type: array
items:
$ref: '#/components/schemas/PriceVolume'
buy:
type: array
items:
$ref: '#/components/schemas/PriceVolume'
Trade:
type: object
description: Execute trade
properties:
id:
$ref: '#/components/schemas/Id'
TradeList:
type: array
description: List of executed trades
items:
$ref: '#/components/schemas/Trade'
TradeOrderSide:
type: string
enum:
- SELL
- BUY
TradeOrderTimeInForce:
type: string
enum:
- GTC
- IOC
- FOK
- GTD
- GTT
TradeOrderStatus:
type: string
enum:
- OPEN
- REJECTED
- CANCELLED
TradeOrder:
type: object
properties:
id:
$ref: '#/components/schemas/Id'
instrument:
$ref: '#/components/schemas/InstrumentName'
side:
$ref: '#/components/schemas/TradeOrderSide'
timeInForce:
$ref: '#/components/schemas/TradeOrderTimeInForce'
status:
$ref: '#/components/schemas/TradeOrderStatus'
TradeOrderList:
type: array
items:
$ref: '#/components/schemas/TradeOrder'
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ get:
content:
application/json:
schema:
$ref: ../../models/currency.yaml#/components/schemas/CurrencyList
$ref: ../models/currency.yaml#/components/schemas/CurrencyList
"500":
description: Error
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ get:
content:
application/json:
schema:
$ref: ../../models/instrument.yaml#/components/schemas/InstrumentList
$ref: ../models/instrument.yaml#/components/schemas/InstrumentList
"500":
description: Error
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ get:
name: instrument_name
required: true
schema:
$ref: '../../models/instrument.yaml#/components/schemas/InstrumentName'
$ref: '../models/instrument.yaml#/components/schemas/InstrumentName'

responses:
"200":
description: order book
content:
application/json:
schema:
$ref: '../../models/order_book.yaml#/components/schemas/OrderBook'
$ref: '../models/order_book.yaml#/components/schemas/OrderBook'
"500":
description: Error
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ get:
content:
application/json:
schema:
$ref: ../../models/trade_order.yaml#/components/schemas/TradeOrderList
$ref: ../models/trade_order.yaml#/components/schemas/TradeOrderList
"500":
description: Error
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ get:
content:
application/json:
schema:
$ref: '../../models/trade.yaml#/components/schemas/TradeList'
$ref: '../models/trade.yaml#/components/schemas/TradeList'
"500":
description: Error
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions pkg/openapi.yaml → pkg/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ components:
scheme: basic
paths:
/currencies:
$ref: ./rest/api/currencies_list.yaml
$ref: ./endpoints/currencies_list.yaml
/instruments:
$ref: ./rest/api/instruments_list.yaml
$ref: ./endpoints/instruments_list.yaml
/order_books/{instrument_name}:
$ref: ./rest/api/order_books.yaml
$ref: ./endpoints/order_books.yaml
/trades:
$ref: ./rest/api/trades_list.yaml
$ref: ./endpoints/trades_list.yaml
/trade_orders:
$ref: ./rest/api/trade_orders_list.yaml
$ref: ./endpoints/trade_orders_list.yaml
10 changes: 9 additions & 1 deletion pkg/rest/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ api/error.go
api/helpers.go
api/impl.go
api/logger.go
api/model_get_order_book_200_response.go
api/model_currency.go
api/model_instrument.go
api/model_order_book.go
api/model_price_volume.go
api/model_trade.go
api/model_trade_order.go
api/model_trade_order_side.go
api/model_trade_order_status.go
api/model_trade_order_time_in_force.go
api/openapi.yaml
2 changes: 1 addition & 1 deletion pkg/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To see how to make this your own, look here:
[README](https://openapi-generator.tech)

- API version: 1.0.0
- Build date: 2023-09-05T23:22:31.538915+03:00[Europe/Riga]
- Build date: 2023-11-20T22:33:35.531021+02:00[Europe/Riga]


### Running the server
Expand Down
4 changes: 2 additions & 2 deletions pkg/rest/api/api_order_books_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (s *OrderBooksAPIService) GetOrderBook(ctx context.Context, instrumentName
// TODO - update GetOrderBook with the required logic for this service method.
// Add api_order_books_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.

// TODO: Uncomment the next line to return response Response(200, GetOrderBook200Response{}) or use other options such as http.Ok ...
// return Response(200, GetOrderBook200Response{}), nil
// TODO: Uncomment the next line to return response Response(200, OrderBook{}) or use other options such as http.Ok ...
// return Response(200, OrderBook{}), nil

// TODO: Uncomment the next line to return response Response(500, {}) or use other options such as http.Ok ...
// return Response(500, nil),nil
Expand Down
Loading

0 comments on commit b3f9b77

Please sign in to comment.