From b1f68cc0ed579ece4d640cf0f490bc2f813b4acb Mon Sep 17 00:00:00 2001 From: tolyo Date: Tue, 5 Sep 2023 23:23:22 +0300 Subject: [PATCH] Reorganize YAML --- Makefile | 15 ++++---- .../definitions => pkg/models}/currency.yaml | 0 .../models}/instrument.yaml | 0 .../models}/order_book.yaml | 0 .../definitions => pkg/models}/shared.yaml | 0 .../definitions => pkg/models}/trade.yaml | 0 .../models}/trade_order.yaml | 0 .../models}/trading_account.yaml | 0 {openapi => pkg}/openapi.yaml | 10 +++--- pkg/rest/.openapi-generator-ignore | 3 ++ pkg/rest/README.md | 2 +- .../rest/api}/currencies_list.yaml | 2 +- .../rest/api}/instruments_list.yaml | 2 +- pkg/rest/api/model_instrument.go | 36 ------------------- pkg/rest/api/model_order_book.go | 36 ------------------- pkg/rest/api/model_price_volume.go | 26 -------------- pkg/rest/api/model_trade.go | 25 ------------- pkg/rest/api/model_trade_order.go | 33 ----------------- pkg/rest/api/model_trade_order_side.go | 28 --------------- pkg/rest/api/model_trade_order_status.go | 29 --------------- .../api/model_trade_order_time_in_force.go | 31 ---------------- .../paths => pkg/rest/api}/order_books.yaml | 4 +-- .../rest/api}/trade_orders_list.yaml | 2 +- .../paths => pkg/rest/api}/trades_list.yaml | 2 +- 24 files changed, 22 insertions(+), 264 deletions(-) rename {openapi/definitions => pkg/models}/currency.yaml (100%) rename {openapi/definitions => pkg/models}/instrument.yaml (100%) rename {openapi/definitions => pkg/models}/order_book.yaml (100%) rename {openapi/definitions => pkg/models}/shared.yaml (100%) rename {openapi/definitions => pkg/models}/trade.yaml (100%) rename {openapi/definitions => pkg/models}/trade_order.yaml (100%) rename {openapi/definitions => pkg/models}/trading_account.yaml (100%) rename {openapi => pkg}/openapi.yaml (76%) rename {openapi/paths => pkg/rest/api}/currencies_list.yaml (78%) rename {openapi/paths => pkg/rest/api}/instruments_list.yaml (77%) delete mode 100644 pkg/rest/api/model_instrument.go delete mode 100644 pkg/rest/api/model_order_book.go delete mode 100644 pkg/rest/api/model_price_volume.go delete mode 100644 pkg/rest/api/model_trade.go delete mode 100644 pkg/rest/api/model_trade_order.go delete mode 100644 pkg/rest/api/model_trade_order_side.go delete mode 100644 pkg/rest/api/model_trade_order_status.go delete mode 100644 pkg/rest/api/model_trade_order_time_in_force.go rename {openapi/paths => pkg/rest/api}/order_books.yaml (70%) rename {openapi/paths => pkg/rest/api}/trade_orders_list.yaml (78%) rename {openapi/paths => pkg/rest/api}/trades_list.yaml (77%) diff --git a/Makefile b/Makefile index 76337e8..028e178 100644 --- a/Makefile +++ b/Makefile @@ -39,15 +39,14 @@ db-rebuild: ## Reset the database $(MAKE) db-downgrade $(MAKE) db-update -build-api: ## Build OpenAPI - node node_modules/swagger-cli/swagger-cli.js bundle --dereference \ - -o pkg/static/docs/api/openapi.json \ - -t json \ - -r openapi/openapi.yaml +validate-api: ## Validate api + npx @openapitools/openapi-generator-cli validate \ + -i pkg/openapi.yaml \ + --recommend -generate-api: ## Generate server bindings +generate-api: ## Generate server bindings, move model files, fix imports npx @openapitools/openapi-generator-cli generate \ - -i openapi/openapi.yaml \ + -i pkg/openapi.yaml \ -g go-server \ -o pkg/rest \ --additional-properties=packageName=api \ @@ -57,4 +56,4 @@ generate-api: ## Generate server bindings help: grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ - | sed -n 's/^\(.*\): \(.*\)##\(.*\)/\1\3/p' \ No newline at end of file + | sed -n 's/^\(.*\): \(.*\)##\(.*\)/\1\3/p' diff --git a/openapi/definitions/currency.yaml b/pkg/models/currency.yaml similarity index 100% rename from openapi/definitions/currency.yaml rename to pkg/models/currency.yaml diff --git a/openapi/definitions/instrument.yaml b/pkg/models/instrument.yaml similarity index 100% rename from openapi/definitions/instrument.yaml rename to pkg/models/instrument.yaml diff --git a/openapi/definitions/order_book.yaml b/pkg/models/order_book.yaml similarity index 100% rename from openapi/definitions/order_book.yaml rename to pkg/models/order_book.yaml diff --git a/openapi/definitions/shared.yaml b/pkg/models/shared.yaml similarity index 100% rename from openapi/definitions/shared.yaml rename to pkg/models/shared.yaml diff --git a/openapi/definitions/trade.yaml b/pkg/models/trade.yaml similarity index 100% rename from openapi/definitions/trade.yaml rename to pkg/models/trade.yaml diff --git a/openapi/definitions/trade_order.yaml b/pkg/models/trade_order.yaml similarity index 100% rename from openapi/definitions/trade_order.yaml rename to pkg/models/trade_order.yaml diff --git a/openapi/definitions/trading_account.yaml b/pkg/models/trading_account.yaml similarity index 100% rename from openapi/definitions/trading_account.yaml rename to pkg/models/trading_account.yaml diff --git a/openapi/openapi.yaml b/pkg/openapi.yaml similarity index 76% rename from openapi/openapi.yaml rename to pkg/openapi.yaml index a18fb28..68adc92 100644 --- a/openapi/openapi.yaml +++ b/pkg/openapi.yaml @@ -28,12 +28,12 @@ components: scheme: basic paths: /currencies: - $ref: ./paths/currencies_list.yaml + $ref: ./rest/api/currencies_list.yaml /instruments: - $ref: paths/instruments_list.yaml + $ref: ./rest/api/instruments_list.yaml /order_books/{instrument_name}: - $ref: paths/order_books.yaml + $ref: ./rest/api/order_books.yaml /trades: - $ref: paths/trades_list.yaml + $ref: ./rest/api/trades_list.yaml /trade_orders: - $ref: paths/trade_orders_list.yaml + $ref: ./rest/api/trade_orders_list.yaml diff --git a/pkg/rest/.openapi-generator-ignore b/pkg/rest/.openapi-generator-ignore index efb30c3..19f3b1e 100644 --- a/pkg/rest/.openapi-generator-ignore +++ b/pkg/rest/.openapi-generator-ignore @@ -3,6 +3,9 @@ # Use this file to prevent files from being overwritten by the generator. # The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: **/routers.go # You can match any string of characters against a directory, file or extension with a single asterisk (*): diff --git a/pkg/rest/README.md b/pkg/rest/README.md index 8baba13..2ad018e 100644 --- a/pkg/rest/README.md +++ b/pkg/rest/README.md @@ -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-05T22:09:37.812488+03:00[Europe/Riga] +- Build date: 2023-09-05T23:22:31.538915+03:00[Europe/Riga] ### Running the server diff --git a/openapi/paths/currencies_list.yaml b/pkg/rest/api/currencies_list.yaml similarity index 78% rename from openapi/paths/currencies_list.yaml rename to pkg/rest/api/currencies_list.yaml index 8a9e162..8ed5906 100644 --- a/openapi/paths/currencies_list.yaml +++ b/pkg/rest/api/currencies_list.yaml @@ -10,6 +10,6 @@ get: content: application/json: schema: - $ref: ../definitions/currency.yaml#/components/schemas/CurrencyList + $ref: ../../models/currency.yaml#/components/schemas/CurrencyList "500": description: Error diff --git a/openapi/paths/instruments_list.yaml b/pkg/rest/api/instruments_list.yaml similarity index 77% rename from openapi/paths/instruments_list.yaml rename to pkg/rest/api/instruments_list.yaml index 7002797..f2b809f 100644 --- a/openapi/paths/instruments_list.yaml +++ b/pkg/rest/api/instruments_list.yaml @@ -10,6 +10,6 @@ get: content: application/json: schema: - $ref: ../definitions/instrument.yaml#/components/schemas/InstrumentList + $ref: ../../models/instrument.yaml#/components/schemas/InstrumentList "500": description: Error diff --git a/pkg/rest/api/model_instrument.go b/pkg/rest/api/model_instrument.go deleted file mode 100644 index 1ca753f..0000000 --- a/pkg/rest/api/model_instrument.go +++ /dev/null @@ -1,36 +0,0 @@ -/* - * OPEN OUTCRY API - * - * # 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. - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package api - -type Instrument struct { - Id string `json:"id,omitempty"` - - // Ticker-like name of the instrument. For monetary instruments, a currency pair is used. - Name string `json:"name,omitempty"` - - // ISO 4217 Currency symbol - BaseCurrency string `json:"base_currency,omitempty"` - - // ISO 4217 Currency symbol - QuoteCurrency string `json:"quote_currency,omitempty"` - - // Availability for trading - Enabled bool `json:"enabled,omitempty"` -} - -// AssertInstrumentRequired checks if the required fields are not zero-ed -func AssertInstrumentRequired(obj Instrument) error { - return nil -} - -// AssertInstrumentConstraints checks if the values respects the defined constraints -func AssertInstrumentConstraints(obj Instrument) error { - return nil -} diff --git a/pkg/rest/api/model_order_book.go b/pkg/rest/api/model_order_book.go deleted file mode 100644 index 7542b9d..0000000 --- a/pkg/rest/api/model_order_book.go +++ /dev/null @@ -1,36 +0,0 @@ -/* - * OPEN OUTCRY API - * - * # 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. - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package api - -type OrderBook struct { - Sell []PriceVolume `json:"sell,omitempty"` - - Buy []PriceVolume `json:"buy,omitempty"` -} - -// AssertOrderBookRequired checks if the required fields are not zero-ed -func AssertOrderBookRequired(obj OrderBook) error { - for _, el := range obj.Sell { - if err := AssertPriceVolumeRequired(el); err != nil { - return err - } - } - for _, el := range obj.Buy { - if err := AssertPriceVolumeRequired(el); err != nil { - return err - } - } - return nil -} - -// AssertOrderBookConstraints checks if the values respects the defined constraints -func AssertOrderBookConstraints(obj OrderBook) error { - return nil -} diff --git a/pkg/rest/api/model_price_volume.go b/pkg/rest/api/model_price_volume.go deleted file mode 100644 index ffea120..0000000 --- a/pkg/rest/api/model_price_volume.go +++ /dev/null @@ -1,26 +0,0 @@ -/* - * OPEN OUTCRY API - * - * # 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. - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package api - -type PriceVolume struct { - Price float32 `json:"price,omitempty"` - - Volume float32 `json:"volume,omitempty"` -} - -// AssertPriceVolumeRequired checks if the required fields are not zero-ed -func AssertPriceVolumeRequired(obj PriceVolume) error { - return nil -} - -// AssertPriceVolumeConstraints checks if the values respects the defined constraints -func AssertPriceVolumeConstraints(obj PriceVolume) error { - return nil -} diff --git a/pkg/rest/api/model_trade.go b/pkg/rest/api/model_trade.go deleted file mode 100644 index 324e56b..0000000 --- a/pkg/rest/api/model_trade.go +++ /dev/null @@ -1,25 +0,0 @@ -/* - * OPEN OUTCRY API - * - * # 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. - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package api - -// Trade - Execute trade -type Trade struct { - Id string `json:"id,omitempty"` -} - -// AssertTradeRequired checks if the required fields are not zero-ed -func AssertTradeRequired(obj Trade) error { - return nil -} - -// AssertTradeConstraints checks if the values respects the defined constraints -func AssertTradeConstraints(obj Trade) error { - return nil -} diff --git a/pkg/rest/api/model_trade_order.go b/pkg/rest/api/model_trade_order.go deleted file mode 100644 index 08cc510..0000000 --- a/pkg/rest/api/model_trade_order.go +++ /dev/null @@ -1,33 +0,0 @@ -/* - * OPEN OUTCRY API - * - * # 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. - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package api - -type TradeOrder struct { - Id string `json:"id,omitempty"` - - // Ticker-like name of the instrument. For monetary instruments, a currency pair is used. - Instrument string `json:"instrument,omitempty"` - - Side TradeOrderSide `json:"side,omitempty"` - - TimeInForce TradeOrderTimeInForce `json:"timeInForce,omitempty"` - - Status TradeOrderStatus `json:"status,omitempty"` -} - -// AssertTradeOrderRequired checks if the required fields are not zero-ed -func AssertTradeOrderRequired(obj TradeOrder) error { - return nil -} - -// AssertTradeOrderConstraints checks if the values respects the defined constraints -func AssertTradeOrderConstraints(obj TradeOrder) error { - return nil -} diff --git a/pkg/rest/api/model_trade_order_side.go b/pkg/rest/api/model_trade_order_side.go deleted file mode 100644 index ee71c59..0000000 --- a/pkg/rest/api/model_trade_order_side.go +++ /dev/null @@ -1,28 +0,0 @@ -/* - * OPEN OUTCRY API - * - * # 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. - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package api - -type TradeOrderSide string - -// List of TradeOrderSide -const ( - SELL TradeOrderSide = "SELL" - BUY TradeOrderSide = "BUY" -) - -// AssertTradeOrderSideRequired checks if the required fields are not zero-ed -func AssertTradeOrderSideRequired(obj TradeOrderSide) error { - return nil -} - -// AssertTradeOrderSideConstraints checks if the values respects the defined constraints -func AssertTradeOrderSideConstraints(obj TradeOrderSide) error { - return nil -} diff --git a/pkg/rest/api/model_trade_order_status.go b/pkg/rest/api/model_trade_order_status.go deleted file mode 100644 index 41b62a7..0000000 --- a/pkg/rest/api/model_trade_order_status.go +++ /dev/null @@ -1,29 +0,0 @@ -/* - * OPEN OUTCRY API - * - * # 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. - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package api - -type TradeOrderStatus string - -// List of TradeOrderStatus -const ( - OPEN TradeOrderStatus = "OPEN" - REJECTED TradeOrderStatus = "REJECTED" - CANCELLED TradeOrderStatus = "CANCELLED" -) - -// AssertTradeOrderStatusRequired checks if the required fields are not zero-ed -func AssertTradeOrderStatusRequired(obj TradeOrderStatus) error { - return nil -} - -// AssertTradeOrderStatusConstraints checks if the values respects the defined constraints -func AssertTradeOrderStatusConstraints(obj TradeOrderStatus) error { - return nil -} diff --git a/pkg/rest/api/model_trade_order_time_in_force.go b/pkg/rest/api/model_trade_order_time_in_force.go deleted file mode 100644 index 096e2aa..0000000 --- a/pkg/rest/api/model_trade_order_time_in_force.go +++ /dev/null @@ -1,31 +0,0 @@ -/* - * OPEN OUTCRY API - * - * # 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. - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package api - -type TradeOrderTimeInForce string - -// List of TradeOrderTimeInForce -const ( - GTC TradeOrderTimeInForce = "GTC" - IOC TradeOrderTimeInForce = "IOC" - FOK TradeOrderTimeInForce = "FOK" - GTD TradeOrderTimeInForce = "GTD" - GTT TradeOrderTimeInForce = "GTT" -) - -// AssertTradeOrderTimeInForceRequired checks if the required fields are not zero-ed -func AssertTradeOrderTimeInForceRequired(obj TradeOrderTimeInForce) error { - return nil -} - -// AssertTradeOrderTimeInForceConstraints checks if the values respects the defined constraints -func AssertTradeOrderTimeInForceConstraints(obj TradeOrderTimeInForce) error { - return nil -} diff --git a/openapi/paths/order_books.yaml b/pkg/rest/api/order_books.yaml similarity index 70% rename from openapi/paths/order_books.yaml rename to pkg/rest/api/order_books.yaml index 118f4f5..234f60d 100644 --- a/openapi/paths/order_books.yaml +++ b/pkg/rest/api/order_books.yaml @@ -9,7 +9,7 @@ get: name: instrument_name required: true schema: - $ref: '../definitions/instrument.yaml#/components/schemas/InstrumentName' + $ref: '../../models/instrument.yaml#/components/schemas/InstrumentName' responses: "200": @@ -17,6 +17,6 @@ get: content: application/json: schema: - $ref: '../definitions/order_book.yaml#/components/schemas/OrderBook' + $ref: '../../models/order_book.yaml#/components/schemas/OrderBook' "500": description: Error diff --git a/openapi/paths/trade_orders_list.yaml b/pkg/rest/api/trade_orders_list.yaml similarity index 78% rename from openapi/paths/trade_orders_list.yaml rename to pkg/rest/api/trade_orders_list.yaml index 3a536e8..1372f24 100644 --- a/openapi/paths/trade_orders_list.yaml +++ b/pkg/rest/api/trade_orders_list.yaml @@ -10,6 +10,6 @@ get: content: application/json: schema: - $ref: ../definitions/trade_order.yaml#/components/schemas/TradeOrderList + $ref: ../../models/trade_order.yaml#/components/schemas/TradeOrderList "500": description: Error diff --git a/openapi/paths/trades_list.yaml b/pkg/rest/api/trades_list.yaml similarity index 77% rename from openapi/paths/trades_list.yaml rename to pkg/rest/api/trades_list.yaml index 61c387e..5511b6b 100644 --- a/openapi/paths/trades_list.yaml +++ b/pkg/rest/api/trades_list.yaml @@ -10,6 +10,6 @@ get: content: application/json: schema: - $ref: '../definitions/trade.yaml#/components/schemas/TradeList' + $ref: '../../models/trade.yaml#/components/schemas/TradeList' "500": description: Error