Skip to content

Commit

Permalink
Clean up generator
Browse files Browse the repository at this point in the history
  • Loading branch information
tolyo committed Sep 5, 2023
1 parent 5955241 commit 6824552
Show file tree
Hide file tree
Showing 41 changed files with 538 additions and 476 deletions.
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
.PHONY: help

setup:
go install golang.org/x/tools/cmd/goimports@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/pressly/goose/v3/cmd/goose@latest
npm i
go get ./...

build: ## Installs and compiles dependencies
go build -v ./...
go install github.com/pressly/goose/v3/cmd/goose@latest

run: ## Start dev mode
go run main.go
Expand All @@ -16,9 +19,10 @@ test:
go test ./... -v -cover -p 1

lint:
@go fmt ./...
@go vet ./...
@staticcheck ./...
go fmt ./...
goimports -l -w .
staticcheck ./...
go vet ./...

include ./pkg/conf/dev.env
DBDSN:="host=$(POSTGRES_HOST) user=$(POSTGRES_USER) password=$(POSTGRES_PASSWORD) dbname=$(POSTGRES_DB) port=$(POSTGRES_PORT) sslmode=disable"
Expand Down Expand Up @@ -47,7 +51,9 @@ generate-api: ## Generate server bindings
-g go-server \
-o pkg/rest \
--additional-properties=packageName=api \
--additional-properties=sourceFolder=api
--additional-properties=sourceFolder=api \
--additional-properties=outputAsLibrary=true
$(MAKE) lint

