Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ _testmain.go
_*
.env
*.jar
main
main
2 changes: 2 additions & 0 deletions codegen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
openapi-generator-cli.jar
metabase/*
5 changes: 5 additions & 0 deletions codegen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Generate Go classes

To generate go classes, you need to have Java, curl and go.

In this folder, update `swagger_spec.yaml` file to add new entry, then run `./openapi-generator-command.sh`.
33 changes: 30 additions & 3 deletions codegen/openapi-generator-command.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
#perl -p -i -e 's/\s+\[Beta\]\s*$/\n/g' swagger_spec.yaml
java -jar openapi-generator-cli.jar generate -i swagger_spec.yaml -g go -o metabase -D packageName=metabase
perl -p -i -e 's/(\[\]\[\]\S+)/[][]interface{}/g' metabase/model_dataset_query_results_data.go
echo "\n\nfunc (apiClient *APIClient) HTTPClient() *http.Client { return apiClient.cfg.HTTPClient }" >> metabase/client.go

if ! command -v java &> /dev/null
then
echo "You must install Java before run this script"
exit
fi

if [ ! -f openapi-generator-cli.jar ]; then
curl --output openapi-generator-cli.jar -L https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/6.6.0/openapi-generator-cli-6.6.0.jar
fi

#GITHUB_PATH="$(git config --get remote.origin.url | cut -d : -f 2)"
GITHUB_USER=grokify #"$(echo "${GITHUB_PATH}" | cut -d / -f 1)"
GITHUB_REPO_NAME=go-metabase #"$(echo "${GITHUB_PATH}" | cut -d / -f 2 | sed 's/.git//')"

java -jar openapi-generator-cli.jar generate \
-i swagger_spec.yaml \
-g go \
-o metabase \
--git-repo-id "${GITHUB_REPO_NAME}" \
--git-user-id "${GITHUB_USER}" \
--additional-properties=packageName=metabase
# perl -p -i -e 's/(\[\]\[\]\S+)/[][]interface{}/g' metabase/model_dataset_query_results_data.go
echo -e "\n\nfunc (apiClient *APIClient) HTTPClient() *http.Client { return apiClient.cfg.HTTPClient }" >> metabase/client.go
gofmt -s -w metabase/*.go

rm -rf metabase/test
rm -f metabase/go.*
rm -f metabase/git_push.sh
rm -rf ../metabase
mv metabase ../
6 changes: 5 additions & 1 deletion codegen/swagger_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ components:
items:
type: array
items:
type: object
oneOf:
- string
- number
- integer
- boolean
#$ref: '#/components/schemas/ArrayString'
native_form:
$ref: '#/components/schemas/DatasetQueryResultsNativeForm'
Expand Down
9 changes: 4 additions & 5 deletions examples/database_list/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"os"

"github.com/antihax/optional"
"github.com/jessevdk/go-flags"

"github.com/grokify/go-metabase/metabase"
Expand Down Expand Up @@ -65,11 +64,11 @@ func main() {
}

func printDatabaseList(apiClient *metabase.APIClient, verbose bool) error {
opts := metabase.ListDatabasesOpts{
IncludeTables: optional.NewBool(true)}

info, resp, err := apiClient.DatabaseApi.ListDatabases(
context.Background(), &opts)
request := apiClient.DatabaseApi.ListDatabases(context.Background())
request.IncludeTables(true)

info, resp, err := apiClient.DatabaseApi.ListDatabasesExecute(request)
if err != nil {
return err
} else if resp.StatusCode >= 300 {
Expand Down
23 changes: 14 additions & 9 deletions examples/dataset_query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,25 @@ func main() {

databaseId := int64(3)
sourceTableId := int64(656)

requestType := "query"
queryPage := int64(1)
queryItems := int64(2000)
maxResult := int64(10000)
opts := metabase.DatasetQueryJsonQuery{
Database: databaseId,
Type: "query",
Query: metabase.DatasetQueryDsl{
SourceTable: sourceTableId,
Page: metabase.DatasetQueryDslPage{Page: int64(1), Items: int64(2000)},
Database: &databaseId,
Type: &requestType,
Query: &metabase.DatasetQueryDsl{
SourceTable: &sourceTableId,
Page: &metabase.DatasetQueryDslPage{Page: &queryPage, Items: &queryItems},
},
Constraints: metabase.DatasetQueryConstraints{MaxResults: 10000},
Constraints: &metabase.DatasetQueryConstraints{MaxResults: &maxResult},
}

request := apiClient.DatasetApi.QueryDatabase(context.Background())
request.DatasetQueryJsonQuery(opts)

if 1 == 1 {
info, resp, err := apiClient.DatasetApi.QueryDatabase(
context.Background(), opts)
info, resp, err := apiClient.DatasetApi.QueryDatabaseExecute(request)
if err != nil {
log.Fatal(err)
} else if resp.StatusCode >= 300 {
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
require (
github.com/buger/jsonparser v1.1.1 // indirect
github.com/caarlos0/env/v6 v6.10.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
Expand All @@ -27,9 +28,11 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/rs/zerolog v1.29.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
github.com/valyala/quicktemplate v1.7.0 // indirect
Expand All @@ -45,4 +48,5 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/oleiade/reflections.v1 v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.30.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus=
Expand Down
56 changes: 56 additions & 0 deletions metabase/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.gitignore
.openapi-generator-ignore
.travis.yml
README.md
api/openapi.yaml
api_database.go
api_dataset.go
client.go
configuration.go
docs/Database.md
docs/DatabaseApi.md
docs/DatabaseDetails.md
docs/DatabaseTable.md
docs/DatasetApi.md
docs/DatasetQueryConstraints.md
docs/DatasetQueryDsl.md
docs/DatasetQueryDslPage.md
docs/DatasetQueryJsonQuery.md
docs/DatasetQueryNative.md
docs/DatasetQueryOpts.md
docs/DatasetQueryResults.md
docs/DatasetQueryResultsCol.md
docs/DatasetQueryResultsColFingerprint.md
docs/DatasetQueryResultsColFingerprintGlobal.md
docs/DatasetQueryResultsColFingerprintType.md
docs/DatasetQueryResultsColTarget.md
docs/DatasetQueryResultsData.md
docs/DatasetQueryResultsMetadata.md
docs/DatasetQueryResultsMetadataColumn.md
docs/DatasetQueryResultsNativeForm.md
git_push.sh
go.mod
go.sum
model_database.go
model_database_details.go
model_database_table.go
model_dataset_query_constraints.go
model_dataset_query_dsl.go
model_dataset_query_dsl_page.go
model_dataset_query_json_query.go
model_dataset_query_native.go
model_dataset_query_opts.go
model_dataset_query_results.go
model_dataset_query_results_col.go
model_dataset_query_results_col_fingerprint.go
model_dataset_query_results_col_fingerprint_global.go
model_dataset_query_results_col_fingerprint_type.go
model_dataset_query_results_col_target.go
model_dataset_query_results_data.go
model_dataset_query_results_metadata.go
model_dataset_query_results_metadata_column.go
model_dataset_query_results_native_form.go
response.go
test/api_database_test.go
test/api_dataset_test.go
utils.go
2 changes: 1 addition & 1 deletion metabase/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0-SNAPSHOT
6.6.0
74 changes: 69 additions & 5 deletions metabase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,63 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
## Installation

Install the following dependencies:
```

```shell
go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context
go get github.com/antihax/optional
```

Put the package under your project folder and add the following in import:

```golang
import metabase "github.com/grokify/go-metabase"
```

To use a proxy, set the environment variable `HTTP_PROXY`:

```golang
import "./metabase"
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
```

## Configuration of Server URL

Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification.

### Select Server Configuration

For using other server than the one defined on index 0 set context value `sw.ContextServerIndex` of type `int`.

```golang
ctx := context.WithValue(context.Background(), metabase.ContextServerIndex, 1)
```

### Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value `sw.ContextServerVariables` of type `map[string]string`.

```golang
ctx := context.WithValue(context.Background(), metabase.ContextServerVariables, map[string]string{
"basePath": "v2",
})
```

Note, enum values are always validated and all unused variables are silently ignored.

### URLs Configuration per Operation

Each operation can use different server URL defined using `OperationServers` map in the `Configuration`.
An operation is uniquely identified by `"{classname}Service.{nickname}"` string.
Similar rules for overriding default operation server index and variables applies by using `sw.ContextOperationServerIndices` and `sw.ContextOperationServerVariables` context maps.

```golang
ctx := context.WithValue(context.Background(), metabase.ContextOperationServerIndices, map[string]int{
"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), metabase.ContextOperationServerVariables, map[string]map[string]string{
"{classname}Service.{nickname}": {
"port": "8443",
},
})
```

## Documentation for API Endpoints
Expand Down Expand Up @@ -58,8 +105,25 @@ Class | Method | HTTP request | Description


## Documentation For Authorization
Endpoints do not require authorization.

Endpoints do not require authorization.


## Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains
a number of utility functions to easily obtain pointers to values of basic types.
Each of these functions takes a value of the given basic type and returns a pointer to it:

* `PtrBool`
* `PtrInt`
* `PtrInt32`
* `PtrInt64`
* `PtrFloat`
* `PtrFloat32`
* `PtrFloat64`
* `PtrString`
* `PtrTime`

## Author

Expand Down
Loading