help:
grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
Expand Down
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ require (
github.com/gorilla/mux v1.8.0
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
Expand All @@ -31,9 +29,7 @@ require (
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/tools v0.10.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
58 changes: 4 additions & 54 deletions go.sum

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions openapi/definitions/trade_order.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ components:
schemas:

TradeOrderSide:
type: enum
type: string
enum:
- SELL
- BUY

TradeOrderTimeInForce:
type: enum
type: string
enum:
- GTC
- IOC
- FOK
- GTD
- GTT

TradeOrderStatus:
type: enum
type: string
enum:
- OPEN
- REJECTED
- CANCELLED
Expand Down
13 changes: 6 additions & 7 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
openapi: 3.0.2
openapi: 3.1.0
info:
description: |
# Introduction
This API is {cumented in **OpenAPI 3.0 format**.
This API is documented in **OpenAPI 3.0 format**.
This API the following operations:
* Retrieve a list of available instruments
* 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

Expand All @@ -29,7 +28,7 @@ components:
scheme: basic
paths:
/currencies:
$ref: paths/currencies_list.yaml
$ref: ./paths/currencies_list.yaml
/instruments:
$ref: paths/instruments_list.yaml
/order_books/{instrument_name}:
Expand Down
32 changes: 15 additions & 17 deletions openapi/paths/currencies_list.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
paths:
/:
get:
tags:
- currencies
summary: currencies list
description: Returns list of available currencies
operationId: getCurrencies
responses:
"200":
description: currencies list
content:
application/json:
schema:
$ref: ../definitions/currency.yaml#/components/schemas/CurrencyList
"500":
description: Error
get:
tags:
- currencies
summary: currencies list
description: Returns list of available currencies
operationId: getCurrencies
responses:
"200":
description: currencies list
content:
application/json:
schema:
$ref: ../definitions/currency.yaml#/components/schemas/CurrencyList
"500":
description: Error
1 change: 1 addition & 0 deletions pkg/db/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db

import (
"embed"

"github.com/pressly/goose/v3"
)

Expand Down
5 changes: 1 addition & 4 deletions pkg/rest/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

# 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:
#ApiClient.cs
**/routers.go

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
Expand Down
12 changes: 3 additions & 9 deletions pkg/rest/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Dockerfile
README.md
api/api.go
api/api_currencies.go
api/api_currencies_service.go
api/api_instruments.go
api/api_instruments_service.go
api/api_order_books.go
Expand All @@ -13,12 +14,5 @@ api/error.go
api/helpers.go
api/impl.go
api/logger.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_get_order_book_200_response.go
api/openapi.yaml
api/routers.go
go.mod
main.go
15 changes: 0 additions & 15 deletions pkg/rest/Dockerfile

This file was deleted.

7 changes: 3 additions & 4 deletions pkg/rest/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Go API Server for api

# Introduction
This API is {cumented in **OpenAPI 3.0 format**.
This API is documented in **OpenAPI 3.0 format**.

This API the following operations:
* Retrieve a list of available instruments
* 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.
Expand All @@ -25,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-05T19:06:15.448226+03:00[Europe/Riga]
- Build date: 2023-09-05T22:09:37.812488+03:00[Europe/Riga]


### Running the server
Expand Down
40 changes: 26 additions & 14 deletions pkg/rest/api/api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* OPEN OUTCRY API
*
* # Introduction This API is {cumented 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.
* # 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)
Expand All @@ -14,65 +14,77 @@ import (
"net/http"
)


// CurrenciesAPIRouter defines the required methods for binding the api requests to a responses for the CurrenciesAPI
// The CurrenciesAPIRouter implementation should parse necessary information from the http request,
// pass the data to a CurrenciesAPIServicer to perform the required actions, then write the service results to the http response.
type CurrenciesAPIRouter interface {
GetCurrencies(http.ResponseWriter, *http.Request)
}

// InstrumentsAPIRouter defines the required methods for binding the api requests to a responses for the InstrumentsAPI
// The InstrumentsAPIRouter implementation should parse necessary information from the http request,
// pass the data to a InstrumentsAPIServicer to perform the required actions, then write the service results to the http response.
type InstrumentsAPIRouter interface {
type InstrumentsAPIRouter interface {
GetInstruments(http.ResponseWriter, *http.Request)
}

// OrderBooksAPIRouter defines the required methods for binding the api requests to a responses for the OrderBooksAPI
// The OrderBooksAPIRouter implementation should parse necessary information from the http request,
// pass the data to a OrderBooksAPIServicer to perform the required actions, then write the service results to the http response.
type OrderBooksAPIRouter interface {
type OrderBooksAPIRouter interface {
GetOrderBook(http.ResponseWriter, *http.Request)
}

// TradeOrderAPIRouter defines the required methods for binding the api requests to a responses for the TradeOrderAPI
// The TradeOrderAPIRouter implementation should parse necessary information from the http request,
// pass the data to a TradeOrderAPIServicer to perform the required actions, then write the service results to the http response.
type TradeOrderAPIRouter interface {
type TradeOrderAPIRouter interface {
GetTradeOrders(http.ResponseWriter, *http.Request)
}

// TradesAPIRouter defines the required methods for binding the api requests to a responses for the TradesAPI
// The TradesAPIRouter implementation should parse necessary information from the http request,
// pass the data to a TradesAPIServicer to perform the required actions, then write the service results to the http response.
type TradesAPIRouter interface {
type TradesAPIRouter interface {
GetTrades(http.ResponseWriter, *http.Request)
}

// CurrenciesAPIServicer defines the api actions for the CurrenciesAPI service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type CurrenciesAPIServicer interface {
GetCurrencies(context.Context) (ImplResponse, error)
}

// InstrumentsAPIServicer defines the api actions for the InstrumentsAPI service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type InstrumentsAPIServicer interface {
type InstrumentsAPIServicer interface {
GetInstruments(context.Context) (ImplResponse, error)
}


// OrderBooksAPIServicer defines the api actions for the OrderBooksAPI service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type OrderBooksAPIServicer interface {
GetOrderBook(context.Context, string) (ImplResponse, error)
type OrderBooksAPIServicer interface {
GetOrderBook(context.Context, interface{}) (ImplResponse, error)
}


// TradeOrderAPIServicer defines the api actions for the TradeOrderAPI service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type TradeOrderAPIServicer interface {
type TradeOrderAPIServicer interface {
GetTradeOrders(context.Context) (ImplResponse, error)
}


// TradesAPIServicer defines the api actions for the TradesAPI service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type TradesAPIServicer interface {
type TradesAPIServicer interface {
GetTrades(context.Context) (ImplResponse, error)
}
Loading

0 comments on commit 6824552

Please sign in to comment.