diff --git a/.gitattributes b/.gitattributes new file mode 100755 index 0000000..e6a9944 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# This allows generated code to be indexed correctly +*.go linguist-generated=false \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..d3c2f59 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +# .gitignore diff --git a/README.md b/README.md index 7ae1e9d..d0955e0 100755 --- a/README.md +++ b/README.md @@ -19,30 +19,31 @@ go get github.com/fabra-io/go-sdk ```go package main -import( +import ( "context" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" "log" - "github.com/fabra-io/go-sdk" - "github.com/fabra-io/go-sdk/pkg/models/operations" ) func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Connection.GetNamespaces(ctx, 548814) - if err != nil { - log.Fatal(err) - } - - if res.Namespaces != nil { - // handle response - } + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + var connectionID int64 = 995455 + + ctx := context.Background() + res, err := s.Connection.GetNamespaces(ctx, connectionID) + if err != nil { + log.Fatal(err) + } + + if res.Namespaces != nil { + // handle response + } } + ``` @@ -50,35 +51,67 @@ func main() { ## Available Resources and Operations -### [Connection](docs/connection/README.md) +### [Connection](docs/sdks/connection/README.md) + +* [GetNamespaces](docs/sdks/connection/README.md#getnamespaces) - Get all namespaces +* [GetSchema](docs/sdks/connection/README.md#getschema) - Get schema for table +* [GetTables](docs/sdks/connection/README.md#gettables) - Get all tables + +### [CustomerData](docs/sdks/customerdata/README.md) -* [GetNamespaces](docs/connection/README.md#getnamespaces) - Get all namespaces -* [GetSchema](docs/connection/README.md#getschema) - Get schema for table -* [GetTables](docs/connection/README.md#gettables) - Get all tables +* [QueryObject](docs/sdks/customerdata/README.md#queryobject) - Query object record for customer -### [Destination](docs/destination/README.md) +### [Destination](docs/sdks/destination/README.md) -* [CreateDestination](docs/destination/README.md#createdestination) - Create a new destination -* [GetDestinations](docs/destination/README.md#getdestinations) - Get all destinations +* [CreateDestination](docs/sdks/destination/README.md#createdestination) - Create a new destination +* [GetDestinations](docs/sdks/destination/README.md#getdestinations) - Get all destinations -### [LinkToken](docs/linktoken/README.md) +### [LinkToken](docs/sdks/linktoken/README.md) -* [CreateLinkToken](docs/linktoken/README.md#createlinktoken) - Create a new link token +* [CreateLinkToken](docs/sdks/linktoken/README.md#createlinktoken) - Create a new link token -### [Object](docs/object/README.md) +### [Object](docs/sdks/object/README.md) -* [CreateObject](docs/object/README.md#createobject) - Create a new object -* [GetObjects](docs/object/README.md#getobjects) - Get all objects +* [CreateObject](docs/sdks/object/README.md#createobject) - Create a new object +* [GetObjects](docs/sdks/object/README.md#getobjects) - Get all objects -### [Source](docs/source/README.md) +### [Source](docs/sdks/source/README.md) -* [CreateSource](docs/source/README.md#createsource) - Create a new source -* [GetSources](docs/source/README.md#getsources) - Get all sources +* [CreateSource](docs/sdks/source/README.md#createsource) - Create a new source +* [GetSources](docs/sdks/source/README.md#getsources) - Get all sources -### [Sync](docs/sync/README.md) +### [Sync](docs/sdks/sync/README.md) -* [CreateSync](docs/sync/README.md#createsync) - Create a new sync -* [GetSyncs](docs/sync/README.md#getsyncs) - Get all syncs +* [CreateSync](docs/sdks/sync/README.md#createsync) - Create a new sync +* [GetSyncs](docs/sdks/sync/README.md#getsyncs) - Get all syncs + + + + + + + + + +# Pagination + +Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the +returned response object will have a `Next` method that can be called to pull down the next group of results. If the +return value of `Next` is `nil`, then there are no more pages to be fetched. + +Here's an example of one such pagination call: + + + + + + + + + + + + ### SDK Generated by [Speakeasy](https://docs.speakeasyapi.dev/docs/using-speakeasy/client-sdks) diff --git a/RELEASES.md b/RELEASES.md index c46d339..8d638e8 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -86,4 +86,54 @@ Based on: - OpenAPI Doc 0.1.0 - Speakeasy CLI 1.29.0 (2.26.0) https://github.com/speakeasy-api/speakeasy ### Releases -- [Go v0.6.0] https://github.com/fabra-io/go-sdk/releases/tag/v0.6.0 - . \ No newline at end of file +- [Go v0.6.0] https://github.com/fabra-io/go-sdk/releases/tag/v0.6.0 - . + +## 2023-09-22 00:02:30 +### Changes +Based on: +- OpenAPI Doc 0.1.0 +- Speakeasy CLI 1.89.0 (2.125.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [go v0.7.0] . +### Releases +- [Go v0.7.0] https://github.com/fabra-io/go-sdk/releases/tag/v0.7.0 - . + +## 2023-09-29 00:02:13 +### Changes +Based on: +- OpenAPI Doc 0.1.0 +- Speakeasy CLI 1.91.3 (2.139.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [go v0.8.0] . +### Releases +- [Go v0.8.0] https://github.com/fabra-io/go-sdk/releases/tag/v0.8.0 - . + +## 2023-10-07 00:02:09 +### Changes +Based on: +- OpenAPI Doc 0.1.0 +- Speakeasy CLI 1.96.1 (2.150.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [go v0.9.0] . +### Releases +- [Go v0.9.0] https://github.com/fabra-io/go-sdk/releases/tag/v0.9.0 - . + +## 2023-10-14 00:02:17 +### Changes +Based on: +- OpenAPI Doc 0.1.0 +- Speakeasy CLI 1.99.2 (2.155.1) https://github.com/speakeasy-api/speakeasy +### Generated +- [go v0.9.1] . +### Releases +- [Go v0.9.1] https://github.com/fabra-io/go-sdk/releases/tag/v0.9.1 - . + +## 2023-10-21 00:02:07 +### Changes +Based on: +- OpenAPI Doc 0.1.0 +- Speakeasy CLI 1.104.0 (2.169.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [go v0.10.0] . +### Releases +- [Go v0.10.0] https://github.com/fabra-io/go-sdk/releases/tag/v0.10.0 - . \ No newline at end of file diff --git a/USAGE.md b/USAGE.md index 7fb8d50..f5c177f 100755 --- a/USAGE.md +++ b/USAGE.md @@ -1,30 +1,33 @@ + + ```go package main -import( +import ( "context" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" "log" - "github.com/fabra-io/go-sdk" - "github.com/fabra-io/go-sdk/pkg/models/operations" ) func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Connection.GetNamespaces(ctx, 548814) - if err != nil { - log.Fatal(err) - } - - if res.Namespaces != nil { - // handle response - } + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + var connectionID int64 = 995455 + + ctx := context.Background() + res, err := s.Connection.GetNamespaces(ctx, connectionID) + if err != nil { + log.Fatal(err) + } + + if res.Namespaces != nil { + // handle response + } } + ``` \ No newline at end of file diff --git a/connection.go b/connection.go index 6526cf3..c5bbe55 100755 --- a/connection.go +++ b/connection.go @@ -1,58 +1,52 @@ // Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. -package fabra +package gosdk import ( + "bytes" "context" "fmt" "github.com/fabra-io/go-sdk/pkg/models/operations" + "github.com/fabra-io/go-sdk/pkg/models/sdkerrors" "github.com/fabra-io/go-sdk/pkg/models/shared" "github.com/fabra-io/go-sdk/pkg/utils" + "io" "net/http" "strings" ) // connection - Operations on connections type connection struct { - defaultClient HTTPClient - securityClient HTTPClient - serverURL string - language string - sdkVersion string - genVersion string + sdkConfiguration sdkConfiguration } -func newConnection(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *connection { +func newConnection(sdkConfig sdkConfiguration) *connection { return &connection{ - defaultClient: defaultClient, - securityClient: securityClient, - serverURL: serverURL, - language: language, - sdkVersion: sdkVersion, - genVersion: genVersion, + sdkConfiguration: sdkConfig, } } // GetNamespaces - Get all namespaces - func (s *connection) GetNamespaces(ctx context.Context, connectionID int64) (*operations.GetNamespacesResponse, error) { request := operations.GetNamespacesRequest{ ConnectionID: connectionID, } - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/connection/namespaces" req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil { return nil, fmt.Errorf("error populating query params: %w", err) } - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -61,7 +55,6 @@ func (s *connection) GetNamespaces(ctx context.Context, connectionID int64) (*op if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -70,16 +63,25 @@ func (s *connection) GetNamespaces(ctx context.Context, connectionID int64) (*op ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *shared.Namespaces - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out shared.Namespaces + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.Namespaces = out + res.Namespaces = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough @@ -90,7 +92,6 @@ func (s *connection) GetNamespaces(ctx context.Context, connectionID int64) (*op } // GetSchema - Get schema for table - func (s *connection) GetSchema(ctx context.Context, connectionID int64, namespace string, tableName string) (*operations.GetSchemaResponse, error) { request := operations.GetSchemaRequest{ ConnectionID: connectionID, @@ -98,19 +99,21 @@ func (s *connection) GetSchema(ctx context.Context, connectionID int64, namespac TableName: tableName, } - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/connection/schema" req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil { return nil, fmt.Errorf("error populating query params: %w", err) } - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -119,7 +122,6 @@ func (s *connection) GetSchema(ctx context.Context, connectionID int64, namespac if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -128,16 +130,25 @@ func (s *connection) GetSchema(ctx context.Context, connectionID int64, namespac ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *operations.GetSchema200ApplicationJSON - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out operations.GetSchema200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.GetSchema200ApplicationJSONObject = out + res.GetSchema200ApplicationJSONObject = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough @@ -148,26 +159,27 @@ func (s *connection) GetSchema(ctx context.Context, connectionID int64, namespac } // GetTables - Get all tables - func (s *connection) GetTables(ctx context.Context, connectionID int64, namespace string) (*operations.GetTablesResponse, error) { request := operations.GetTablesRequest{ ConnectionID: connectionID, Namespace: namespace, } - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/connection/tables" req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil { return nil, fmt.Errorf("error populating query params: %w", err) } - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -176,7 +188,6 @@ func (s *connection) GetTables(ctx context.Context, connectionID int64, namespac if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -185,16 +196,25 @@ func (s *connection) GetTables(ctx context.Context, connectionID int64, namespac ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *operations.GetTables200ApplicationJSON - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out operations.GetTables200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.GetTables200ApplicationJSONObject = out + res.GetTables200ApplicationJSONObject = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough diff --git a/customerdata.go b/customerdata.go new file mode 100755 index 0000000..1f1c656 --- /dev/null +++ b/customerdata.go @@ -0,0 +1,98 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package gosdk + +import ( + "bytes" + "context" + "fmt" + "github.com/fabra-io/go-sdk/pkg/models/operations" + "github.com/fabra-io/go-sdk/pkg/models/sdkerrors" + "github.com/fabra-io/go-sdk/pkg/utils" + "io" + "net/http" +) + +type customerData struct { + sdkConfiguration sdkConfiguration +} + +func newCustomerData(sdkConfig sdkConfiguration) *customerData { + return &customerData{ + sdkConfiguration: sdkConfig, + } +} + +// QueryObject - Query object record for customer +// Query a single object record directly from a customer's source. The response payload will match the object schema you've defined. +func (s *customerData) QueryObject(ctx context.Context, endCustomerID string, objectID int64, requestBody *operations.QueryObjectRequestBody) (*operations.QueryObjectResponse, error) { + request := operations.QueryObjectRequest{ + EndCustomerID: endCustomerID, + ObjectID: objectID, + RequestBody: requestBody, + } + + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) + url, err := utils.GenerateURL(ctx, baseURL, "/customer/{endCustomerID}/object/{objectID}/record", request, nil) + if err != nil { + return nil, fmt.Errorf("error generating URL: %w", err) + } + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, true, "RequestBody", "json", `request:"mediaType=application/json"`) + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + + req, err := http.NewRequestWithContext(ctx, "POST", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) + + req.Header.Set("Content-Type", reqContentType) + + client := s.sdkConfiguration.SecurityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.QueryObjectResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out operations.QueryObject200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { + return nil, err + } + + res.QueryObject200ApplicationJSONObject = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) + } + case httpRes.StatusCode == 401: + fallthrough + case httpRes.StatusCode == 500: + } + + return res, nil +} diff --git a/destination.go b/destination.go index f8fa95b..e1c9d0a 100755 --- a/destination.go +++ b/destination.go @@ -1,45 +1,37 @@ // Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. -package fabra +package gosdk import ( + "bytes" "context" "fmt" "github.com/fabra-io/go-sdk/pkg/models/operations" + "github.com/fabra-io/go-sdk/pkg/models/sdkerrors" "github.com/fabra-io/go-sdk/pkg/models/shared" "github.com/fabra-io/go-sdk/pkg/utils" + "io" "net/http" "strings" ) // destination - Operations on destinations type destination struct { - defaultClient HTTPClient - securityClient HTTPClient - serverURL string - language string - sdkVersion string - genVersion string + sdkConfiguration sdkConfiguration } -func newDestination(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *destination { +func newDestination(sdkConfig sdkConfiguration) *destination { return &destination{ - defaultClient: defaultClient, - securityClient: securityClient, - serverURL: serverURL, - language: language, - sdkVersion: sdkVersion, - genVersion: genVersion, + sdkConfiguration: sdkConfig, } } // CreateDestination - Create a new destination - func (s *destination) CreateDestination(ctx context.Context, request shared.DestinationInput) (*operations.CreateDestinationResponse, error) { - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/destination" - bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, fmt.Errorf("error serializing request body: %w", err) } @@ -51,10 +43,12 @@ func (s *destination) CreateDestination(ctx context.Context, request shared.Dest if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) req.Header.Set("Content-Type", reqContentType) - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -63,7 +57,6 @@ func (s *destination) CreateDestination(ctx context.Context, request shared.Dest if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -72,16 +65,25 @@ func (s *destination) CreateDestination(ctx context.Context, request shared.Dest ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *operations.CreateDestination200ApplicationJSON - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out operations.CreateDestination200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.CreateDestination200ApplicationJSONObject = out + res.CreateDestination200ApplicationJSONObject = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough @@ -92,17 +94,18 @@ func (s *destination) CreateDestination(ctx context.Context, request shared.Dest } // GetDestinations - Get all destinations - func (s *destination) GetDestinations(ctx context.Context) (*operations.GetDestinationsResponse, error) { - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/destinations" req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -111,7 +114,6 @@ func (s *destination) GetDestinations(ctx context.Context) (*operations.GetDesti if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -120,16 +122,25 @@ func (s *destination) GetDestinations(ctx context.Context) (*operations.GetDesti ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *operations.GetDestinations200ApplicationJSON - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out operations.GetDestinations200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.GetDestinations200ApplicationJSONObject = out + res.GetDestinations200ApplicationJSONObject = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough diff --git a/docs/connection/README.md b/docs/connection/README.md deleted file mode 100755 index b13a4e9..0000000 --- a/docs/connection/README.md +++ /dev/null @@ -1,116 +0,0 @@ -# Connection - -## Overview - -Operations on connections - -### Available Operations - -* [GetNamespaces](#getnamespaces) - Get all namespaces -* [GetSchema](#getschema) - Get schema for table -* [GetTables](#gettables) - Get all tables - -## GetNamespaces - -Get all namespaces - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" - "github.com/fabra-io/go-sdk/pkg/models/operations" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Connection.GetNamespaces(ctx, 592845) - if err != nil { - log.Fatal(err) - } - - if res.Namespaces != nil { - // handle response - } -} -``` - -## GetSchema - -Get schema for table - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" - "github.com/fabra-io/go-sdk/pkg/models/operations" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Connection.GetSchema(ctx, 715190, "quibusdam", "unde") - if err != nil { - log.Fatal(err) - } - - if res.GetSchema200ApplicationJSONObject != nil { - // handle response - } -} -``` - -## GetTables - -Get all tables - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" - "github.com/fabra-io/go-sdk/pkg/models/operations" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Connection.GetTables(ctx, 857946, "corrupti") - if err != nil { - log.Fatal(err) - } - - if res.GetTables200ApplicationJSONObject != nil { - // handle response - } -} -``` diff --git a/docs/destination/README.md b/docs/destination/README.md deleted file mode 100755 index 6d9a94a..0000000 --- a/docs/destination/README.md +++ /dev/null @@ -1,107 +0,0 @@ -# Destination - -## Overview - -Operations on destinations - -### Available Operations - -* [CreateDestination](#createdestination) - Create a new destination -* [GetDestinations](#getdestinations) - Get all destinations - -## CreateDestination - -Create a new destination - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" - "github.com/fabra-io/go-sdk/pkg/models/shared" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Destination.CreateDestination(ctx, shared.DestinationInput{ - BigqueryConfig: &shared.BigQueryConfig{ - Credentials: fabra.String("Paste JSON from GCP"), - Location: "us-west1", - }, - ConnectionType: shared.ConnectionTypeEnumWebhook, - DisplayName: "BigQuery", - MongodbConfig: &shared.MongoDbConfig{ - ConnectionOptions: fabra.String("retryWrites=true&w=majority"), - Host: "examplecluster.abc123.mongodb.net", - Password: "securePassword123", - Username: "jane_doe", - }, - RedshiftConfig: &shared.RedshiftConfig{ - DatabaseName: "your_database", - Host: "examplecluster.12345.us-west-1.redshift.amazonaws.com", - Password: "securePassword123", - Port: "5432", - Username: "jane_doe", - }, - SnowflakeConfig: &shared.SnowflakeConfig{ - DatabaseName: "your_database", - Host: "abc123.us-east4.gcp.snowflakecomputing.com", - Password: "securePassword123", - Role: "your_role", - Username: "jane_doe", - WarehouseName: "your_warehouse", - }, - }) - if err != nil { - log.Fatal(err) - } - - if res.CreateDestination200ApplicationJSONObject != nil { - // handle response - } -} -``` - -## GetDestinations - -Get all destinations - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Destination.GetDestinations(ctx) - if err != nil { - log.Fatal(err) - } - - if res.GetDestinations200ApplicationJSONObject != nil { - // handle response - } -} -``` diff --git a/docs/linktoken/README.md b/docs/linktoken/README.md deleted file mode 100755 index c4564be..0000000 --- a/docs/linktoken/README.md +++ /dev/null @@ -1,46 +0,0 @@ -# LinkToken - -## Overview - -Operations on link tokens - -### Available Operations - -* [CreateLinkToken](#createlinktoken) - Create a new link token - -## CreateLinkToken - -Create a new link token - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" - "github.com/fabra-io/go-sdk/pkg/models/shared" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.LinkToken.CreateLinkToken(ctx, shared.CreateLinkTokenRequest{ - EndCustomerID: "123", - }) - if err != nil { - log.Fatal(err) - } - - if res.CreateLinkTokenResponse != nil { - // handle response - } -} -``` diff --git a/docs/models/operations/createdestination200applicationjson.md b/docs/models/operations/createdestination200applicationjson.md new file mode 100755 index 0000000..3ba37b5 --- /dev/null +++ b/docs/models/operations/createdestination200applicationjson.md @@ -0,0 +1,10 @@ +# CreateDestination200ApplicationJSON + +Successfully created destination + + +## Fields + +| Field | Type | Required | Description | +| --------------------------------------------------------- | --------------------------------------------------------- | --------------------------------------------------------- | --------------------------------------------------------- | +| `Destination` | [*shared.Destination](../../models/shared/destination.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/createdestinationresponse.md b/docs/models/operations/createdestinationresponse.md new file mode 100755 index 0000000..c85671c --- /dev/null +++ b/docs/models/operations/createdestinationresponse.md @@ -0,0 +1,11 @@ +# CreateDestinationResponse + + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------ | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `CreateDestination200ApplicationJSONObject` | [*CreateDestination200ApplicationJSON](../../models/operations/createdestination200applicationjson.md) | :heavy_minus_sign: | Successfully created destination | \ No newline at end of file diff --git a/docs/models/operations/createlinktokenresponse.md b/docs/models/operations/createlinktokenresponse.md new file mode 100755 index 0000000..17e909e --- /dev/null +++ b/docs/models/operations/createlinktokenresponse.md @@ -0,0 +1,11 @@ +# CreateLinkTokenResponse + + +## Fields + +| Field | Type | Required | Description | +| --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `CreateLinkTokenResponse` | [*shared.CreateLinkTokenResponse](../../models/shared/createlinktokenresponse.md) | :heavy_minus_sign: | Successfully created link token | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | \ No newline at end of file diff --git a/docs/models/operations/createobject200applicationjson.md b/docs/models/operations/createobject200applicationjson.md new file mode 100755 index 0000000..1581681 --- /dev/null +++ b/docs/models/operations/createobject200applicationjson.md @@ -0,0 +1,10 @@ +# CreateObject200ApplicationJSON + +Successfully created object + + +## Fields + +| Field | Type | Required | Description | +| ----------------------------------------------- | ----------------------------------------------- | ----------------------------------------------- | ----------------------------------------------- | +| `Object` | [*shared.Object](../../models/shared/object.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/createobjectresponse.md b/docs/models/operations/createobjectresponse.md new file mode 100755 index 0000000..ad817f5 --- /dev/null +++ b/docs/models/operations/createobjectresponse.md @@ -0,0 +1,11 @@ +# CreateObjectResponse + + +## Fields + +| Field | Type | Required | Description | +| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `CreateObject200ApplicationJSONObject` | [*CreateObject200ApplicationJSON](../../models/operations/createobject200applicationjson.md) | :heavy_minus_sign: | Successfully created object | \ No newline at end of file diff --git a/docs/models/operations/createsource200applicationjson.md b/docs/models/operations/createsource200applicationjson.md new file mode 100755 index 0000000..1d72026 --- /dev/null +++ b/docs/models/operations/createsource200applicationjson.md @@ -0,0 +1,10 @@ +# CreateSource200ApplicationJSON + +Successfully created source + + +## Fields + +| Field | Type | Required | Description | +| ----------------------------------------------- | ----------------------------------------------- | ----------------------------------------------- | ----------------------------------------------- | +| `Source` | [*shared.Source](../../models/shared/source.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/createsourceresponse.md b/docs/models/operations/createsourceresponse.md new file mode 100755 index 0000000..99a6311 --- /dev/null +++ b/docs/models/operations/createsourceresponse.md @@ -0,0 +1,11 @@ +# CreateSourceResponse + + +## Fields + +| Field | Type | Required | Description | +| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `CreateSource200ApplicationJSONObject` | [*CreateSource200ApplicationJSON](../../models/operations/createsource200applicationjson.md) | :heavy_minus_sign: | Successfully created source | \ No newline at end of file diff --git a/docs/models/operations/createsync200applicationjson.md b/docs/models/operations/createsync200applicationjson.md new file mode 100755 index 0000000..5d5e902 --- /dev/null +++ b/docs/models/operations/createsync200applicationjson.md @@ -0,0 +1,10 @@ +# CreateSync200ApplicationJSON + +Successfully created sync + + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------- | ------------------------------------------- | ------------------------------------------- | ------------------------------------------- | +| `Sync` | [*shared.Sync](../../models/shared/sync.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/createsyncresponse.md b/docs/models/operations/createsyncresponse.md new file mode 100755 index 0000000..d09c597 --- /dev/null +++ b/docs/models/operations/createsyncresponse.md @@ -0,0 +1,11 @@ +# CreateSyncResponse + + +## Fields + +| Field | Type | Required | Description | +| ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `CreateSync200ApplicationJSONObject` | [*CreateSync200ApplicationJSON](../../models/operations/createsync200applicationjson.md) | :heavy_minus_sign: | Successfully created sync | \ No newline at end of file diff --git a/docs/models/operations/getdestinations200applicationjson.md b/docs/models/operations/getdestinations200applicationjson.md new file mode 100755 index 0000000..b0dad16 --- /dev/null +++ b/docs/models/operations/getdestinations200applicationjson.md @@ -0,0 +1,10 @@ +# GetDestinations200ApplicationJSON + +Successfully fetched destinations + + +## Fields + +| Field | Type | Required | Description | +| ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | +| `Destinations` | [][shared.Destination](../../models/shared/destination.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/getdestinationsresponse.md b/docs/models/operations/getdestinationsresponse.md new file mode 100755 index 0000000..e9c65a9 --- /dev/null +++ b/docs/models/operations/getdestinationsresponse.md @@ -0,0 +1,11 @@ +# GetDestinationsResponse + + +## Fields + +| Field | Type | Required | Description | +| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `GetDestinations200ApplicationJSONObject` | [*GetDestinations200ApplicationJSON](../../models/operations/getdestinations200applicationjson.md) | :heavy_minus_sign: | Successfully fetched destinations | \ No newline at end of file diff --git a/docs/models/operations/getnamespacesrequest.md b/docs/models/operations/getnamespacesrequest.md new file mode 100755 index 0000000..5b07ed7 --- /dev/null +++ b/docs/models/operations/getnamespacesrequest.md @@ -0,0 +1,8 @@ +# GetNamespacesRequest + + +## Fields + +| Field | Type | Required | Description | +| ------------------ | ------------------ | ------------------ | ------------------ | +| `ConnectionID` | *int64* | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/models/operations/getnamespacesresponse.md b/docs/models/operations/getnamespacesresponse.md new file mode 100755 index 0000000..bf2e9b1 --- /dev/null +++ b/docs/models/operations/getnamespacesresponse.md @@ -0,0 +1,11 @@ +# GetNamespacesResponse + + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------- | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `Namespaces` | [*shared.Namespaces](../../models/shared/namespaces.md) | :heavy_minus_sign: | Successfully fetched namespaces | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | \ No newline at end of file diff --git a/docs/models/operations/getobjects200applicationjson.md b/docs/models/operations/getobjects200applicationjson.md new file mode 100755 index 0000000..c91ed60 --- /dev/null +++ b/docs/models/operations/getobjects200applicationjson.md @@ -0,0 +1,10 @@ +# GetObjects200ApplicationJSON + +Successfully fetched objects + + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | +| `Objects` | [][shared.Object](../../models/shared/object.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/getobjectsresponse.md b/docs/models/operations/getobjectsresponse.md new file mode 100755 index 0000000..031f4d0 --- /dev/null +++ b/docs/models/operations/getobjectsresponse.md @@ -0,0 +1,11 @@ +# GetObjectsResponse + + +## Fields + +| Field | Type | Required | Description | +| ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `GetObjects200ApplicationJSONObject` | [*GetObjects200ApplicationJSON](../../models/operations/getobjects200applicationjson.md) | :heavy_minus_sign: | Successfully fetched objects | \ No newline at end of file diff --git a/docs/models/operations/getschema200applicationjson.md b/docs/models/operations/getschema200applicationjson.md new file mode 100755 index 0000000..2623634 --- /dev/null +++ b/docs/models/operations/getschema200applicationjson.md @@ -0,0 +1,10 @@ +# GetSchema200ApplicationJSON + +Successfully fetched schema + + +## Fields + +| Field | Type | Required | Description | Example | +| --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | +| `Schema` | [][shared.Field](../../models/shared/field.md) | :heavy_minus_sign: | N/A | [object Object],[object Object],[object Object],[object Object] | \ No newline at end of file diff --git a/docs/models/operations/getschemarequest.md b/docs/models/operations/getschemarequest.md new file mode 100755 index 0000000..c9a042b --- /dev/null +++ b/docs/models/operations/getschemarequest.md @@ -0,0 +1,10 @@ +# GetSchemaRequest + + +## Fields + +| Field | Type | Required | Description | +| ------------------ | ------------------ | ------------------ | ------------------ | +| `ConnectionID` | *int64* | :heavy_check_mark: | N/A | +| `Namespace` | *string* | :heavy_check_mark: | N/A | +| `TableName` | *string* | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/models/operations/getschemaresponse.md b/docs/models/operations/getschemaresponse.md new file mode 100755 index 0000000..0399880 --- /dev/null +++ b/docs/models/operations/getschemaresponse.md @@ -0,0 +1,11 @@ +# GetSchemaResponse + + +## Fields + +| Field | Type | Required | Description | +| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `GetSchema200ApplicationJSONObject` | [*GetSchema200ApplicationJSON](../../models/operations/getschema200applicationjson.md) | :heavy_minus_sign: | Successfully fetched schema | \ No newline at end of file diff --git a/docs/models/operations/getsources200applicationjson.md b/docs/models/operations/getsources200applicationjson.md new file mode 100755 index 0000000..ac3a291 --- /dev/null +++ b/docs/models/operations/getsources200applicationjson.md @@ -0,0 +1,10 @@ +# GetSources200ApplicationJSON + +Successfully fetched sources + + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | +| `Sources` | [][shared.Source](../../models/shared/source.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/getsourcesresponse.md b/docs/models/operations/getsourcesresponse.md new file mode 100755 index 0000000..6a50010 --- /dev/null +++ b/docs/models/operations/getsourcesresponse.md @@ -0,0 +1,11 @@ +# GetSourcesResponse + + +## Fields + +| Field | Type | Required | Description | +| ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `GetSources200ApplicationJSONObject` | [*GetSources200ApplicationJSON](../../models/operations/getsources200applicationjson.md) | :heavy_minus_sign: | Successfully fetched sources | \ No newline at end of file diff --git a/docs/models/operations/getsyncs200applicationjson.md b/docs/models/operations/getsyncs200applicationjson.md new file mode 100755 index 0000000..e693dea --- /dev/null +++ b/docs/models/operations/getsyncs200applicationjson.md @@ -0,0 +1,10 @@ +# GetSyncs200ApplicationJSON + +Successfully fetched syncs + + +## Fields + +| Field | Type | Required | Description | +| -------------------------------------------- | -------------------------------------------- | -------------------------------------------- | -------------------------------------------- | +| `Syncs` | [][shared.Sync](../../models/shared/sync.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/getsyncsresponse.md b/docs/models/operations/getsyncsresponse.md new file mode 100755 index 0000000..2d1e447 --- /dev/null +++ b/docs/models/operations/getsyncsresponse.md @@ -0,0 +1,11 @@ +# GetSyncsResponse + + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `GetSyncs200ApplicationJSONObject` | [*GetSyncs200ApplicationJSON](../../models/operations/getsyncs200applicationjson.md) | :heavy_minus_sign: | Successfully fetched syncs | \ No newline at end of file diff --git a/docs/models/operations/gettables200applicationjson.md b/docs/models/operations/gettables200applicationjson.md new file mode 100755 index 0000000..0d626ba --- /dev/null +++ b/docs/models/operations/gettables200applicationjson.md @@ -0,0 +1,10 @@ +# GetTables200ApplicationJSON + +Successfully fetched tables + + +## Fields + +| Field | Type | Required | Description | Example | +| ---------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- | +| `Tables` | []*string* | :heavy_minus_sign: | N/A | events,users,companies | \ No newline at end of file diff --git a/docs/models/operations/gettablesrequest.md b/docs/models/operations/gettablesrequest.md new file mode 100755 index 0000000..6165de7 --- /dev/null +++ b/docs/models/operations/gettablesrequest.md @@ -0,0 +1,9 @@ +# GetTablesRequest + + +## Fields + +| Field | Type | Required | Description | +| ------------------ | ------------------ | ------------------ | ------------------ | +| `ConnectionID` | *int64* | :heavy_check_mark: | N/A | +| `Namespace` | *string* | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/models/operations/gettablesresponse.md b/docs/models/operations/gettablesresponse.md new file mode 100755 index 0000000..3ffa219 --- /dev/null +++ b/docs/models/operations/gettablesresponse.md @@ -0,0 +1,11 @@ +# GetTablesResponse + + +## Fields + +| Field | Type | Required | Description | +| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `GetTables200ApplicationJSONObject` | [*GetTables200ApplicationJSON](../../models/operations/gettables200applicationjson.md) | :heavy_minus_sign: | Successfully fetched tables | \ No newline at end of file diff --git a/docs/models/operations/queryobject200applicationjson.md b/docs/models/operations/queryobject200applicationjson.md new file mode 100755 index 0000000..98c1e11 --- /dev/null +++ b/docs/models/operations/queryobject200applicationjson.md @@ -0,0 +1,12 @@ +# QueryObject200ApplicationJSON + +The response payload will match the schema you defined when creating the object + + +## Fields + +| Field | Type | Required | Description | Example | +| -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | +| `ExampleField1` | **int64* | :heavy_minus_sign: | N/A | 1 | +| `ExampleField2` | **string* | :heavy_minus_sign: | N/A | hello | +| `ExampleField3` | [*QueryObject200ApplicationJSONExampleField3](../../models/operations/queryobject200applicationjsonexamplefield3.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file diff --git a/docs/models/operations/queryobject200applicationjsonexamplefield3.md b/docs/models/operations/queryobject200applicationjsonexamplefield3.md new file mode 100755 index 0000000..8c8948f --- /dev/null +++ b/docs/models/operations/queryobject200applicationjsonexamplefield3.md @@ -0,0 +1,9 @@ +# QueryObject200ApplicationJSONExampleField3 + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | +| `NestedField1` | **string* | :heavy_minus_sign: | N/A | world | +| `NestedField2` | **int64* | :heavy_minus_sign: | N/A | 2 | \ No newline at end of file diff --git a/docs/models/operations/queryobjectrequest.md b/docs/models/operations/queryobjectrequest.md new file mode 100755 index 0000000..dff3a62 --- /dev/null +++ b/docs/models/operations/queryobjectrequest.md @@ -0,0 +1,10 @@ +# QueryObjectRequest + + +## Fields + +| Field | Type | Required | Description | +| ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | +| `EndCustomerID` | *string* | :heavy_check_mark: | N/A | +| `ObjectID` | *int64* | :heavy_check_mark: | N/A | +| `RequestBody` | [*QueryObjectRequestBody](../../models/operations/queryobjectrequestbody.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/queryobjectrequestbody.md b/docs/models/operations/queryobjectrequestbody.md new file mode 100755 index 0000000..ab6385a --- /dev/null +++ b/docs/models/operations/queryobjectrequestbody.md @@ -0,0 +1,8 @@ +# QueryObjectRequestBody + + +## Fields + +| Field | Type | Required | Description | +| ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | +| `Filters` | [][shared.QueryFilter](../../models/shared/queryfilter.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/operations/queryobjectresponse.md b/docs/models/operations/queryobjectresponse.md new file mode 100755 index 0000000..a1556ce --- /dev/null +++ b/docs/models/operations/queryobjectresponse.md @@ -0,0 +1,11 @@ +# QueryObjectResponse + + +## Fields + +| Field | Type | Required | Description | +| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | +| `ContentType` | *string* | :heavy_check_mark: | HTTP response content type for this operation | +| `StatusCode` | *int* | :heavy_check_mark: | HTTP response status code for this operation | +| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | Raw HTTP response; suitable for custom response parsing | +| `QueryObject200ApplicationJSONObject` | [*QueryObject200ApplicationJSON](../../models/operations/queryobject200applicationjson.md) | :heavy_minus_sign: | The response payload will match the schema you defined when creating the object | \ No newline at end of file diff --git a/docs/models/shared/bigqueryconfig.md b/docs/models/shared/bigqueryconfig.md new file mode 100755 index 0000000..532cb15 --- /dev/null +++ b/docs/models/shared/bigqueryconfig.md @@ -0,0 +1,9 @@ +# BigQueryConfig + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | +| `Credentials` | **string* | :heavy_minus_sign: | N/A | Paste JSON from GCP | +| `Location` | *string* | :heavy_check_mark: | N/A | us-west1 | \ No newline at end of file diff --git a/docs/models/shared/connection.md b/docs/models/shared/connection.md new file mode 100755 index 0000000..179c8e0 --- /dev/null +++ b/docs/models/shared/connection.md @@ -0,0 +1,9 @@ +# Connection + + +## Fields + +| Field | Type | Required | Description | Example | +| -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | +| `ConnectionType` | [*ConnectionType](../../models/shared/connectiontype.md) | :heavy_minus_sign: | N/A | | +| `ID` | **int64* | :heavy_minus_sign: | N/A | 1 | \ No newline at end of file diff --git a/docs/models/shared/connectiontype.md b/docs/models/shared/connectiontype.md new file mode 100755 index 0000000..7d4dac5 --- /dev/null +++ b/docs/models/shared/connectiontype.md @@ -0,0 +1,12 @@ +# ConnectionType + + +## Values + +| Name | Value | +| ------------------------- | ------------------------- | +| `ConnectionTypeSnowflake` | snowflake | +| `ConnectionTypeBigquery` | bigquery | +| `ConnectionTypeRedshift` | redshift | +| `ConnectionTypeMongodb` | mongodb | +| `ConnectionTypeWebhook` | webhook | \ No newline at end of file diff --git a/docs/models/shared/createlinktokenrequest.md b/docs/models/shared/createlinktokenrequest.md new file mode 100755 index 0000000..96dbb22 --- /dev/null +++ b/docs/models/shared/createlinktokenrequest.md @@ -0,0 +1,8 @@ +# CreateLinkTokenRequest + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | +| `EndCustomerID` | *string* | :heavy_check_mark: | N/A | abcd-1234-efgh-5678 | \ No newline at end of file diff --git a/docs/models/shared/createlinktokenresponse.md b/docs/models/shared/createlinktokenresponse.md new file mode 100755 index 0000000..f3e198d --- /dev/null +++ b/docs/models/shared/createlinktokenresponse.md @@ -0,0 +1,8 @@ +# CreateLinkTokenResponse + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | +| `LinkToken` | **string* | :heavy_minus_sign: | N/A | abc123def | \ No newline at end of file diff --git a/docs/models/shared/destination.md b/docs/models/shared/destination.md new file mode 100755 index 0000000..4dcbe2c --- /dev/null +++ b/docs/models/shared/destination.md @@ -0,0 +1,10 @@ +# Destination + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | +| `Connection` | [*Connection](../../models/shared/connection.md) | :heavy_minus_sign: | N/A | | +| `DisplayName` | **string* | :heavy_minus_sign: | N/A | BigQuery | +| `ID` | **int64* | :heavy_minus_sign: | N/A | 10 | \ No newline at end of file diff --git a/docs/models/shared/destinationinput.md b/docs/models/shared/destinationinput.md new file mode 100755 index 0000000..e18325c --- /dev/null +++ b/docs/models/shared/destinationinput.md @@ -0,0 +1,13 @@ +# DestinationInput + + +## Fields + +| Field | Type | Required | Description | Example | +| ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | +| `BigqueryConfig` | [*BigQueryConfig](../../models/shared/bigqueryconfig.md) | :heavy_minus_sign: | N/A | | +| `ConnectionType` | [ConnectionType](../../models/shared/connectiontype.md) | :heavy_check_mark: | N/A | | +| `DisplayName` | *string* | :heavy_check_mark: | N/A | BigQuery | +| `MongodbConfig` | [*MongoDbConfig](../../models/shared/mongodbconfig.md) | :heavy_minus_sign: | N/A | | +| `RedshiftConfig` | [*RedshiftConfig](../../models/shared/redshiftconfig.md) | :heavy_minus_sign: | N/A | | +| `SnowflakeConfig` | [*SnowflakeConfig](../../models/shared/snowflakeconfig.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file diff --git a/docs/models/shared/field.md b/docs/models/shared/field.md new file mode 100755 index 0000000..8691d5b --- /dev/null +++ b/docs/models/shared/field.md @@ -0,0 +1,9 @@ +# Field + + +## Fields + +| Field | Type | Required | Description | Example | +| ---------------------------------------------- | ---------------------------------------------- | ---------------------------------------------- | ---------------------------------------------- | ---------------------------------------------- | +| `Name` | **string* | :heavy_minus_sign: | N/A | event_name | +| `Type` | [*FieldType](../../models/shared/fieldtype.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file diff --git a/docs/models/shared/fieldmapping.md b/docs/models/shared/fieldmapping.md new file mode 100755 index 0000000..31ab129 --- /dev/null +++ b/docs/models/shared/fieldmapping.md @@ -0,0 +1,9 @@ +# FieldMapping + + +## Fields + +| Field | Type | Required | Description | Example | +| ---------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- | +| `DestinationFieldName` | **string* | :heavy_minus_sign: | N/A | event | +| `SourceFieldName` | **string* | :heavy_minus_sign: | N/A | event_name | \ No newline at end of file diff --git a/docs/models/shared/fieldtype.md b/docs/models/shared/fieldtype.md new file mode 100755 index 0000000..26598e0 --- /dev/null +++ b/docs/models/shared/fieldtype.md @@ -0,0 +1,12 @@ +# FieldType + + +## Values + +| Name | Value | +| -------------------- | -------------------- | +| `FieldTypeString` | string | +| `FieldTypeInteger` | integer | +| `FieldTypeTimestamp` | timestamp | +| `FieldTypeJSON` | json | +| `FieldTypeBoolean` | boolean | \ No newline at end of file diff --git a/docs/models/shared/frequencyunits.md b/docs/models/shared/frequencyunits.md new file mode 100755 index 0000000..bf44ede --- /dev/null +++ b/docs/models/shared/frequencyunits.md @@ -0,0 +1,11 @@ +# FrequencyUnits + + +## Values + +| Name | Value | +| ----------------------- | ----------------------- | +| `FrequencyUnitsMinutes` | minutes | +| `FrequencyUnitsHours` | hours | +| `FrequencyUnitsDays` | days | +| `FrequencyUnitsWeeks` | weeks | \ No newline at end of file diff --git a/docs/models/shared/mongodbconfig.md b/docs/models/shared/mongodbconfig.md new file mode 100755 index 0000000..c7a22d3 --- /dev/null +++ b/docs/models/shared/mongodbconfig.md @@ -0,0 +1,11 @@ +# MongoDbConfig + + +## Fields + +| Field | Type | Required | Description | Example | +| --------------------------------- | --------------------------------- | --------------------------------- | --------------------------------- | --------------------------------- | +| `ConnectionOptions` | **string* | :heavy_minus_sign: | N/A | retryWrites=true&w=majority | +| `Host` | *string* | :heavy_check_mark: | N/A | examplecluster.abc123.mongodb.net | +| `Password` | *string* | :heavy_check_mark: | N/A | securePassword123 | +| `Username` | *string* | :heavy_check_mark: | N/A | jane_doe | \ No newline at end of file diff --git a/docs/models/shared/namespaces.md b/docs/models/shared/namespaces.md new file mode 100755 index 0000000..7d87105 --- /dev/null +++ b/docs/models/shared/namespaces.md @@ -0,0 +1,8 @@ +# Namespaces + + +## Fields + +| Field | Type | Required | Description | Example | +| --------------------------- | --------------------------- | --------------------------- | --------------------------- | --------------------------- | +| `Namespaces` | []*string* | :heavy_minus_sign: | N/A | marketing,analytics,finance | \ No newline at end of file diff --git a/docs/models/shared/object.md b/docs/models/shared/object.md new file mode 100755 index 0000000..0e2b5b7 --- /dev/null +++ b/docs/models/shared/object.md @@ -0,0 +1,14 @@ +# Object + + +## Fields + +| Field | Type | Required | Description | Example | +| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | +| `DestinationID` | **int64* | :heavy_minus_sign: | N/A | 2 | +| `DisplayName` | **string* | :heavy_minus_sign: | N/A | BigQuery | +| `EndCustomerIDField` | **string* | :heavy_minus_sign: | This is where Fabra will insert the End Customer ID specified in the sync configuration | end_customer_id | +| `ID` | **int64* | :heavy_minus_sign: | N/A | 10 | +| `Namespace` | **string* | :heavy_minus_sign: | N/A | bigquery_dataset | +| `ObjectFields` | [][ObjectField](../../models/shared/objectfield.md) | :heavy_minus_sign: | N/A | | +| `TableName` | **string* | :heavy_minus_sign: | N/A | events | \ No newline at end of file diff --git a/docs/models/shared/objectfield.md b/docs/models/shared/objectfield.md new file mode 100755 index 0000000..df209ca --- /dev/null +++ b/docs/models/shared/objectfield.md @@ -0,0 +1,9 @@ +# ObjectField + + +## Fields + +| Field | Type | Required | Description | Example | +| ---------------------------------------------- | ---------------------------------------------- | ---------------------------------------------- | ---------------------------------------------- | ---------------------------------------------- | +| `Name` | **string* | :heavy_minus_sign: | N/A | event_name | +| `Type` | [*FieldType](../../models/shared/fieldtype.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file diff --git a/docs/models/shared/objectinput.md b/docs/models/shared/objectinput.md new file mode 100755 index 0000000..f9a8e8f --- /dev/null +++ b/docs/models/shared/objectinput.md @@ -0,0 +1,17 @@ +# ObjectInput + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | +| `CursorField` | **string* | :heavy_minus_sign: | N/A | updated_at | +| `DestinationID` | *int64* | :heavy_check_mark: | N/A | 2 | +| `DisplayName` | *string* | :heavy_check_mark: | N/A | BigQuery | +| `EndCustomerIDField` | *string* | :heavy_check_mark: | This is where Fabra will insert the End Customer ID specified when creating a source. | end_customer_id | +| `Frequency` | *int64* | :heavy_check_mark: | N/A | 30 | +| `FrequencyUnits` | [FrequencyUnits](../../models/shared/frequencyunits.md) | :heavy_check_mark: | N/A | | +| `Namespace` | *string* | :heavy_check_mark: | N/A | bigquery_dataset | +| `ObjectFields` | [][ObjectField](../../models/shared/objectfield.md) | :heavy_minus_sign: | N/A | | +| `PrimaryKey` | **string* | :heavy_minus_sign: | N/A | event_id | +| `TableName` | *string* | :heavy_check_mark: | N/A | events | \ No newline at end of file diff --git a/docs/models/shared/queryfilter.md b/docs/models/shared/queryfilter.md new file mode 100755 index 0000000..e590a0f --- /dev/null +++ b/docs/models/shared/queryfilter.md @@ -0,0 +1,9 @@ +# QueryFilter + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | +| `FieldName` | *string* | :heavy_check_mark: | N/A | user_id | +| `FieldValue` | *string* | :heavy_check_mark: | N/A | 2 | \ No newline at end of file diff --git a/docs/models/shared/redshiftconfig.md b/docs/models/shared/redshiftconfig.md new file mode 100755 index 0000000..1ef13cb --- /dev/null +++ b/docs/models/shared/redshiftconfig.md @@ -0,0 +1,12 @@ +# RedshiftConfig + + +## Fields + +| Field | Type | Required | Description | Example | +| ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | +| `DatabaseName` | *string* | :heavy_check_mark: | N/A | your_database | +| `Host` | *string* | :heavy_check_mark: | N/A | examplecluster.12345.us-west-1.redshift.amazonaws.com | +| `Password` | *string* | :heavy_check_mark: | N/A | securePassword123 | +| `Port` | *string* | :heavy_check_mark: | N/A | 5432 | +| `Username` | *string* | :heavy_check_mark: | N/A | jane_doe | \ No newline at end of file diff --git a/docs/models/shared/security.md b/docs/models/shared/security.md new file mode 100755 index 0000000..492e6ee --- /dev/null +++ b/docs/models/shared/security.md @@ -0,0 +1,8 @@ +# Security + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | +| `APIKeyAuth` | *string* | :heavy_check_mark: | N/A | | \ No newline at end of file diff --git a/docs/models/shared/snowflakeconfig.md b/docs/models/shared/snowflakeconfig.md new file mode 100755 index 0000000..4d9b12a --- /dev/null +++ b/docs/models/shared/snowflakeconfig.md @@ -0,0 +1,13 @@ +# SnowflakeConfig + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------------------------------ | ------------------------------------------ | ------------------------------------------ | ------------------------------------------ | ------------------------------------------ | +| `DatabaseName` | *string* | :heavy_check_mark: | N/A | your_database | +| `Host` | *string* | :heavy_check_mark: | N/A | abc123.us-east4.gcp.snowflakecomputing.com | +| `Password` | *string* | :heavy_check_mark: | N/A | securePassword123 | +| `Role` | *string* | :heavy_check_mark: | N/A | your_role | +| `Username` | *string* | :heavy_check_mark: | N/A | jane_doe | +| `WarehouseName` | *string* | :heavy_check_mark: | N/A | your_warehouse | \ No newline at end of file diff --git a/docs/models/shared/source.md b/docs/models/shared/source.md new file mode 100755 index 0000000..d8352d4 --- /dev/null +++ b/docs/models/shared/source.md @@ -0,0 +1,11 @@ +# Source + + +## Fields + +| Field | Type | Required | Description | Example | +| ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | ------------------------------------------------ | +| `Connection` | [*Connection](../../models/shared/connection.md) | :heavy_minus_sign: | N/A | | +| `DisplayName` | **string* | :heavy_minus_sign: | N/A | Frontend Events | +| `EndCustomerID` | **string* | :heavy_minus_sign: | N/A | abcd-1234-efgh-5678 | +| `ID` | **int64* | :heavy_minus_sign: | N/A | 10 | \ No newline at end of file diff --git a/docs/models/shared/sourceinput.md b/docs/models/shared/sourceinput.md new file mode 100755 index 0000000..66ee634 --- /dev/null +++ b/docs/models/shared/sourceinput.md @@ -0,0 +1,14 @@ +# SourceInput + + +## Fields + +| Field | Type | Required | Description | Example | +| ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | ---------------------------------------------------------- | +| `BigqueryConfig` | [*BigQueryConfig](../../models/shared/bigqueryconfig.md) | :heavy_minus_sign: | N/A | | +| `ConnectionType` | [ConnectionType](../../models/shared/connectiontype.md) | :heavy_check_mark: | N/A | | +| `DisplayName` | *string* | :heavy_check_mark: | N/A | Frontend Events | +| `EndCustomerID` | *string* | :heavy_check_mark: | N/A | abcd-1234-efgh-5678 | +| `MongodbConfig` | [*MongoDbConfig](../../models/shared/mongodbconfig.md) | :heavy_minus_sign: | N/A | | +| `RedshiftConfig` | [*RedshiftConfig](../../models/shared/redshiftconfig.md) | :heavy_minus_sign: | N/A | | +| `SnowflakeConfig` | [*SnowflakeConfig](../../models/shared/snowflakeconfig.md) | :heavy_minus_sign: | N/A | | \ No newline at end of file diff --git a/docs/models/shared/sync.md b/docs/models/shared/sync.md new file mode 100755 index 0000000..23126f0 --- /dev/null +++ b/docs/models/shared/sync.md @@ -0,0 +1,21 @@ +# Sync + + +## Fields + +| Field | Type | Required | Description | Example | +| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | +| `CursorField` | **string* | :heavy_minus_sign: | N/A | updated_at | +| `CustomJoin` | **string* | :heavy_minus_sign: | N/A | select * from events join additional_properties on events.id = additional_properties.event_id; | +| `DestinationID` | **int64* | :heavy_minus_sign: | N/A | 2 | +| `DisplayName` | **string* | :heavy_minus_sign: | N/A | Event Sync | +| `EndCustomerID` | **string* | :heavy_minus_sign: | N/A | abc123 | +| `FieldMappings` | [][FieldMapping](../../models/shared/fieldmapping.md) | :heavy_minus_sign: | N/A | [object Object] | +| `Frequency` | **int64* | :heavy_minus_sign: | N/A | | +| `FrequencyUnits` | [*FrequencyUnits](../../models/shared/frequencyunits.md) | :heavy_minus_sign: | N/A | | +| `ID` | **int64* | :heavy_minus_sign: | N/A | 10 | +| `Namespace` | **string* | :heavy_minus_sign: | N/A | end_customer_bigquery_dataset | +| `ObjectID` | **int64* | :heavy_minus_sign: | N/A | 3 | +| `PrimaryKey` | **string* | :heavy_minus_sign: | N/A | event_id | +| `SourceID` | **int64* | :heavy_minus_sign: | N/A | 1 | +| `TableName` | **string* | :heavy_minus_sign: | N/A | end_customer_events | \ No newline at end of file diff --git a/docs/models/shared/syncinput.md b/docs/models/shared/syncinput.md new file mode 100755 index 0000000..8f2bf13 --- /dev/null +++ b/docs/models/shared/syncinput.md @@ -0,0 +1,20 @@ +# SyncInput + + +## Fields + +| Field | Type | Required | Description | Example | +| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | +| `CursorField` | **string* | :heavy_minus_sign: | N/A | updated_at | +| `CustomJoin` | **string* | :heavy_minus_sign: | N/A | select * from events join additional_properties on events.id = additional_properties.event_id; | +| `DestinationID` | *int64* | :heavy_check_mark: | N/A | 2 | +| `DisplayName` | *string* | :heavy_check_mark: | N/A | Event Sync | +| `EndCustomerID` | *string* | :heavy_check_mark: | N/A | abc123 | +| `FieldMappings` | [][FieldMapping](../../models/shared/fieldmapping.md) | :heavy_check_mark: | N/A | [object Object] | +| `Frequency` | **int64* | :heavy_minus_sign: | N/A | 30 | +| `FrequencyUnits` | [*FrequencyUnits](../../models/shared/frequencyunits.md) | :heavy_minus_sign: | N/A | | +| `Namespace` | **string* | :heavy_minus_sign: | N/A | end_customer_bigquery_dataset | +| `ObjectID` | *int64* | :heavy_check_mark: | N/A | 3 | +| `PrimaryKey` | **string* | :heavy_minus_sign: | N/A | event_id | +| `SourceID` | *int64* | :heavy_check_mark: | N/A | 1 | +| `TableName` | **string* | :heavy_minus_sign: | N/A | end_customer_events | \ No newline at end of file diff --git a/docs/object/README.md b/docs/object/README.md deleted file mode 100755 index c708209..0000000 --- a/docs/object/README.md +++ /dev/null @@ -1,95 +0,0 @@ -# Object - -## Overview - -Operations on objects - -### Available Operations - -* [CreateObject](#createobject) - Create a new object -* [GetObjects](#getobjects) - Get all objects - -## CreateObject - -Create a new object - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" - "github.com/fabra-io/go-sdk/pkg/models/shared" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Object.CreateObject(ctx, shared.ObjectInput{ - DestinationID: 2, - DisplayName: "BigQuery", - EndCustomerIDField: "end_customer_id", - Namespace: "bigquery_dataset", - ObjectFields: []shared.ObjectField{ - shared.ObjectField{ - Name: fabra.String("event_name"), - Type: shared.FieldTypeEnumJSON.ToPointer(), - }, - shared.ObjectField{ - Name: fabra.String("event_name"), - Type: shared.FieldTypeEnumJSON.ToPointer(), - }, - }, - TableName: "events", - }) - if err != nil { - log.Fatal(err) - } - - if res.CreateObject200ApplicationJSONObject != nil { - // handle response - } -} -``` - -## GetObjects - -Get all objects - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Object.GetObjects(ctx) - if err != nil { - log.Fatal(err) - } - - if res.GetObjects200ApplicationJSONObject != nil { - // handle response - } -} -``` diff --git a/docs/sdks/connection/README.md b/docs/sdks/connection/README.md new file mode 100755 index 0000000..e7bc2ad --- /dev/null +++ b/docs/sdks/connection/README.md @@ -0,0 +1,168 @@ +# Connection +(*Connection*) + +## Overview + +Operations on connections + +### Available Operations + +* [GetNamespaces](#getnamespaces) - Get all namespaces +* [GetSchema](#getschema) - Get schema for table +* [GetTables](#gettables) - Get all tables + +## GetNamespaces + +Get all namespaces + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + + var connectionID int64 = 995455 + + ctx := context.Background() + res, err := s.Connection.GetNamespaces(ctx, connectionID) + if err != nil { + log.Fatal(err) + } + + if res.Namespaces != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | +| `connectionID` | *int64* | :heavy_check_mark: | N/A | + + +### Response + +**[*operations.GetNamespacesResponse](../../models/operations/getnamespacesresponse.md), error** + + +## GetSchema + +Get schema for table + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + + var connectionID int64 = 367941 + + var namespace string = "string" + + var tableName string = "string" + + ctx := context.Background() + res, err := s.Connection.GetSchema(ctx, connectionID, namespace, tableName) + if err != nil { + log.Fatal(err) + } + + if res.GetSchema200ApplicationJSONObject != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | +| `connectionID` | *int64* | :heavy_check_mark: | N/A | +| `namespace` | *string* | :heavy_check_mark: | N/A | +| `tableName` | *string* | :heavy_check_mark: | N/A | + + +### Response + +**[*operations.GetSchemaResponse](../../models/operations/getschemaresponse.md), error** + + +## GetTables + +Get all tables + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + + var connectionID int64 = 820803 + + var namespace string = "string" + + ctx := context.Background() + res, err := s.Connection.GetTables(ctx, connectionID, namespace) + if err != nil { + log.Fatal(err) + } + + if res.GetTables200ApplicationJSONObject != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | +| `connectionID` | *int64* | :heavy_check_mark: | N/A | +| `namespace` | *string* | :heavy_check_mark: | N/A | + + +### Response + +**[*operations.GetTablesResponse](../../models/operations/gettablesresponse.md), error** + diff --git a/docs/sdks/customerdata/README.md b/docs/sdks/customerdata/README.md new file mode 100755 index 0000000..5ad99ad --- /dev/null +++ b/docs/sdks/customerdata/README.md @@ -0,0 +1,69 @@ +# CustomerData +(*CustomerData*) + +### Available Operations + +* [QueryObject](#queryobject) - Query object record for customer + +## QueryObject + +Query a single object record directly from a customer's source. The response payload will match the object schema you've defined. + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" + "github.com/fabra-io/go-sdk/pkg/models/operations" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + + var endCustomerID string = "string" + + var objectID int64 = 906396 + + requestBody := &operations.QueryObjectRequestBody{ + Filters: []shared.QueryFilter{ + shared.QueryFilter{ + FieldName: "user_id", + FieldValue: "2", + }, + }, + } + + ctx := context.Background() + res, err := s.CustomerData.QueryObject(ctx, endCustomerID, objectID, requestBody) + if err != nil { + log.Fatal(err) + } + + if res.QueryObject200ApplicationJSONObject != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | +| `endCustomerID` | *string* | :heavy_check_mark: | N/A | +| `objectID` | *int64* | :heavy_check_mark: | N/A | +| `requestBody` | [*operations.QueryObjectRequestBody](../../models/operations/queryobjectrequestbody.md) | :heavy_minus_sign: | N/A | + + +### Response + +**[*operations.QueryObjectResponse](../../models/operations/queryobjectresponse.md), error** + diff --git a/docs/sdks/destination/README.md b/docs/sdks/destination/README.md new file mode 100755 index 0000000..ec255de --- /dev/null +++ b/docs/sdks/destination/README.md @@ -0,0 +1,130 @@ +# Destination +(*Destination*) + +## Overview + +Operations on destinations + +### Available Operations + +* [CreateDestination](#createdestination) - Create a new destination +* [GetDestinations](#getdestinations) - Get all destinations + +## CreateDestination + +Create a new destination + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + ctx := context.Background() + res, err := s.Destination.CreateDestination(ctx, shared.DestinationInput{ + BigqueryConfig: &shared.BigQueryConfig{ + Credentials: gosdk.String("Paste JSON from GCP"), + Location: "us-west1", + }, + ConnectionType: shared.ConnectionTypeSnowflake, + DisplayName: "BigQuery", + MongodbConfig: &shared.MongoDbConfig{ + ConnectionOptions: gosdk.String("retryWrites=true&w=majority"), + Host: "examplecluster.abc123.mongodb.net", + Password: "securePassword123", + Username: "jane_doe", + }, + RedshiftConfig: &shared.RedshiftConfig{ + DatabaseName: "your_database", + Host: "examplecluster.12345.us-west-1.redshift.amazonaws.com", + Password: "securePassword123", + Port: "5432", + Username: "jane_doe", + }, + SnowflakeConfig: &shared.SnowflakeConfig{ + DatabaseName: "your_database", + Host: "abc123.us-east4.gcp.snowflakecomputing.com", + Password: "securePassword123", + Role: "your_role", + Username: "jane_doe", + WarehouseName: "your_warehouse", + }, + }) + if err != nil { + log.Fatal(err) + } + + if res.CreateDestination200ApplicationJSONObject != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ------------------------------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ | ------------------------------------------------------------------ | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | +| `request` | [shared.DestinationInput](../../models/shared/destinationinput.md) | :heavy_check_mark: | The request object to use for the request. | + + +### Response + +**[*operations.CreateDestinationResponse](../../models/operations/createdestinationresponse.md), error** + + +## GetDestinations + +Get all destinations + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + ctx := context.Background() + res, err := s.Destination.GetDestinations(ctx) + if err != nil { + log.Fatal(err) + } + + if res.GetDestinations200ApplicationJSONObject != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | + + +### Response + +**[*operations.GetDestinationsResponse](../../models/operations/getdestinationsresponse.md), error** + diff --git a/docs/fabra/README.md b/docs/sdks/fabra/README.md similarity index 73% rename from docs/fabra/README.md rename to docs/sdks/fabra/README.md index bbdc71b..08b370d 100755 --- a/docs/fabra/README.md +++ b/docs/sdks/fabra/README.md @@ -1,4 +1,7 @@ # Fabra SDK + +## Overview + ### Available Operations diff --git a/docs/sdks/linktoken/README.md b/docs/sdks/linktoken/README.md new file mode 100755 index 0000000..359be6f --- /dev/null +++ b/docs/sdks/linktoken/README.md @@ -0,0 +1,58 @@ +# LinkToken +(*LinkToken*) + +## Overview + +Operations on link tokens + +### Available Operations + +* [CreateLinkToken](#createlinktoken) - Create a new link token + +## CreateLinkToken + +Create a new link token + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + ctx := context.Background() + res, err := s.LinkToken.CreateLinkToken(ctx, shared.CreateLinkTokenRequest{ + EndCustomerID: "abcd-1234-efgh-5678", + }) + if err != nil { + log.Fatal(err) + } + + if res.CreateLinkTokenResponse != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | +| `request` | [shared.CreateLinkTokenRequest](../../models/shared/createlinktokenrequest.md) | :heavy_check_mark: | The request object to use for the request. | + + +### Response + +**[*operations.CreateLinkTokenResponse](../../models/operations/createlinktokenresponse.md), error** + diff --git a/docs/sdks/object/README.md b/docs/sdks/object/README.md new file mode 100755 index 0000000..1440d93 --- /dev/null +++ b/docs/sdks/object/README.md @@ -0,0 +1,117 @@ +# Object +(*Object*) + +## Overview + +Operations on objects + +### Available Operations + +* [CreateObject](#createobject) - Create a new object +* [GetObjects](#getobjects) - Get all objects + +## CreateObject + +Create a new object + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + ctx := context.Background() + res, err := s.Object.CreateObject(ctx, shared.ObjectInput{ + CursorField: gosdk.String("updated_at"), + DestinationID: 2, + DisplayName: "BigQuery", + EndCustomerIDField: "end_customer_id", + Frequency: 30, + FrequencyUnits: shared.FrequencyUnitsMinutes, + Namespace: "bigquery_dataset", + ObjectFields: []shared.ObjectField{ + shared.ObjectField{ + Name: gosdk.String("event_name"), + }, + }, + PrimaryKey: gosdk.String("event_id"), + TableName: "events", + }) + if err != nil { + log.Fatal(err) + } + + if res.CreateObject200ApplicationJSONObject != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | +| `request` | [shared.ObjectInput](../../models/shared/objectinput.md) | :heavy_check_mark: | The request object to use for the request. | + + +### Response + +**[*operations.CreateObjectResponse](../../models/operations/createobjectresponse.md), error** + + +## GetObjects + +Get all objects + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + ctx := context.Background() + res, err := s.Object.GetObjects(ctx) + if err != nil { + log.Fatal(err) + } + + if res.GetObjects200ApplicationJSONObject != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | + + +### Response + +**[*operations.GetObjectsResponse](../../models/operations/getobjectsresponse.md), error** + diff --git a/docs/sdks/source/README.md b/docs/sdks/source/README.md new file mode 100755 index 0000000..197414c --- /dev/null +++ b/docs/sdks/source/README.md @@ -0,0 +1,131 @@ +# Source +(*Source*) + +## Overview + +Operations on sources + +### Available Operations + +* [CreateSource](#createsource) - Create a new source +* [GetSources](#getsources) - Get all sources + +## CreateSource + +Create a new source + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + ctx := context.Background() + res, err := s.Source.CreateSource(ctx, shared.SourceInput{ + BigqueryConfig: &shared.BigQueryConfig{ + Credentials: gosdk.String("Paste JSON from GCP"), + Location: "us-west1", + }, + ConnectionType: shared.ConnectionTypeWebhook, + DisplayName: "Frontend Events", + EndCustomerID: "abcd-1234-efgh-5678", + MongodbConfig: &shared.MongoDbConfig{ + ConnectionOptions: gosdk.String("retryWrites=true&w=majority"), + Host: "examplecluster.abc123.mongodb.net", + Password: "securePassword123", + Username: "jane_doe", + }, + RedshiftConfig: &shared.RedshiftConfig{ + DatabaseName: "your_database", + Host: "examplecluster.12345.us-west-1.redshift.amazonaws.com", + Password: "securePassword123", + Port: "5432", + Username: "jane_doe", + }, + SnowflakeConfig: &shared.SnowflakeConfig{ + DatabaseName: "your_database", + Host: "abc123.us-east4.gcp.snowflakecomputing.com", + Password: "securePassword123", + Role: "your_role", + Username: "jane_doe", + WarehouseName: "your_warehouse", + }, + }) + if err != nil { + log.Fatal(err) + } + + if res.CreateSource200ApplicationJSONObject != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | +| `request` | [shared.SourceInput](../../models/shared/sourceinput.md) | :heavy_check_mark: | The request object to use for the request. | + + +### Response + +**[*operations.CreateSourceResponse](../../models/operations/createsourceresponse.md), error** + + +## GetSources + +Get all sources + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + ctx := context.Background() + res, err := s.Source.GetSources(ctx) + if err != nil { + log.Fatal(err) + } + + if res.GetSources200ApplicationJSONObject != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | + + +### Response + +**[*operations.GetSourcesResponse](../../models/operations/getsourcesresponse.md), error** + diff --git a/docs/sdks/sync/README.md b/docs/sdks/sync/README.md new file mode 100755 index 0000000..b4e1d4a --- /dev/null +++ b/docs/sdks/sync/README.md @@ -0,0 +1,120 @@ +# Sync +(*Sync*) + +## Overview + +Operations on syncs + +### Available Operations + +* [CreateSync](#createsync) - Create a new sync +* [GetSyncs](#getsyncs) - Get all syncs + +## CreateSync + +Create a new sync + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + ctx := context.Background() + res, err := s.Sync.CreateSync(ctx, shared.SyncInput{ + CursorField: gosdk.String("updated_at"), + CustomJoin: gosdk.String("select * from events join additional_properties on events.id = additional_properties.event_id;"), + DestinationID: 2, + DisplayName: "Event Sync", + EndCustomerID: "abc123", + FieldMappings: []shared.FieldMapping{ + shared.FieldMapping{ + DestinationFieldName: gosdk.String("event"), + SourceFieldName: gosdk.String("event_name"), + }, + }, + Frequency: gosdk.Int64(30), + Namespace: gosdk.String("end_customer_bigquery_dataset"), + ObjectID: 3, + PrimaryKey: gosdk.String("event_id"), + SourceID: 1, + TableName: gosdk.String("end_customer_events"), + }) + if err != nil { + log.Fatal(err) + } + + if res.CreateSync200ApplicationJSONObject != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | +| `request` | [shared.SyncInput](../../models/shared/syncinput.md) | :heavy_check_mark: | The request object to use for the request. | + + +### Response + +**[*operations.CreateSyncResponse](../../models/operations/createsyncresponse.md), error** + + +## GetSyncs + +Get all syncs + +### Example Usage + +```go +package main + +import( + "context" + "log" + gosdk "github.com/fabra-io/go-sdk" + "github.com/fabra-io/go-sdk/pkg/models/shared" +) + +func main() { + s := gosdk.New( + gosdk.WithSecurity(""), + ) + + ctx := context.Background() + res, err := s.Sync.GetSyncs(ctx) + if err != nil { + log.Fatal(err) + } + + if res.GetSyncs200ApplicationJSONObject != nil { + // handle response + } +} +``` + +### Parameters + +| Parameter | Type | Required | Description | +| ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | +| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. | + + +### Response + +**[*operations.GetSyncsResponse](../../models/operations/getsyncsresponse.md), error** + diff --git a/docs/source/README.md b/docs/source/README.md deleted file mode 100755 index 771ed4c..0000000 --- a/docs/source/README.md +++ /dev/null @@ -1,108 +0,0 @@ -# Source - -## Overview - -Operations on sources - -### Available Operations - -* [CreateSource](#createsource) - Create a new source -* [GetSources](#getsources) - Get all sources - -## CreateSource - -Create a new source - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" - "github.com/fabra-io/go-sdk/pkg/models/shared" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Source.CreateSource(ctx, shared.SourceInput{ - BigqueryConfig: &shared.BigQueryConfig{ - Credentials: fabra.String("Paste JSON from GCP"), - Location: "us-west1", - }, - ConnectionType: shared.ConnectionTypeEnumBigquery, - DisplayName: "Frontend Events", - EndCustomerID: 123, - MongodbConfig: &shared.MongoDbConfig{ - ConnectionOptions: fabra.String("retryWrites=true&w=majority"), - Host: "examplecluster.abc123.mongodb.net", - Password: "securePassword123", - Username: "jane_doe", - }, - RedshiftConfig: &shared.RedshiftConfig{ - DatabaseName: "your_database", - Host: "examplecluster.12345.us-west-1.redshift.amazonaws.com", - Password: "securePassword123", - Port: "5432", - Username: "jane_doe", - }, - SnowflakeConfig: &shared.SnowflakeConfig{ - DatabaseName: "your_database", - Host: "abc123.us-east4.gcp.snowflakecomputing.com", - Password: "securePassword123", - Role: "your_role", - Username: "jane_doe", - WarehouseName: "your_warehouse", - }, - }) - if err != nil { - log.Fatal(err) - } - - if res.CreateSource200ApplicationJSONObject != nil { - // handle response - } -} -``` - -## GetSources - -Get all sources - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Source.GetSources(ctx) - if err != nil { - log.Fatal(err) - } - - if res.GetSources200ApplicationJSONObject != nil { - // handle response - } -} -``` diff --git a/docs/sync/README.md b/docs/sync/README.md deleted file mode 100755 index 6cd9f94..0000000 --- a/docs/sync/README.md +++ /dev/null @@ -1,101 +0,0 @@ -# Sync - -## Overview - -Operations on syncs - -### Available Operations - -* [CreateSync](#createsync) - Create a new sync -* [GetSyncs](#getsyncs) - Get all syncs - -## CreateSync - -Create a new sync - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" - "github.com/fabra-io/go-sdk/pkg/models/shared" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Sync.CreateSync(ctx, shared.SyncInput{ - CursorField: fabra.String("updated_at"), - CustomJoin: fabra.String("select * from events join additional_properties on events.id = additional_properties.event_id;"), - DestinationID: 2, - DisplayName: "Event Sync", - FieldMappings: []shared.FieldMapping{ - shared.FieldMapping{ - DestinationFieldName: fabra.String("event"), - SourceFieldName: fabra.String("event_name"), - }, - shared.FieldMapping{ - DestinationFieldName: fabra.String("event"), - SourceFieldName: fabra.String("event_name"), - }, - }, - Frequency: 30, - FrequencyUnits: shared.FrequencyUnitsEnumHours, - Namespace: fabra.String("end_customer_bigquery_dataset"), - ObjectID: 3, - PrimaryKey: fabra.String("event_id"), - SourceID: 1, - TableName: fabra.String("end_customer_events"), - }) - if err != nil { - log.Fatal(err) - } - - if res.CreateSync200ApplicationJSONObject != nil { - // handle response - } -} -``` - -## GetSyncs - -Get all syncs - -### Example Usage - -```go -package main - -import( - "context" - "log" - "github.com/fabra-io/go-sdk" -) - -func main() { - s := fabra.New( - fabra.WithSecurity(shared.Security{ - APIKeyAuth: "YOUR_API_KEY_HERE", - }), - ) - - ctx := context.Background() - res, err := s.Sync.GetSyncs(ctx) - if err != nil { - log.Fatal(err) - } - - if res.GetSyncs200ApplicationJSONObject != nil { - // handle response - } -} -``` diff --git a/fabra.go b/fabra.go index 5a80abe..4d05877 100755 --- a/fabra.go +++ b/fabra.go @@ -1,8 +1,10 @@ // Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. -package fabra +package gosdk import ( + "context" + "fmt" "github.com/fabra-io/go-sdk/pkg/models/shared" "github.com/fabra-io/go-sdk/pkg/utils" "net/http" @@ -37,28 +39,44 @@ func Float32(f float32) *float32 { return &f } // Float64 provides a helper function to return a pointer to a float64 func Float64(f float64) *float64 { return &f } +type sdkConfiguration struct { + DefaultClient HTTPClient + SecurityClient HTTPClient + Security func(context.Context) (interface{}, error) + ServerURL string + ServerIndex int + Language string + OpenAPIDocVersion string + SDKVersion string + GenVersion string + UserAgent string + RetryConfig *utils.RetryConfig +} + +func (c *sdkConfiguration) GetServerDetails() (string, map[string]string) { + if c.ServerURL != "" { + return c.ServerURL, nil + } + + return ServerList[c.ServerIndex], nil +} + type Fabra struct { - // Connection - Operations on connections - Connection *connection - // Destination - Operations on destinations + // Operations on connections + Connection *connection + CustomerData *customerData + // Operations on destinations Destination *destination - // LinkToken - Operations on link tokens + // Operations on link tokens LinkToken *linkToken - // Object - Operations on objects + // Operations on objects Object *object - // Source - Operations on sources + // Operations on sources Source *source - // Sync - Operations on syncs + // Operations on syncs Sync *sync - // Non-idiomatic field names below are to namespace fields from the fields names above to avoid name conflicts - _defaultClient HTTPClient - _securityClient HTTPClient - _security *shared.Security - _serverURL string - _language string - _sdkVersion string - _genVersion string + sdkConfiguration sdkConfiguration } type SDKOption func(*Fabra) @@ -66,7 +84,7 @@ type SDKOption func(*Fabra) // WithServerURL allows the overriding of the default server URL func WithServerURL(serverURL string) SDKOption { return func(sdk *Fabra) { - sdk._serverURL = serverURL + sdk.sdkConfiguration.ServerURL = serverURL } } @@ -77,104 +95,89 @@ func WithTemplatedServerURL(serverURL string, params map[string]string) SDKOptio serverURL = utils.ReplaceParameters(serverURL, params) } - sdk._serverURL = serverURL + sdk.sdkConfiguration.ServerURL = serverURL + } +} + +// WithServerIndex allows the overriding of the default server by index +func WithServerIndex(serverIndex int) SDKOption { + return func(sdk *Fabra) { + if serverIndex < 0 || serverIndex >= len(ServerList) { + panic(fmt.Errorf("server index %d out of range", serverIndex)) + } + + sdk.sdkConfiguration.ServerIndex = serverIndex } } // WithClient allows the overriding of the default HTTP client used by the SDK func WithClient(client HTTPClient) SDKOption { return func(sdk *Fabra) { - sdk._defaultClient = client + sdk.sdkConfiguration.DefaultClient = client + } +} + +func withSecurity(security interface{}) func(context.Context) (interface{}, error) { + return func(context.Context) (interface{}, error) { + return &security, nil } } // WithSecurity configures the SDK to use the provided security details -func WithSecurity(security shared.Security) SDKOption { + +func WithSecurity(apiKeyAuth string) SDKOption { + return func(sdk *Fabra) { + security := shared.Security{APIKeyAuth: apiKeyAuth} + sdk.sdkConfiguration.Security = withSecurity(&security) + } +} + +func WithRetryConfig(retryConfig utils.RetryConfig) SDKOption { return func(sdk *Fabra) { - sdk._security = &security + sdk.sdkConfiguration.RetryConfig = &retryConfig } } // New creates a new instance of the SDK with the provided options func New(opts ...SDKOption) *Fabra { sdk := &Fabra{ - _language: "go", - _sdkVersion: "0.6.0", - _genVersion: "2.26.0", + sdkConfiguration: sdkConfiguration{ + Language: "go", + OpenAPIDocVersion: "0.1.0", + SDKVersion: "0.10.0", + GenVersion: "2.169.0", + UserAgent: "speakeasy-sdk/go 0.10.0 2.169.0 0.1.0 github.com/fabra-io/go-sdk", + }, } for _, opt := range opts { opt(sdk) } // Use WithClient to override the default client if you would like to customize the timeout - if sdk._defaultClient == nil { - sdk._defaultClient = &http.Client{Timeout: 60 * time.Second} + if sdk.sdkConfiguration.DefaultClient == nil { + sdk.sdkConfiguration.DefaultClient = &http.Client{Timeout: 60 * time.Second} } - if sdk._securityClient == nil { - if sdk._security != nil { - sdk._securityClient = utils.ConfigureSecurityClient(sdk._defaultClient, sdk._security) + if sdk.sdkConfiguration.SecurityClient == nil { + if sdk.sdkConfiguration.Security != nil { + sdk.sdkConfiguration.SecurityClient = utils.ConfigureSecurityClient(sdk.sdkConfiguration.DefaultClient, sdk.sdkConfiguration.Security) } else { - sdk._securityClient = sdk._defaultClient + sdk.sdkConfiguration.SecurityClient = sdk.sdkConfiguration.DefaultClient } } - if sdk._serverURL == "" { - sdk._serverURL = ServerList[0] - } + sdk.Connection = newConnection(sdk.sdkConfiguration) + + sdk.CustomerData = newCustomerData(sdk.sdkConfiguration) + + sdk.Destination = newDestination(sdk.sdkConfiguration) + + sdk.LinkToken = newLinkToken(sdk.sdkConfiguration) + + sdk.Object = newObject(sdk.sdkConfiguration) + + sdk.Source = newSource(sdk.sdkConfiguration) - sdk.Connection = newConnection( - sdk._defaultClient, - sdk._securityClient, - sdk._serverURL, - sdk._language, - sdk._sdkVersion, - sdk._genVersion, - ) - - sdk.Destination = newDestination( - sdk._defaultClient, - sdk._securityClient, - sdk._serverURL, - sdk._language, - sdk._sdkVersion, - sdk._genVersion, - ) - - sdk.LinkToken = newLinkToken( - sdk._defaultClient, - sdk._securityClient, - sdk._serverURL, - sdk._language, - sdk._sdkVersion, - sdk._genVersion, - ) - - sdk.Object = newObject( - sdk._defaultClient, - sdk._securityClient, - sdk._serverURL, - sdk._language, - sdk._sdkVersion, - sdk._genVersion, - ) - - sdk.Source = newSource( - sdk._defaultClient, - sdk._securityClient, - sdk._serverURL, - sdk._language, - sdk._sdkVersion, - sdk._genVersion, - ) - - sdk.Sync = newSync( - sdk._defaultClient, - sdk._securityClient, - sdk._serverURL, - sdk._language, - sdk._sdkVersion, - sdk._genVersion, - ) + sdk.Sync = newSync(sdk.sdkConfiguration) return sdk } diff --git a/files.gen b/files.gen index 2b9fc7d..c7ebca5 100755 --- a/files.gen +++ b/files.gen @@ -1,4 +1,5 @@ connection.go +customerdata.go destination.go linktoken.go object.go @@ -7,20 +8,27 @@ sync.go fabra.go go.mod go.sum +pkg/models/sdkerrors/sdkerror.go +pkg/types/bigint.go pkg/types/date.go pkg/types/datetime.go +pkg/types/decimal.go +pkg/types/pointers.go pkg/utils/contenttype.go pkg/utils/form.go pkg/utils/headers.go +pkg/utils/json.go pkg/utils/pathparams.go pkg/utils/queryparams.go pkg/utils/requestbody.go pkg/utils/retries.go pkg/utils/security.go pkg/utils/utils.go +tests/helpers.go pkg/models/operations/getnamespaces.go pkg/models/operations/getschema.go pkg/models/operations/gettables.go +pkg/models/operations/queryobject.go pkg/models/operations/createdestination.go pkg/models/operations/getdestinations.go pkg/models/operations/createlinktoken.go @@ -32,10 +40,11 @@ pkg/models/operations/createsync.go pkg/models/operations/getsyncs.go pkg/models/shared/namespaces.go pkg/models/shared/field.go -pkg/models/shared/fieldtypeenum.go +pkg/models/shared/fieldtype.go +pkg/models/shared/queryfilter.go pkg/models/shared/destination.go pkg/models/shared/connection.go -pkg/models/shared/connectiontypeenum.go +pkg/models/shared/connectiontype.go pkg/models/shared/destinationinput.go pkg/models/shared/snowflakeconfig.go pkg/models/shared/redshiftconfig.go @@ -46,18 +55,74 @@ pkg/models/shared/createlinktokenrequest.go pkg/models/shared/object.go pkg/models/shared/objectfield.go pkg/models/shared/objectinput.go +pkg/models/shared/frequencyunits.go pkg/models/shared/source.go pkg/models/shared/sourceinput.go pkg/models/shared/sync.go -pkg/models/shared/frequencyunitsenum.go pkg/models/shared/fieldmapping.go pkg/models/shared/syncinput.go pkg/models/shared/security.go -docs/fabra/README.md -docs/connection/README.md -docs/destination/README.md -docs/linktoken/README.md -docs/object/README.md -docs/source/README.md -docs/sync/README.md -USAGE.md \ No newline at end of file +USAGE.md +docs/models/operations/getnamespacesrequest.md +docs/models/operations/getnamespacesresponse.md +docs/models/operations/getschemarequest.md +docs/models/operations/getschema200applicationjson.md +docs/models/operations/getschemaresponse.md +docs/models/operations/gettablesrequest.md +docs/models/operations/gettables200applicationjson.md +docs/models/operations/gettablesresponse.md +docs/models/operations/queryobjectrequestbody.md +docs/models/operations/queryobjectrequest.md +docs/models/operations/queryobject200applicationjsonexamplefield3.md +docs/models/operations/queryobject200applicationjson.md +docs/models/operations/queryobjectresponse.md +docs/models/operations/createdestination200applicationjson.md +docs/models/operations/createdestinationresponse.md +docs/models/operations/getdestinations200applicationjson.md +docs/models/operations/getdestinationsresponse.md +docs/models/operations/createlinktokenresponse.md +docs/models/operations/createobject200applicationjson.md +docs/models/operations/createobjectresponse.md +docs/models/operations/getobjects200applicationjson.md +docs/models/operations/getobjectsresponse.md +docs/models/operations/createsource200applicationjson.md +docs/models/operations/createsourceresponse.md +docs/models/operations/getsources200applicationjson.md +docs/models/operations/getsourcesresponse.md +docs/models/operations/createsync200applicationjson.md +docs/models/operations/createsyncresponse.md +docs/models/operations/getsyncs200applicationjson.md +docs/models/operations/getsyncsresponse.md +docs/models/shared/namespaces.md +docs/models/shared/field.md +docs/models/shared/fieldtype.md +docs/models/shared/queryfilter.md +docs/models/shared/destination.md +docs/models/shared/connection.md +docs/models/shared/connectiontype.md +docs/models/shared/destinationinput.md +docs/models/shared/snowflakeconfig.md +docs/models/shared/redshiftconfig.md +docs/models/shared/mongodbconfig.md +docs/models/shared/bigqueryconfig.md +docs/models/shared/createlinktokenresponse.md +docs/models/shared/createlinktokenrequest.md +docs/models/shared/object.md +docs/models/shared/objectfield.md +docs/models/shared/objectinput.md +docs/models/shared/frequencyunits.md +docs/models/shared/source.md +docs/models/shared/sourceinput.md +docs/models/shared/sync.md +docs/models/shared/fieldmapping.md +docs/models/shared/syncinput.md +docs/models/shared/security.md +docs/sdks/fabra/README.md +docs/sdks/connection/README.md +docs/sdks/customerdata/README.md +docs/sdks/destination/README.md +docs/sdks/linktoken/README.md +docs/sdks/object/README.md +docs/sdks/source/README.md +docs/sdks/sync/README.md +.gitattributes \ No newline at end of file diff --git a/gen.yaml b/gen.yaml index f01af5d..a5e5eda 100644 --- a/gen.yaml +++ b/gen.yaml @@ -1,14 +1,25 @@ configVersion: 1.0.0 management: - docChecksum: d016ae393133ddf484189d664481ef5c + docChecksum: a08d8b55b00bfb4ba4828a322fd16614 docVersion: 0.1.0 - speakeasyVersion: 1.29.0 - generationVersion: 2.26.0 + speakeasyVersion: 1.104.0 + generationVersion: 2.169.0 generation: - telemetryEnabled: false + repoURL: https://github.com/fabra-io/go-sdk.git sdkClassName: fabra singleTagPerOp: false + telemetryEnabled: false +features: + go: + core: 2.94.0 + flattening: 2.81.1 + globalSecurity: 2.82.2 + globalServerURLs: 2.82.0 go: - version: 0.6.0 + version: 0.10.0 + flattenGlobalSecurity: true + installationURL: https://github.com/fabra-io/go-sdk maxMethodParams: 5 packageName: github.com/fabra-io/go-sdk + published: true + repoSubDirectory: . diff --git a/go.mod b/go.mod index 9486ac7..a88bbd5 100755 --- a/go.mod +++ b/go.mod @@ -4,4 +4,7 @@ go 1.14 require ( github.com/cenkalti/backoff/v4 v4.2.0 + github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 + github.com/mitchellh/mapstructure v1.5.0 + github.com/spyzhov/ajson v0.8.0 ) diff --git a/go.sum b/go.sum index 2307997..ae03a47 100755 --- a/go.sum +++ b/go.sum @@ -1,2 +1,8 @@ github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 h1:S92OBrGuLLZsyM5ybUzgc/mPjIYk2AZqufieooe98uw= +github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/spyzhov/ajson v0.8.0 h1:sFXyMbi4Y/BKjrsfkUZHSjA2JM1184enheSjjoT/zCc= +github.com/spyzhov/ajson v0.8.0/go.mod h1:63V+CGM6f1Bu/p4nLIN8885ojBdt88TbLoSFzyqMuVA= diff --git a/linktoken.go b/linktoken.go index a3a9edd..3f1171c 100755 --- a/linktoken.go +++ b/linktoken.go @@ -1,45 +1,37 @@ // Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. -package fabra +package gosdk import ( + "bytes" "context" "fmt" "github.com/fabra-io/go-sdk/pkg/models/operations" + "github.com/fabra-io/go-sdk/pkg/models/sdkerrors" "github.com/fabra-io/go-sdk/pkg/models/shared" "github.com/fabra-io/go-sdk/pkg/utils" + "io" "net/http" "strings" ) // linkToken - Operations on link tokens type linkToken struct { - defaultClient HTTPClient - securityClient HTTPClient - serverURL string - language string - sdkVersion string - genVersion string + sdkConfiguration sdkConfiguration } -func newLinkToken(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *linkToken { +func newLinkToken(sdkConfig sdkConfiguration) *linkToken { return &linkToken{ - defaultClient: defaultClient, - securityClient: securityClient, - serverURL: serverURL, - language: language, - sdkVersion: sdkVersion, - genVersion: genVersion, + sdkConfiguration: sdkConfig, } } // CreateLinkToken - Create a new link token - func (s *linkToken) CreateLinkToken(ctx context.Context, request shared.CreateLinkTokenRequest) (*operations.CreateLinkTokenResponse, error) { - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/link_token" - bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, fmt.Errorf("error serializing request body: %w", err) } @@ -51,10 +43,12 @@ func (s *linkToken) CreateLinkToken(ctx context.Context, request shared.CreateLi if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) req.Header.Set("Content-Type", reqContentType) - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -63,7 +57,6 @@ func (s *linkToken) CreateLinkToken(ctx context.Context, request shared.CreateLi if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -72,16 +65,25 @@ func (s *linkToken) CreateLinkToken(ctx context.Context, request shared.CreateLi ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *shared.CreateLinkTokenResponse - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out shared.CreateLinkTokenResponse + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.CreateLinkTokenResponse = out + res.CreateLinkTokenResponse = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough diff --git a/object.go b/object.go index 91e3049..d8e8bc7 100755 --- a/object.go +++ b/object.go @@ -1,45 +1,37 @@ // Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. -package fabra +package gosdk import ( + "bytes" "context" "fmt" "github.com/fabra-io/go-sdk/pkg/models/operations" + "github.com/fabra-io/go-sdk/pkg/models/sdkerrors" "github.com/fabra-io/go-sdk/pkg/models/shared" "github.com/fabra-io/go-sdk/pkg/utils" + "io" "net/http" "strings" ) // object - Operations on objects type object struct { - defaultClient HTTPClient - securityClient HTTPClient - serverURL string - language string - sdkVersion string - genVersion string + sdkConfiguration sdkConfiguration } -func newObject(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *object { +func newObject(sdkConfig sdkConfiguration) *object { return &object{ - defaultClient: defaultClient, - securityClient: securityClient, - serverURL: serverURL, - language: language, - sdkVersion: sdkVersion, - genVersion: genVersion, + sdkConfiguration: sdkConfig, } } // CreateObject - Create a new object - func (s *object) CreateObject(ctx context.Context, request shared.ObjectInput) (*operations.CreateObjectResponse, error) { - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/object" - bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, fmt.Errorf("error serializing request body: %w", err) } @@ -51,10 +43,12 @@ func (s *object) CreateObject(ctx context.Context, request shared.ObjectInput) ( if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) req.Header.Set("Content-Type", reqContentType) - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -63,7 +57,6 @@ func (s *object) CreateObject(ctx context.Context, request shared.ObjectInput) ( if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -72,16 +65,25 @@ func (s *object) CreateObject(ctx context.Context, request shared.ObjectInput) ( ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *operations.CreateObject200ApplicationJSON - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out operations.CreateObject200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.CreateObject200ApplicationJSONObject = out + res.CreateObject200ApplicationJSONObject = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough @@ -92,17 +94,18 @@ func (s *object) CreateObject(ctx context.Context, request shared.ObjectInput) ( } // GetObjects - Get all objects - func (s *object) GetObjects(ctx context.Context) (*operations.GetObjectsResponse, error) { - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/objects" req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -111,7 +114,6 @@ func (s *object) GetObjects(ctx context.Context) (*operations.GetObjectsResponse if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -120,16 +122,25 @@ func (s *object) GetObjects(ctx context.Context) (*operations.GetObjectsResponse ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *operations.GetObjects200ApplicationJSON - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out operations.GetObjects200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.GetObjects200ApplicationJSONObject = out + res.GetObjects200ApplicationJSONObject = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough diff --git a/pkg/models/operations/createdestination.go b/pkg/models/operations/createdestination.go index 839653d..5b39258 100755 --- a/pkg/models/operations/createdestination.go +++ b/pkg/models/operations/createdestination.go @@ -12,10 +12,48 @@ type CreateDestination200ApplicationJSON struct { Destination *shared.Destination `json:"destination,omitempty"` } +func (o *CreateDestination200ApplicationJSON) GetDestination() *shared.Destination { + if o == nil { + return nil + } + return o.Destination +} + type CreateDestinationResponse struct { + // HTTP response content type for this operation ContentType string - StatusCode int + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing RawResponse *http.Response // Successfully created destination CreateDestination200ApplicationJSONObject *CreateDestination200ApplicationJSON } + +func (o *CreateDestinationResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *CreateDestinationResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *CreateDestinationResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} + +func (o *CreateDestinationResponse) GetCreateDestination200ApplicationJSONObject() *CreateDestination200ApplicationJSON { + if o == nil { + return nil + } + return o.CreateDestination200ApplicationJSONObject +} diff --git a/pkg/models/operations/createlinktoken.go b/pkg/models/operations/createlinktoken.go index 869700e..0aaa588 100755 --- a/pkg/models/operations/createlinktoken.go +++ b/pkg/models/operations/createlinktoken.go @@ -8,9 +8,40 @@ import ( ) type CreateLinkTokenResponse struct { + // HTTP response content type for this operation ContentType string // Successfully created link token CreateLinkTokenResponse *shared.CreateLinkTokenResponse - StatusCode int - RawResponse *http.Response + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response +} + +func (o *CreateLinkTokenResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *CreateLinkTokenResponse) GetCreateLinkTokenResponse() *shared.CreateLinkTokenResponse { + if o == nil { + return nil + } + return o.CreateLinkTokenResponse +} + +func (o *CreateLinkTokenResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *CreateLinkTokenResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse } diff --git a/pkg/models/operations/createobject.go b/pkg/models/operations/createobject.go index 00ed9f5..7ddda85 100755 --- a/pkg/models/operations/createobject.go +++ b/pkg/models/operations/createobject.go @@ -12,10 +12,48 @@ type CreateObject200ApplicationJSON struct { Object *shared.Object `json:"object,omitempty"` } +func (o *CreateObject200ApplicationJSON) GetObject() *shared.Object { + if o == nil { + return nil + } + return o.Object +} + type CreateObjectResponse struct { + // HTTP response content type for this operation ContentType string - StatusCode int + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing RawResponse *http.Response // Successfully created object CreateObject200ApplicationJSONObject *CreateObject200ApplicationJSON } + +func (o *CreateObjectResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *CreateObjectResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *CreateObjectResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} + +func (o *CreateObjectResponse) GetCreateObject200ApplicationJSONObject() *CreateObject200ApplicationJSON { + if o == nil { + return nil + } + return o.CreateObject200ApplicationJSONObject +} diff --git a/pkg/models/operations/createsource.go b/pkg/models/operations/createsource.go index 1697bed..cd459be 100755 --- a/pkg/models/operations/createsource.go +++ b/pkg/models/operations/createsource.go @@ -12,10 +12,48 @@ type CreateSource200ApplicationJSON struct { Source *shared.Source `json:"source,omitempty"` } +func (o *CreateSource200ApplicationJSON) GetSource() *shared.Source { + if o == nil { + return nil + } + return o.Source +} + type CreateSourceResponse struct { + // HTTP response content type for this operation ContentType string - StatusCode int + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing RawResponse *http.Response // Successfully created source CreateSource200ApplicationJSONObject *CreateSource200ApplicationJSON } + +func (o *CreateSourceResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *CreateSourceResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *CreateSourceResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} + +func (o *CreateSourceResponse) GetCreateSource200ApplicationJSONObject() *CreateSource200ApplicationJSON { + if o == nil { + return nil + } + return o.CreateSource200ApplicationJSONObject +} diff --git a/pkg/models/operations/createsync.go b/pkg/models/operations/createsync.go index 40353cc..0ff0935 100755 --- a/pkg/models/operations/createsync.go +++ b/pkg/models/operations/createsync.go @@ -12,10 +12,48 @@ type CreateSync200ApplicationJSON struct { Sync *shared.Sync `json:"sync,omitempty"` } +func (o *CreateSync200ApplicationJSON) GetSync() *shared.Sync { + if o == nil { + return nil + } + return o.Sync +} + type CreateSyncResponse struct { + // HTTP response content type for this operation ContentType string - StatusCode int + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing RawResponse *http.Response // Successfully created sync CreateSync200ApplicationJSONObject *CreateSync200ApplicationJSON } + +func (o *CreateSyncResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *CreateSyncResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *CreateSyncResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} + +func (o *CreateSyncResponse) GetCreateSync200ApplicationJSONObject() *CreateSync200ApplicationJSON { + if o == nil { + return nil + } + return o.CreateSync200ApplicationJSONObject +} diff --git a/pkg/models/operations/getdestinations.go b/pkg/models/operations/getdestinations.go index 7708046..5f173fa 100755 --- a/pkg/models/operations/getdestinations.go +++ b/pkg/models/operations/getdestinations.go @@ -12,10 +12,48 @@ type GetDestinations200ApplicationJSON struct { Destinations []shared.Destination `json:"destinations,omitempty"` } +func (o *GetDestinations200ApplicationJSON) GetDestinations() []shared.Destination { + if o == nil { + return nil + } + return o.Destinations +} + type GetDestinationsResponse struct { + // HTTP response content type for this operation ContentType string - StatusCode int + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing RawResponse *http.Response // Successfully fetched destinations GetDestinations200ApplicationJSONObject *GetDestinations200ApplicationJSON } + +func (o *GetDestinationsResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *GetDestinationsResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *GetDestinationsResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} + +func (o *GetDestinationsResponse) GetGetDestinations200ApplicationJSONObject() *GetDestinations200ApplicationJSON { + if o == nil { + return nil + } + return o.GetDestinations200ApplicationJSONObject +} diff --git a/pkg/models/operations/getnamespaces.go b/pkg/models/operations/getnamespaces.go index 377d188..d22fe5c 100755 --- a/pkg/models/operations/getnamespaces.go +++ b/pkg/models/operations/getnamespaces.go @@ -11,10 +11,48 @@ type GetNamespacesRequest struct { ConnectionID int64 `queryParam:"style=form,explode=true,name=connectionID"` } +func (o *GetNamespacesRequest) GetConnectionID() int64 { + if o == nil { + return 0 + } + return o.ConnectionID +} + type GetNamespacesResponse struct { + // HTTP response content type for this operation ContentType string // Successfully fetched namespaces - Namespaces *shared.Namespaces - StatusCode int + Namespaces *shared.Namespaces + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing RawResponse *http.Response } + +func (o *GetNamespacesResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *GetNamespacesResponse) GetNamespaces() *shared.Namespaces { + if o == nil { + return nil + } + return o.Namespaces +} + +func (o *GetNamespacesResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *GetNamespacesResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} diff --git a/pkg/models/operations/getobjects.go b/pkg/models/operations/getobjects.go index e1cd52d..5b9a517 100755 --- a/pkg/models/operations/getobjects.go +++ b/pkg/models/operations/getobjects.go @@ -12,10 +12,48 @@ type GetObjects200ApplicationJSON struct { Objects []shared.Object `json:"objects,omitempty"` } +func (o *GetObjects200ApplicationJSON) GetObjects() []shared.Object { + if o == nil { + return nil + } + return o.Objects +} + type GetObjectsResponse struct { + // HTTP response content type for this operation ContentType string - StatusCode int + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing RawResponse *http.Response // Successfully fetched objects GetObjects200ApplicationJSONObject *GetObjects200ApplicationJSON } + +func (o *GetObjectsResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *GetObjectsResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *GetObjectsResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} + +func (o *GetObjectsResponse) GetGetObjects200ApplicationJSONObject() *GetObjects200ApplicationJSON { + if o == nil { + return nil + } + return o.GetObjects200ApplicationJSONObject +} diff --git a/pkg/models/operations/getschema.go b/pkg/models/operations/getschema.go index 7886a4d..198d313 100755 --- a/pkg/models/operations/getschema.go +++ b/pkg/models/operations/getschema.go @@ -13,15 +13,74 @@ type GetSchemaRequest struct { TableName string `queryParam:"style=form,explode=true,name=tableName"` } +func (o *GetSchemaRequest) GetConnectionID() int64 { + if o == nil { + return 0 + } + return o.ConnectionID +} + +func (o *GetSchemaRequest) GetNamespace() string { + if o == nil { + return "" + } + return o.Namespace +} + +func (o *GetSchemaRequest) GetTableName() string { + if o == nil { + return "" + } + return o.TableName +} + // GetSchema200ApplicationJSON - Successfully fetched schema type GetSchema200ApplicationJSON struct { Schema []shared.Field `json:"schema,omitempty"` } +func (o *GetSchema200ApplicationJSON) GetSchema() []shared.Field { + if o == nil { + return nil + } + return o.Schema +} + type GetSchemaResponse struct { + // HTTP response content type for this operation ContentType string - StatusCode int + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing RawResponse *http.Response // Successfully fetched schema GetSchema200ApplicationJSONObject *GetSchema200ApplicationJSON } + +func (o *GetSchemaResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *GetSchemaResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *GetSchemaResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} + +func (o *GetSchemaResponse) GetGetSchema200ApplicationJSONObject() *GetSchema200ApplicationJSON { + if o == nil { + return nil + } + return o.GetSchema200ApplicationJSONObject +} diff --git a/pkg/models/operations/getsources.go b/pkg/models/operations/getsources.go index a330a99..3ab3cc6 100755 --- a/pkg/models/operations/getsources.go +++ b/pkg/models/operations/getsources.go @@ -12,10 +12,48 @@ type GetSources200ApplicationJSON struct { Sources []shared.Source `json:"sources,omitempty"` } +func (o *GetSources200ApplicationJSON) GetSources() []shared.Source { + if o == nil { + return nil + } + return o.Sources +} + type GetSourcesResponse struct { + // HTTP response content type for this operation ContentType string - StatusCode int + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing RawResponse *http.Response // Successfully fetched sources GetSources200ApplicationJSONObject *GetSources200ApplicationJSON } + +func (o *GetSourcesResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *GetSourcesResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *GetSourcesResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} + +func (o *GetSourcesResponse) GetGetSources200ApplicationJSONObject() *GetSources200ApplicationJSON { + if o == nil { + return nil + } + return o.GetSources200ApplicationJSONObject +} diff --git a/pkg/models/operations/getsyncs.go b/pkg/models/operations/getsyncs.go index 9ad58c9..ad7f4da 100755 --- a/pkg/models/operations/getsyncs.go +++ b/pkg/models/operations/getsyncs.go @@ -12,10 +12,48 @@ type GetSyncs200ApplicationJSON struct { Syncs []shared.Sync `json:"syncs,omitempty"` } +func (o *GetSyncs200ApplicationJSON) GetSyncs() []shared.Sync { + if o == nil { + return nil + } + return o.Syncs +} + type GetSyncsResponse struct { + // HTTP response content type for this operation ContentType string - StatusCode int + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing RawResponse *http.Response // Successfully fetched syncs GetSyncs200ApplicationJSONObject *GetSyncs200ApplicationJSON } + +func (o *GetSyncsResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *GetSyncsResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *GetSyncsResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} + +func (o *GetSyncsResponse) GetGetSyncs200ApplicationJSONObject() *GetSyncs200ApplicationJSON { + if o == nil { + return nil + } + return o.GetSyncs200ApplicationJSONObject +} diff --git a/pkg/models/operations/gettables.go b/pkg/models/operations/gettables.go index 783d6e3..fa60afc 100755 --- a/pkg/models/operations/gettables.go +++ b/pkg/models/operations/gettables.go @@ -11,15 +11,67 @@ type GetTablesRequest struct { Namespace string `queryParam:"style=form,explode=true,name=namespace"` } +func (o *GetTablesRequest) GetConnectionID() int64 { + if o == nil { + return 0 + } + return o.ConnectionID +} + +func (o *GetTablesRequest) GetNamespace() string { + if o == nil { + return "" + } + return o.Namespace +} + // GetTables200ApplicationJSON - Successfully fetched tables type GetTables200ApplicationJSON struct { Tables []string `json:"tables,omitempty"` } +func (o *GetTables200ApplicationJSON) GetTables() []string { + if o == nil { + return nil + } + return o.Tables +} + type GetTablesResponse struct { + // HTTP response content type for this operation ContentType string - StatusCode int + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing RawResponse *http.Response // Successfully fetched tables GetTables200ApplicationJSONObject *GetTables200ApplicationJSON } + +func (o *GetTablesResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *GetTablesResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *GetTablesResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} + +func (o *GetTablesResponse) GetGetTables200ApplicationJSONObject() *GetTables200ApplicationJSON { + if o == nil { + return nil + } + return o.GetTables200ApplicationJSONObject +} diff --git a/pkg/models/operations/queryobject.go b/pkg/models/operations/queryobject.go new file mode 100755 index 0000000..f1857b9 --- /dev/null +++ b/pkg/models/operations/queryobject.go @@ -0,0 +1,132 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "github.com/fabra-io/go-sdk/pkg/models/shared" + "net/http" +) + +type QueryObjectRequestBody struct { + Filters []shared.QueryFilter `json:"filters,omitempty"` +} + +func (o *QueryObjectRequestBody) GetFilters() []shared.QueryFilter { + if o == nil { + return nil + } + return o.Filters +} + +type QueryObjectRequest struct { + EndCustomerID string `pathParam:"style=simple,explode=false,name=endCustomerID"` + ObjectID int64 `pathParam:"style=simple,explode=false,name=objectID"` + RequestBody *QueryObjectRequestBody `request:"mediaType=application/json"` +} + +func (o *QueryObjectRequest) GetEndCustomerID() string { + if o == nil { + return "" + } + return o.EndCustomerID +} + +func (o *QueryObjectRequest) GetObjectID() int64 { + if o == nil { + return 0 + } + return o.ObjectID +} + +func (o *QueryObjectRequest) GetRequestBody() *QueryObjectRequestBody { + if o == nil { + return nil + } + return o.RequestBody +} + +type QueryObject200ApplicationJSONExampleField3 struct { + NestedField1 *string `json:"nested_field_1,omitempty"` + NestedField2 *int64 `json:"nested_field_2,omitempty"` +} + +func (o *QueryObject200ApplicationJSONExampleField3) GetNestedField1() *string { + if o == nil { + return nil + } + return o.NestedField1 +} + +func (o *QueryObject200ApplicationJSONExampleField3) GetNestedField2() *int64 { + if o == nil { + return nil + } + return o.NestedField2 +} + +// QueryObject200ApplicationJSON - The response payload will match the schema you defined when creating the object +type QueryObject200ApplicationJSON struct { + ExampleField1 *int64 `json:"example_field_1,omitempty"` + ExampleField2 *string `json:"example_field_2,omitempty"` + ExampleField3 *QueryObject200ApplicationJSONExampleField3 `json:"example_field_3,omitempty"` +} + +func (o *QueryObject200ApplicationJSON) GetExampleField1() *int64 { + if o == nil { + return nil + } + return o.ExampleField1 +} + +func (o *QueryObject200ApplicationJSON) GetExampleField2() *string { + if o == nil { + return nil + } + return o.ExampleField2 +} + +func (o *QueryObject200ApplicationJSON) GetExampleField3() *QueryObject200ApplicationJSONExampleField3 { + if o == nil { + return nil + } + return o.ExampleField3 +} + +type QueryObjectResponse struct { + // HTTP response content type for this operation + ContentType string + // HTTP response status code for this operation + StatusCode int + // Raw HTTP response; suitable for custom response parsing + RawResponse *http.Response + // The response payload will match the schema you defined when creating the object + QueryObject200ApplicationJSONObject *QueryObject200ApplicationJSON +} + +func (o *QueryObjectResponse) GetContentType() string { + if o == nil { + return "" + } + return o.ContentType +} + +func (o *QueryObjectResponse) GetStatusCode() int { + if o == nil { + return 0 + } + return o.StatusCode +} + +func (o *QueryObjectResponse) GetRawResponse() *http.Response { + if o == nil { + return nil + } + return o.RawResponse +} + +func (o *QueryObjectResponse) GetQueryObject200ApplicationJSONObject() *QueryObject200ApplicationJSON { + if o == nil { + return nil + } + return o.QueryObject200ApplicationJSONObject +} diff --git a/pkg/models/sdkerrors/sdkerror.go b/pkg/models/sdkerrors/sdkerror.go new file mode 100755 index 0000000..5c1affd --- /dev/null +++ b/pkg/models/sdkerrors/sdkerror.go @@ -0,0 +1,35 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package sdkerrors + +import ( + "fmt" + "net/http" +) + +type SDKError struct { + Message string + StatusCode int + Body string + RawResponse *http.Response +} + +var _ error = &SDKError{} + +func NewSDKError(message string, statusCode int, body string, httpRes *http.Response) *SDKError { + return &SDKError{ + Message: message, + StatusCode: statusCode, + Body: body, + RawResponse: httpRes, + } +} + +func (e *SDKError) Error() string { + body := "" + if len(e.Body) > 0 { + body = fmt.Sprintf("\n%s", e.Body) + } + + return fmt.Sprintf("%s: Status %d%s", e.Message, e.StatusCode, body) +} diff --git a/pkg/models/shared/bigqueryconfig.go b/pkg/models/shared/bigqueryconfig.go index 15f9cbb..fefd243 100755 --- a/pkg/models/shared/bigqueryconfig.go +++ b/pkg/models/shared/bigqueryconfig.go @@ -6,3 +6,17 @@ type BigQueryConfig struct { Credentials *string `json:"credentials,omitempty"` Location string `json:"location"` } + +func (o *BigQueryConfig) GetCredentials() *string { + if o == nil { + return nil + } + return o.Credentials +} + +func (o *BigQueryConfig) GetLocation() string { + if o == nil { + return "" + } + return o.Location +} diff --git a/pkg/models/shared/connection.go b/pkg/models/shared/connection.go index 48b38b8..713e039 100755 --- a/pkg/models/shared/connection.go +++ b/pkg/models/shared/connection.go @@ -3,6 +3,20 @@ package shared type Connection struct { - ConnectionType *ConnectionTypeEnum `json:"connection_type,omitempty"` - ID *int64 `json:"id,omitempty"` + ConnectionType *ConnectionType `json:"connection_type,omitempty"` + ID *int64 `json:"id,omitempty"` +} + +func (o *Connection) GetConnectionType() *ConnectionType { + if o == nil { + return nil + } + return o.ConnectionType +} + +func (o *Connection) GetID() *int64 { + if o == nil { + return nil + } + return o.ID } diff --git a/pkg/models/shared/connectiontype.go b/pkg/models/shared/connectiontype.go new file mode 100755 index 0000000..884cd4a --- /dev/null +++ b/pkg/models/shared/connectiontype.go @@ -0,0 +1,44 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "encoding/json" + "fmt" +) + +type ConnectionType string + +const ( + ConnectionTypeSnowflake ConnectionType = "snowflake" + ConnectionTypeBigquery ConnectionType = "bigquery" + ConnectionTypeRedshift ConnectionType = "redshift" + ConnectionTypeMongodb ConnectionType = "mongodb" + ConnectionTypeWebhook ConnectionType = "webhook" +) + +func (e ConnectionType) ToPointer() *ConnectionType { + return &e +} + +func (e *ConnectionType) UnmarshalJSON(data []byte) error { + var v string + if err := json.Unmarshal(data, &v); err != nil { + return err + } + switch v { + case "snowflake": + fallthrough + case "bigquery": + fallthrough + case "redshift": + fallthrough + case "mongodb": + fallthrough + case "webhook": + *e = ConnectionType(v) + return nil + default: + return fmt.Errorf("invalid value for ConnectionType: %v", v) + } +} diff --git a/pkg/models/shared/connectiontypeenum.go b/pkg/models/shared/connectiontypeenum.go deleted file mode 100755 index 09f0726..0000000 --- a/pkg/models/shared/connectiontypeenum.go +++ /dev/null @@ -1,44 +0,0 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. - -package shared - -import ( - "encoding/json" - "fmt" -) - -type ConnectionTypeEnum string - -const ( - ConnectionTypeEnumSnowflake ConnectionTypeEnum = "snowflake" - ConnectionTypeEnumBigquery ConnectionTypeEnum = "bigquery" - ConnectionTypeEnumRedshift ConnectionTypeEnum = "redshift" - ConnectionTypeEnumMongodb ConnectionTypeEnum = "mongodb" - ConnectionTypeEnumWebhook ConnectionTypeEnum = "webhook" -) - -func (e ConnectionTypeEnum) ToPointer() *ConnectionTypeEnum { - return &e -} - -func (e *ConnectionTypeEnum) UnmarshalJSON(data []byte) error { - var v string - if err := json.Unmarshal(data, &v); err != nil { - return err - } - switch v { - case "snowflake": - fallthrough - case "bigquery": - fallthrough - case "redshift": - fallthrough - case "mongodb": - fallthrough - case "webhook": - *e = ConnectionTypeEnum(v) - return nil - default: - return fmt.Errorf("invalid value for ConnectionTypeEnum: %v", v) - } -} diff --git a/pkg/models/shared/createlinktokenrequest.go b/pkg/models/shared/createlinktokenrequest.go index 71f08dd..c092f78 100755 --- a/pkg/models/shared/createlinktokenrequest.go +++ b/pkg/models/shared/createlinktokenrequest.go @@ -5,3 +5,10 @@ package shared type CreateLinkTokenRequest struct { EndCustomerID string `json:"end_customer_id"` } + +func (o *CreateLinkTokenRequest) GetEndCustomerID() string { + if o == nil { + return "" + } + return o.EndCustomerID +} diff --git a/pkg/models/shared/createlinktokenresponse.go b/pkg/models/shared/createlinktokenresponse.go index a74a9cd..79db588 100755 --- a/pkg/models/shared/createlinktokenresponse.go +++ b/pkg/models/shared/createlinktokenresponse.go @@ -2,7 +2,13 @@ package shared -// CreateLinkTokenResponse - Successfully created link token type CreateLinkTokenResponse struct { LinkToken *string `json:"link_token,omitempty"` } + +func (o *CreateLinkTokenResponse) GetLinkToken() *string { + if o == nil { + return nil + } + return o.LinkToken +} diff --git a/pkg/models/shared/destination.go b/pkg/models/shared/destination.go index c08ed0c..a0a4a0d 100755 --- a/pkg/models/shared/destination.go +++ b/pkg/models/shared/destination.go @@ -7,3 +7,24 @@ type Destination struct { DisplayName *string `json:"display_name,omitempty"` ID *int64 `json:"id,omitempty"` } + +func (o *Destination) GetConnection() *Connection { + if o == nil { + return nil + } + return o.Connection +} + +func (o *Destination) GetDisplayName() *string { + if o == nil { + return nil + } + return o.DisplayName +} + +func (o *Destination) GetID() *int64 { + if o == nil { + return nil + } + return o.ID +} diff --git a/pkg/models/shared/destinationinput.go b/pkg/models/shared/destinationinput.go index 95cc04d..6fa0db0 100755 --- a/pkg/models/shared/destinationinput.go +++ b/pkg/models/shared/destinationinput.go @@ -3,10 +3,52 @@ package shared type DestinationInput struct { - BigqueryConfig *BigQueryConfig `json:"bigquery_config,omitempty"` - ConnectionType ConnectionTypeEnum `json:"connection_type"` - DisplayName string `json:"display_name"` - MongodbConfig *MongoDbConfig `json:"mongodb_config,omitempty"` - RedshiftConfig *RedshiftConfig `json:"redshift_config,omitempty"` - SnowflakeConfig *SnowflakeConfig `json:"snowflake_config,omitempty"` + BigqueryConfig *BigQueryConfig `json:"bigquery_config,omitempty"` + ConnectionType ConnectionType `json:"connection_type"` + DisplayName string `json:"display_name"` + MongodbConfig *MongoDbConfig `json:"mongodb_config,omitempty"` + RedshiftConfig *RedshiftConfig `json:"redshift_config,omitempty"` + SnowflakeConfig *SnowflakeConfig `json:"snowflake_config,omitempty"` +} + +func (o *DestinationInput) GetBigqueryConfig() *BigQueryConfig { + if o == nil { + return nil + } + return o.BigqueryConfig +} + +func (o *DestinationInput) GetConnectionType() ConnectionType { + if o == nil { + return ConnectionType("") + } + return o.ConnectionType +} + +func (o *DestinationInput) GetDisplayName() string { + if o == nil { + return "" + } + return o.DisplayName +} + +func (o *DestinationInput) GetMongodbConfig() *MongoDbConfig { + if o == nil { + return nil + } + return o.MongodbConfig +} + +func (o *DestinationInput) GetRedshiftConfig() *RedshiftConfig { + if o == nil { + return nil + } + return o.RedshiftConfig +} + +func (o *DestinationInput) GetSnowflakeConfig() *SnowflakeConfig { + if o == nil { + return nil + } + return o.SnowflakeConfig } diff --git a/pkg/models/shared/field.go b/pkg/models/shared/field.go index f8a3d4d..61a6f7a 100755 --- a/pkg/models/shared/field.go +++ b/pkg/models/shared/field.go @@ -3,6 +3,20 @@ package shared type Field struct { - Name *string `json:"name,omitempty"` - Type *FieldTypeEnum `json:"type,omitempty"` + Name *string `json:"name,omitempty"` + Type *FieldType `json:"type,omitempty"` +} + +func (o *Field) GetName() *string { + if o == nil { + return nil + } + return o.Name +} + +func (o *Field) GetType() *FieldType { + if o == nil { + return nil + } + return o.Type } diff --git a/pkg/models/shared/fieldmapping.go b/pkg/models/shared/fieldmapping.go index 9733d37..2d8f8d7 100755 --- a/pkg/models/shared/fieldmapping.go +++ b/pkg/models/shared/fieldmapping.go @@ -6,3 +6,17 @@ type FieldMapping struct { DestinationFieldName *string `json:"destination_field_name,omitempty"` SourceFieldName *string `json:"source_field_name,omitempty"` } + +func (o *FieldMapping) GetDestinationFieldName() *string { + if o == nil { + return nil + } + return o.DestinationFieldName +} + +func (o *FieldMapping) GetSourceFieldName() *string { + if o == nil { + return nil + } + return o.SourceFieldName +} diff --git a/pkg/models/shared/fieldtype.go b/pkg/models/shared/fieldtype.go new file mode 100755 index 0000000..90fe4b3 --- /dev/null +++ b/pkg/models/shared/fieldtype.go @@ -0,0 +1,44 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "encoding/json" + "fmt" +) + +type FieldType string + +const ( + FieldTypeString FieldType = "string" + FieldTypeInteger FieldType = "integer" + FieldTypeTimestamp FieldType = "timestamp" + FieldTypeJSON FieldType = "json" + FieldTypeBoolean FieldType = "boolean" +) + +func (e FieldType) ToPointer() *FieldType { + return &e +} + +func (e *FieldType) UnmarshalJSON(data []byte) error { + var v string + if err := json.Unmarshal(data, &v); err != nil { + return err + } + switch v { + case "string": + fallthrough + case "integer": + fallthrough + case "timestamp": + fallthrough + case "json": + fallthrough + case "boolean": + *e = FieldType(v) + return nil + default: + return fmt.Errorf("invalid value for FieldType: %v", v) + } +} diff --git a/pkg/models/shared/fieldtypeenum.go b/pkg/models/shared/fieldtypeenum.go deleted file mode 100755 index 807e60c..0000000 --- a/pkg/models/shared/fieldtypeenum.go +++ /dev/null @@ -1,44 +0,0 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. - -package shared - -import ( - "encoding/json" - "fmt" -) - -type FieldTypeEnum string - -const ( - FieldTypeEnumString FieldTypeEnum = "string" - FieldTypeEnumInteger FieldTypeEnum = "integer" - FieldTypeEnumTimestamp FieldTypeEnum = "timestamp" - FieldTypeEnumJSON FieldTypeEnum = "json" - FieldTypeEnumBoolean FieldTypeEnum = "boolean" -) - -func (e FieldTypeEnum) ToPointer() *FieldTypeEnum { - return &e -} - -func (e *FieldTypeEnum) UnmarshalJSON(data []byte) error { - var v string - if err := json.Unmarshal(data, &v); err != nil { - return err - } - switch v { - case "string": - fallthrough - case "integer": - fallthrough - case "timestamp": - fallthrough - case "json": - fallthrough - case "boolean": - *e = FieldTypeEnum(v) - return nil - default: - return fmt.Errorf("invalid value for FieldTypeEnum: %v", v) - } -} diff --git a/pkg/models/shared/frequencyunits.go b/pkg/models/shared/frequencyunits.go new file mode 100755 index 0000000..3c033de --- /dev/null +++ b/pkg/models/shared/frequencyunits.go @@ -0,0 +1,41 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "encoding/json" + "fmt" +) + +type FrequencyUnits string + +const ( + FrequencyUnitsMinutes FrequencyUnits = "minutes" + FrequencyUnitsHours FrequencyUnits = "hours" + FrequencyUnitsDays FrequencyUnits = "days" + FrequencyUnitsWeeks FrequencyUnits = "weeks" +) + +func (e FrequencyUnits) ToPointer() *FrequencyUnits { + return &e +} + +func (e *FrequencyUnits) UnmarshalJSON(data []byte) error { + var v string + if err := json.Unmarshal(data, &v); err != nil { + return err + } + switch v { + case "minutes": + fallthrough + case "hours": + fallthrough + case "days": + fallthrough + case "weeks": + *e = FrequencyUnits(v) + return nil + default: + return fmt.Errorf("invalid value for FrequencyUnits: %v", v) + } +} diff --git a/pkg/models/shared/frequencyunitsenum.go b/pkg/models/shared/frequencyunitsenum.go deleted file mode 100755 index 380e281..0000000 --- a/pkg/models/shared/frequencyunitsenum.go +++ /dev/null @@ -1,41 +0,0 @@ -// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. - -package shared - -import ( - "encoding/json" - "fmt" -) - -type FrequencyUnitsEnum string - -const ( - FrequencyUnitsEnumMinutes FrequencyUnitsEnum = "minutes" - FrequencyUnitsEnumHours FrequencyUnitsEnum = "hours" - FrequencyUnitsEnumDays FrequencyUnitsEnum = "days" - FrequencyUnitsEnumWeeks FrequencyUnitsEnum = "weeks" -) - -func (e FrequencyUnitsEnum) ToPointer() *FrequencyUnitsEnum { - return &e -} - -func (e *FrequencyUnitsEnum) UnmarshalJSON(data []byte) error { - var v string - if err := json.Unmarshal(data, &v); err != nil { - return err - } - switch v { - case "minutes": - fallthrough - case "hours": - fallthrough - case "days": - fallthrough - case "weeks": - *e = FrequencyUnitsEnum(v) - return nil - default: - return fmt.Errorf("invalid value for FrequencyUnitsEnum: %v", v) - } -} diff --git a/pkg/models/shared/mongodbconfig.go b/pkg/models/shared/mongodbconfig.go index 1b07187..19e062a 100755 --- a/pkg/models/shared/mongodbconfig.go +++ b/pkg/models/shared/mongodbconfig.go @@ -8,3 +8,31 @@ type MongoDbConfig struct { Password string `json:"password"` Username string `json:"username"` } + +func (o *MongoDbConfig) GetConnectionOptions() *string { + if o == nil { + return nil + } + return o.ConnectionOptions +} + +func (o *MongoDbConfig) GetHost() string { + if o == nil { + return "" + } + return o.Host +} + +func (o *MongoDbConfig) GetPassword() string { + if o == nil { + return "" + } + return o.Password +} + +func (o *MongoDbConfig) GetUsername() string { + if o == nil { + return "" + } + return o.Username +} diff --git a/pkg/models/shared/namespaces.go b/pkg/models/shared/namespaces.go index dda775a..9482346 100755 --- a/pkg/models/shared/namespaces.go +++ b/pkg/models/shared/namespaces.go @@ -2,7 +2,13 @@ package shared -// Namespaces - Successfully fetched namespaces type Namespaces struct { Namespaces []string `json:"namespaces,omitempty"` } + +func (o *Namespaces) GetNamespaces() []string { + if o == nil { + return nil + } + return o.Namespaces +} diff --git a/pkg/models/shared/object.go b/pkg/models/shared/object.go index b8453d4..23636bb 100755 --- a/pkg/models/shared/object.go +++ b/pkg/models/shared/object.go @@ -12,3 +12,52 @@ type Object struct { ObjectFields []ObjectField `json:"object_fields,omitempty"` TableName *string `json:"table_name,omitempty"` } + +func (o *Object) GetDestinationID() *int64 { + if o == nil { + return nil + } + return o.DestinationID +} + +func (o *Object) GetDisplayName() *string { + if o == nil { + return nil + } + return o.DisplayName +} + +func (o *Object) GetEndCustomerIDField() *string { + if o == nil { + return nil + } + return o.EndCustomerIDField +} + +func (o *Object) GetID() *int64 { + if o == nil { + return nil + } + return o.ID +} + +func (o *Object) GetNamespace() *string { + if o == nil { + return nil + } + return o.Namespace +} + +func (o *Object) GetObjectFields() []ObjectField { + if o == nil { + return nil + } + return o.ObjectFields +} + +func (o *Object) GetTableName() *string { + if o == nil { + return nil + } + return o.TableName +} diff --git a/pkg/models/shared/objectfield.go b/pkg/models/shared/objectfield.go index a561f59..0f5c9ce 100755 --- a/pkg/models/shared/objectfield.go +++ b/pkg/models/shared/objectfield.go @@ -3,6 +3,20 @@ package shared type ObjectField struct { - Name *string `json:"name,omitempty"` - Type *FieldTypeEnum `json:"type,omitempty"` + Name *string `json:"name,omitempty"` + Type *FieldType `json:"type,omitempty"` +} + +func (o *ObjectField) GetName() *string { + if o == nil { + return nil + } + return o.Name +} + +func (o *ObjectField) GetType() *FieldType { + if o == nil { + return nil + } + return o.Type } diff --git a/pkg/models/shared/objectinput.go b/pkg/models/shared/objectinput.go index 5479869..e92e744 100755 --- a/pkg/models/shared/objectinput.go +++ b/pkg/models/shared/objectinput.go @@ -3,11 +3,85 @@ package shared type ObjectInput struct { - DestinationID int64 `json:"destination_id"` - DisplayName string `json:"display_name"` + CursorField *string `json:"cursor_field,omitempty"` + DestinationID int64 `json:"destination_id"` + DisplayName string `json:"display_name"` // This is where Fabra will insert the End Customer ID specified when creating a source. - EndCustomerIDField string `json:"end_customer_id_field"` - Namespace string `json:"namespace"` - ObjectFields []ObjectField `json:"object_fields,omitempty"` - TableName string `json:"table_name"` + EndCustomerIDField string `json:"end_customer_id_field"` + Frequency int64 `json:"frequency"` + FrequencyUnits FrequencyUnits `json:"frequency_units"` + Namespace string `json:"namespace"` + ObjectFields []ObjectField `json:"object_fields,omitempty"` + PrimaryKey *string `json:"primary_key,omitempty"` + TableName string `json:"table_name"` +} + +func (o *ObjectInput) GetCursorField() *string { + if o == nil { + return nil + } + return o.CursorField +} + +func (o *ObjectInput) GetDestinationID() int64 { + if o == nil { + return 0 + } + return o.DestinationID +} + +func (o *ObjectInput) GetDisplayName() string { + if o == nil { + return "" + } + return o.DisplayName +} + +func (o *ObjectInput) GetEndCustomerIDField() string { + if o == nil { + return "" + } + return o.EndCustomerIDField +} + +func (o *ObjectInput) GetFrequency() int64 { + if o == nil { + return 0 + } + return o.Frequency +} + +func (o *ObjectInput) GetFrequencyUnits() FrequencyUnits { + if o == nil { + return FrequencyUnits("") + } + return o.FrequencyUnits +} + +func (o *ObjectInput) GetNamespace() string { + if o == nil { + return "" + } + return o.Namespace +} + +func (o *ObjectInput) GetObjectFields() []ObjectField { + if o == nil { + return nil + } + return o.ObjectFields +} + +func (o *ObjectInput) GetPrimaryKey() *string { + if o == nil { + return nil + } + return o.PrimaryKey +} + +func (o *ObjectInput) GetTableName() string { + if o == nil { + return "" + } + return o.TableName } diff --git a/pkg/models/shared/queryfilter.go b/pkg/models/shared/queryfilter.go new file mode 100755 index 0000000..7e309a4 --- /dev/null +++ b/pkg/models/shared/queryfilter.go @@ -0,0 +1,22 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +type QueryFilter struct { + FieldName string `json:"field_name"` + FieldValue string `json:"field_value"` +} + +func (o *QueryFilter) GetFieldName() string { + if o == nil { + return "" + } + return o.FieldName +} + +func (o *QueryFilter) GetFieldValue() string { + if o == nil { + return "" + } + return o.FieldValue +} diff --git a/pkg/models/shared/redshiftconfig.go b/pkg/models/shared/redshiftconfig.go index 459d71a..785c90f 100755 --- a/pkg/models/shared/redshiftconfig.go +++ b/pkg/models/shared/redshiftconfig.go @@ -9,3 +9,38 @@ type RedshiftConfig struct { Port string `json:"port"` Username string `json:"username"` } + +func (o *RedshiftConfig) GetDatabaseName() string { + if o == nil { + return "" + } + return o.DatabaseName +} + +func (o *RedshiftConfig) GetHost() string { + if o == nil { + return "" + } + return o.Host +} + +func (o *RedshiftConfig) GetPassword() string { + if o == nil { + return "" + } + return o.Password +} + +func (o *RedshiftConfig) GetPort() string { + if o == nil { + return "" + } + return o.Port +} + +func (o *RedshiftConfig) GetUsername() string { + if o == nil { + return "" + } + return o.Username +} diff --git a/pkg/models/shared/security.go b/pkg/models/shared/security.go index 6cf0529..0a51ca6 100755 --- a/pkg/models/shared/security.go +++ b/pkg/models/shared/security.go @@ -3,5 +3,12 @@ package shared type Security struct { - APIKeyAuth string `security:"scheme,type=apiKey,subtype=header,name=X-API-Key"` + APIKeyAuth string `security:"scheme,type=apiKey,subtype=header,name=X-API-KEY"` +} + +func (o *Security) GetAPIKeyAuth() string { + if o == nil { + return "" + } + return o.APIKeyAuth } diff --git a/pkg/models/shared/snowflakeconfig.go b/pkg/models/shared/snowflakeconfig.go index bddc6d4..e5505f6 100755 --- a/pkg/models/shared/snowflakeconfig.go +++ b/pkg/models/shared/snowflakeconfig.go @@ -10,3 +10,45 @@ type SnowflakeConfig struct { Username string `json:"username"` WarehouseName string `json:"warehouse_name"` } + +func (o *SnowflakeConfig) GetDatabaseName() string { + if o == nil { + return "" + } + return o.DatabaseName +} + +func (o *SnowflakeConfig) GetHost() string { + if o == nil { + return "" + } + return o.Host +} + +func (o *SnowflakeConfig) GetPassword() string { + if o == nil { + return "" + } + return o.Password +} + +func (o *SnowflakeConfig) GetRole() string { + if o == nil { + return "" + } + return o.Role +} + +func (o *SnowflakeConfig) GetUsername() string { + if o == nil { + return "" + } + return o.Username +} + +func (o *SnowflakeConfig) GetWarehouseName() string { + if o == nil { + return "" + } + return o.WarehouseName +} diff --git a/pkg/models/shared/source.go b/pkg/models/shared/source.go index b175dc3..eefe029 100755 --- a/pkg/models/shared/source.go +++ b/pkg/models/shared/source.go @@ -5,6 +5,34 @@ package shared type Source struct { Connection *Connection `json:"connection,omitempty"` DisplayName *string `json:"display_name,omitempty"` - EndCustomerID *int64 `json:"end_customer_id,omitempty"` + EndCustomerID *string `json:"end_customer_id,omitempty"` ID *int64 `json:"id,omitempty"` } + +func (o *Source) GetConnection() *Connection { + if o == nil { + return nil + } + return o.Connection +} + +func (o *Source) GetDisplayName() *string { + if o == nil { + return nil + } + return o.DisplayName +} + +func (o *Source) GetEndCustomerID() *string { + if o == nil { + return nil + } + return o.EndCustomerID +} + +func (o *Source) GetID() *int64 { + if o == nil { + return nil + } + return o.ID +} diff --git a/pkg/models/shared/sourceinput.go b/pkg/models/shared/sourceinput.go index bc12f22..7c5d9aa 100755 --- a/pkg/models/shared/sourceinput.go +++ b/pkg/models/shared/sourceinput.go @@ -3,11 +3,60 @@ package shared type SourceInput struct { - BigqueryConfig *BigQueryConfig `json:"bigquery_config,omitempty"` - ConnectionType ConnectionTypeEnum `json:"connection_type"` - DisplayName string `json:"display_name"` - EndCustomerID int64 `json:"end_customer_id"` - MongodbConfig *MongoDbConfig `json:"mongodb_config,omitempty"` - RedshiftConfig *RedshiftConfig `json:"redshift_config,omitempty"` - SnowflakeConfig *SnowflakeConfig `json:"snowflake_config,omitempty"` + BigqueryConfig *BigQueryConfig `json:"bigquery_config,omitempty"` + ConnectionType ConnectionType `json:"connection_type"` + DisplayName string `json:"display_name"` + EndCustomerID string `json:"end_customer_id"` + MongodbConfig *MongoDbConfig `json:"mongodb_config,omitempty"` + RedshiftConfig *RedshiftConfig `json:"redshift_config,omitempty"` + SnowflakeConfig *SnowflakeConfig `json:"snowflake_config,omitempty"` +} + +func (o *SourceInput) GetBigqueryConfig() *BigQueryConfig { + if o == nil { + return nil + } + return o.BigqueryConfig +} + +func (o *SourceInput) GetConnectionType() ConnectionType { + if o == nil { + return ConnectionType("") + } + return o.ConnectionType +} + +func (o *SourceInput) GetDisplayName() string { + if o == nil { + return "" + } + return o.DisplayName +} + +func (o *SourceInput) GetEndCustomerID() string { + if o == nil { + return "" + } + return o.EndCustomerID +} + +func (o *SourceInput) GetMongodbConfig() *MongoDbConfig { + if o == nil { + return nil + } + return o.MongodbConfig +} + +func (o *SourceInput) GetRedshiftConfig() *RedshiftConfig { + if o == nil { + return nil + } + return o.RedshiftConfig +} + +func (o *SourceInput) GetSnowflakeConfig() *SnowflakeConfig { + if o == nil { + return nil + } + return o.SnowflakeConfig } diff --git a/pkg/models/shared/sync.go b/pkg/models/shared/sync.go index 2266dd4..d86b8cf 100755 --- a/pkg/models/shared/sync.go +++ b/pkg/models/shared/sync.go @@ -3,17 +3,116 @@ package shared type Sync struct { - CursorField *string `json:"cursor_field,omitempty"` - CustomJoin *string `json:"custom_join,omitempty"` - DestinationID *int64 `json:"destination_id,omitempty"` - DisplayName *string `json:"display_name,omitempty"` - FieldMappings []FieldMapping `json:"field_mappings,omitempty"` - Frequency *int64 `json:"frequency,omitempty"` - FrequencyUnits *FrequencyUnitsEnum `json:"frequency_units,omitempty"` - ID *int64 `json:"id,omitempty"` - Namespace *string `json:"namespace,omitempty"` - ObjectID *int64 `json:"object_id,omitempty"` - PrimaryKey *string `json:"primary_key,omitempty"` - SourceID *int64 `json:"source_id,omitempty"` - TableName *string `json:"table_name,omitempty"` + CursorField *string `json:"cursor_field,omitempty"` + CustomJoin *string `json:"custom_join,omitempty"` + DestinationID *int64 `json:"destination_id,omitempty"` + DisplayName *string `json:"display_name,omitempty"` + EndCustomerID *string `json:"end_customer_id,omitempty"` + FieldMappings []FieldMapping `json:"field_mappings,omitempty"` + Frequency *int64 `json:"frequency,omitempty"` + FrequencyUnits *FrequencyUnits `json:"frequency_units,omitempty"` + ID *int64 `json:"id,omitempty"` + Namespace *string `json:"namespace,omitempty"` + ObjectID *int64 `json:"object_id,omitempty"` + PrimaryKey *string `json:"primary_key,omitempty"` + SourceID *int64 `json:"source_id,omitempty"` + TableName *string `json:"table_name,omitempty"` +} + +func (o *Sync) GetCursorField() *string { + if o == nil { + return nil + } + return o.CursorField +} + +func (o *Sync) GetCustomJoin() *string { + if o == nil { + return nil + } + return o.CustomJoin +} + +func (o *Sync) GetDestinationID() *int64 { + if o == nil { + return nil + } + return o.DestinationID +} + +func (o *Sync) GetDisplayName() *string { + if o == nil { + return nil + } + return o.DisplayName +} + +func (o *Sync) GetEndCustomerID() *string { + if o == nil { + return nil + } + return o.EndCustomerID +} + +func (o *Sync) GetFieldMappings() []FieldMapping { + if o == nil { + return nil + } + return o.FieldMappings +} + +func (o *Sync) GetFrequency() *int64 { + if o == nil { + return nil + } + return o.Frequency +} + +func (o *Sync) GetFrequencyUnits() *FrequencyUnits { + if o == nil { + return nil + } + return o.FrequencyUnits +} + +func (o *Sync) GetID() *int64 { + if o == nil { + return nil + } + return o.ID +} + +func (o *Sync) GetNamespace() *string { + if o == nil { + return nil + } + return o.Namespace +} + +func (o *Sync) GetObjectID() *int64 { + if o == nil { + return nil + } + return o.ObjectID +} + +func (o *Sync) GetPrimaryKey() *string { + if o == nil { + return nil + } + return o.PrimaryKey +} + +func (o *Sync) GetSourceID() *int64 { + if o == nil { + return nil + } + return o.SourceID +} + +func (o *Sync) GetTableName() *string { + if o == nil { + return nil + } + return o.TableName } diff --git a/pkg/models/shared/syncinput.go b/pkg/models/shared/syncinput.go index 85a1c6f..e9b419c 100755 --- a/pkg/models/shared/syncinput.go +++ b/pkg/models/shared/syncinput.go @@ -3,16 +3,108 @@ package shared type SyncInput struct { - CursorField *string `json:"cursor_field,omitempty"` - CustomJoin *string `json:"custom_join,omitempty"` - DestinationID int64 `json:"destination_id"` - DisplayName string `json:"display_name"` - FieldMappings []FieldMapping `json:"field_mappings"` - Frequency int64 `json:"frequency"` - FrequencyUnits FrequencyUnitsEnum `json:"frequency_units"` - Namespace *string `json:"namespace,omitempty"` - ObjectID int64 `json:"object_id"` - PrimaryKey *string `json:"primary_key,omitempty"` - SourceID int64 `json:"source_id"` - TableName *string `json:"table_name,omitempty"` + CursorField *string `json:"cursor_field,omitempty"` + CustomJoin *string `json:"custom_join,omitempty"` + DestinationID int64 `json:"destination_id"` + DisplayName string `json:"display_name"` + EndCustomerID string `json:"end_customer_id"` + FieldMappings []FieldMapping `json:"field_mappings"` + Frequency *int64 `json:"frequency,omitempty"` + FrequencyUnits *FrequencyUnits `json:"frequency_units,omitempty"` + Namespace *string `json:"namespace,omitempty"` + ObjectID int64 `json:"object_id"` + PrimaryKey *string `json:"primary_key,omitempty"` + SourceID int64 `json:"source_id"` + TableName *string `json:"table_name,omitempty"` +} + +func (o *SyncInput) GetCursorField() *string { + if o == nil { + return nil + } + return o.CursorField +} + +func (o *SyncInput) GetCustomJoin() *string { + if o == nil { + return nil + } + return o.CustomJoin +} + +func (o *SyncInput) GetDestinationID() int64 { + if o == nil { + return 0 + } + return o.DestinationID +} + +func (o *SyncInput) GetDisplayName() string { + if o == nil { + return "" + } + return o.DisplayName +} + +func (o *SyncInput) GetEndCustomerID() string { + if o == nil { + return "" + } + return o.EndCustomerID +} + +func (o *SyncInput) GetFieldMappings() []FieldMapping { + if o == nil { + return []FieldMapping{} + } + return o.FieldMappings +} + +func (o *SyncInput) GetFrequency() *int64 { + if o == nil { + return nil + } + return o.Frequency +} + +func (o *SyncInput) GetFrequencyUnits() *FrequencyUnits { + if o == nil { + return nil + } + return o.FrequencyUnits +} + +func (o *SyncInput) GetNamespace() *string { + if o == nil { + return nil + } + return o.Namespace +} + +func (o *SyncInput) GetObjectID() int64 { + if o == nil { + return 0 + } + return o.ObjectID +} + +func (o *SyncInput) GetPrimaryKey() *string { + if o == nil { + return nil + } + return o.PrimaryKey +} + +func (o *SyncInput) GetSourceID() int64 { + if o == nil { + return 0 + } + return o.SourceID +} + +func (o *SyncInput) GetTableName() *string { + if o == nil { + return nil + } + return o.TableName } diff --git a/pkg/types/bigint.go b/pkg/types/bigint.go new file mode 100755 index 0000000..afd0cd2 --- /dev/null +++ b/pkg/types/bigint.go @@ -0,0 +1,21 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import ( + "fmt" + "math/big" +) + +// MustNewBigIntFromString returns an instance of big.Int from a string +// The string is assumed to be base 10 and if it is not a valid big.Int +// then the function panics. +// Avoid using this function in production code. +func MustNewBigIntFromString(s string) *big.Int { + i, ok := new(big.Int).SetString(s, 10) + if !ok { + panic(fmt.Errorf("failed to parse string as big.Int")) + } + + return i +} diff --git a/pkg/types/date.go b/pkg/types/date.go index 01c69b7..c4648fa 100755 --- a/pkg/types/date.go +++ b/pkg/types/date.go @@ -67,6 +67,10 @@ func MustDateFromString(str string) Date { return d } +func (d Date) GetTime() time.Time { + return d.Time +} + func (d Date) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf(`"%s"`, d.Time.Format("2006-01-02"))), nil } diff --git a/pkg/types/decimal.go b/pkg/types/decimal.go new file mode 100755 index 0000000..a42284b --- /dev/null +++ b/pkg/types/decimal.go @@ -0,0 +1,20 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import ( + "fmt" + + "github.com/ericlagergren/decimal" +) + +// MustNewDecimalFromString returns an instance of Decimal from a string +// Avoid using this function in production code. +func MustNewDecimalFromString(s string) *decimal.Big { + d, ok := new(decimal.Big).SetString(s) + if !ok { + panic(fmt.Errorf("failed to parse string as decimal.Big")) + } + + return d +} diff --git a/pkg/types/pointers.go b/pkg/types/pointers.go new file mode 100755 index 0000000..4f15e99 --- /dev/null +++ b/pkg/types/pointers.go @@ -0,0 +1,10 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +func String(s string) *string { return &s } +func Bool(b bool) *bool { return &b } +func Int(i int) *int { return &i } +func Int64(i int64) *int64 { return &i } +func Float32(f float32) *float32 { return &f } +func Float64(f float64) *float64 { return &f } diff --git a/pkg/utils/form.go b/pkg/utils/form.go index 2f82c1d..27885cb 100755 --- a/pkg/utils/form.go +++ b/pkg/utils/form.go @@ -4,22 +4,26 @@ package utils import ( "fmt" + "math/big" "net/url" "reflect" "strings" "time" + "github.com/ericlagergren/decimal" + "github.com/fabra-io/go-sdk/pkg/types" ) -func populateForm(paramName string, explode bool, objType reflect.Type, objValue reflect.Value, arrayDelimiter string, getFieldName func(reflect.StructField) string) url.Values { +func populateForm(paramName string, explode bool, objType reflect.Type, objValue reflect.Value, delimiter string, getFieldName func(reflect.StructField) string) url.Values { formValues := url.Values{} + if isNil(objType, objValue) { + return formValues + } + if objType.Kind() == reflect.Pointer { - if objValue.IsNil() { - return formValues - } objType = objType.Elem() objValue = objValue.Elem() } @@ -31,6 +35,10 @@ func populateForm(paramName string, explode bool, objType reflect.Type, objValue formValues.Add(paramName, valToString(objValue.Interface())) case types.Date: formValues.Add(paramName, valToString(objValue.Interface())) + case big.Int: + formValues.Add(paramName, valToString(objValue.Interface())) + case decimal.Big: + formValues.Add(paramName, valToString(objValue.Interface())) default: var items []string @@ -38,11 +46,11 @@ func populateForm(paramName string, explode bool, objType reflect.Type, objValue fieldType := objType.Field(i) valType := objValue.Field(i) - if valType.Kind() == reflect.Pointer { - if valType.IsNil() { - continue - } + if isNil(fieldType.Type, valType) { + continue + } + if valType.Kind() == reflect.Pointer { valType = valType.Elem() } @@ -54,12 +62,12 @@ func populateForm(paramName string, explode bool, objType reflect.Type, objValue if explode { formValues.Add(fieldName, valToString(valType.Interface())) } else { - items = append(items, fmt.Sprintf("%s,%s", fieldName, valToString(valType.Interface()))) + items = append(items, fmt.Sprintf("%s%s%s", fieldName, delimiter, valToString(valType.Interface()))) } } if len(items) > 0 { - formValues.Add(paramName, strings.Join(items, ",")) + formValues.Add(paramName, strings.Join(items, delimiter)) } } case reflect.Map: @@ -70,15 +78,15 @@ func populateForm(paramName string, explode bool, objType reflect.Type, objValue if explode { formValues.Add(iter.Key().String(), valToString(iter.Value().Interface())) } else { - items = append(items, fmt.Sprintf("%s,%s", iter.Key().String(), valToString(iter.Value().Interface()))) + items = append(items, fmt.Sprintf("%s%s%s", iter.Key().String(), delimiter, valToString(iter.Value().Interface()))) } } if len(items) > 0 { - formValues.Add(paramName, strings.Join(items, ",")) + formValues.Add(paramName, strings.Join(items, delimiter)) } case reflect.Slice, reflect.Array: - values := parseDelimitedArray(explode, objValue, arrayDelimiter) + values := parseDelimitedArray(explode, objValue, delimiter) for _, v := range values { formValues.Add(paramName, v) } diff --git a/pkg/utils/headers.go b/pkg/utils/headers.go index d8ca9b1..0837022 100755 --- a/pkg/utils/headers.go +++ b/pkg/utils/headers.go @@ -31,10 +31,11 @@ func PopulateHeaders(ctx context.Context, req *http.Request, headers interface{} } func serializeHeader(objType reflect.Type, objValue reflect.Value, explode bool) string { + if isNil(objType, objValue) { + return "" + } + if objType.Kind() == reflect.Pointer { - if objValue.IsNil() { - return "" - } objType = objType.Elem() objValue = objValue.Elem() } @@ -47,10 +48,11 @@ func serializeHeader(objType reflect.Type, objValue reflect.Value, explode bool) fieldType := objType.Field(i) valType := objValue.Field(i) + if isNil(fieldType.Type, valType) { + continue + } + if fieldType.Type.Kind() == reflect.Pointer { - if valType.IsNil() { - continue - } valType = valType.Elem() } diff --git a/pkg/utils/json.go b/pkg/utils/json.go new file mode 100755 index 0000000..0da3198 --- /dev/null +++ b/pkg/utils/json.go @@ -0,0 +1,579 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package utils + +import ( + "bytes" + "encoding/json" + "fmt" + "math/big" + "reflect" + "strings" + "time" + "unsafe" + + "github.com/fabra-io/go-sdk/pkg/types" + + "github.com/ericlagergren/decimal" +) + +func MarshalJSON(v interface{}, tag reflect.StructTag, topLevel bool) ([]byte, error) { + typ, val := dereferencePointers(reflect.TypeOf(v), reflect.ValueOf(v)) + + switch { + case isModelType(typ): + if topLevel { + return json.Marshal(v) + } + + if isNil(typ, val) { + return []byte("null"), nil + } + + out := map[string]json.RawMessage{} + + for i := 0; i < typ.NumField(); i++ { + field := typ.Field(i) + fieldVal := val.Field(i) + + fieldName := field.Name + + omitEmpty := false + jsonTag := field.Tag.Get("json") + if jsonTag != "" { + for _, tag := range strings.Split(jsonTag, ",") { + if tag == "omitempty" { + omitEmpty = true + } else { + fieldName = tag + } + } + } + + if isNil(field.Type, fieldVal) { + if omitEmpty { + continue + } + } + + if !field.IsExported() && field.Tag.Get("const") == "" { + continue + } + + additionalProperties := field.Tag.Get("additionalProperties") + if fieldName == "-" && additionalProperties == "" { + continue + } + + if additionalProperties == "true" { + if field.Type.Kind() != reflect.Map { + return nil, fmt.Errorf("additionalProperties must be a map") + } + + for _, key := range fieldVal.MapKeys() { + r, err := marshalValue(fieldVal.MapIndex(key).Interface(), field.Tag) + if err != nil { + return nil, err + } + + out[key.String()] = r + } + + continue + } + + var fv interface{} + + if field.IsExported() { + fv = fieldVal.Interface() + } else { + pt := reflect.New(typ).Elem() + pt.Set(val) + + pf := pt.Field(i) + + fv = reflect.NewAt(pf.Type(), unsafe.Pointer(pf.UnsafeAddr())).Elem().Interface() + } + + r, err := marshalValue(fv, field.Tag) + if err != nil { + return nil, err + } + + out[fieldName] = r + } + + return json.Marshal(out) + default: + return marshalValue(v, tag) + } +} + +func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool, disallowUnknownFields bool) error { + if reflect.TypeOf(v).Kind() != reflect.Ptr { + return fmt.Errorf("v must be a pointer") + } + + typ, val := dereferencePointers(reflect.TypeOf(v), reflect.ValueOf(v)) + + switch { + case isModelType(typ): + if topLevel || bytes.Equal(b, []byte("null")) { + d := json.NewDecoder(bytes.NewReader(b)) + if disallowUnknownFields { + d.DisallowUnknownFields() + } + return d.Decode(v) + } + + var unmarhsaled map[string]json.RawMessage + + if err := json.Unmarshal(b, &unmarhsaled); err != nil { + return err + } + + var additionalPropertiesField *reflect.StructField + var additionalPropertiesValue *reflect.Value + + for i := 0; i < typ.NumField(); i++ { + field := typ.Field(i) + fieldVal := val.Field(i) + + fieldName := field.Name + + jsonTag := field.Tag.Get("json") + if jsonTag != "" { + for _, tag := range strings.Split(jsonTag, ",") { + if tag != "omitempty" { + fieldName = tag + } + } + } + + if field.Tag.Get("additionalProperties") == "true" { + additionalPropertiesField = &field + additionalPropertiesValue = &fieldVal + continue + } + + // If we receive a value for a const field ignore it but mark it as unmarshaled + if field.Tag.Get("const") != "" { + if r, ok := unmarhsaled[fieldName]; ok { + val := string(r) + if strings.HasPrefix(val, `"`) && strings.HasSuffix(val, `"`) { + val = val[1 : len(val)-1] + } + if val != field.Tag.Get("const") { + return fmt.Errorf("const field %s does not match expected value %s", fieldName, field.Tag.Get("const")) + } + + delete(unmarhsaled, fieldName) + } + } else if !field.IsExported() { + continue + } + + value, ok := unmarhsaled[fieldName] + if !ok { + defaultTag := field.Tag.Get("default") + if defaultTag != "" { + value = handleDefaultConstValue(defaultTag, fieldVal.Interface(), field.Tag) + ok = true + } + } else { + delete(unmarhsaled, fieldName) + } + + if ok { + if err := unmarshalValue(value, fieldVal, field.Tag, disallowUnknownFields); err != nil { + return err + } + } + } + + keys := make([]string, 0, len(unmarhsaled)) + for k := range unmarhsaled { + keys = append(keys, k) + } + + if len(keys) > 0 { + if disallowUnknownFields && (additionalPropertiesField == nil || additionalPropertiesValue == nil) { + return fmt.Errorf("unknown fields: %v", keys) + } + + if additionalPropertiesField != nil && additionalPropertiesValue != nil { + if additionalPropertiesValue.Kind() != reflect.Map { + return fmt.Errorf("additionalProperties must be a map") + } + + additionalPropertiesValue.Set(reflect.MakeMap(additionalPropertiesField.Type)) + + for key, value := range unmarhsaled { + val := reflect.New(additionalPropertiesField.Type.Elem()) + + if err := unmarshalValue(value, val, additionalPropertiesField.Tag, disallowUnknownFields); err != nil { + return err + } + + additionalPropertiesValue.SetMapIndex(reflect.ValueOf(key), val.Elem()) + } + } + } + default: + return unmarshalValue(b, reflect.ValueOf(v), tag, disallowUnknownFields) + } + + return nil +} + +func marshalValue(v interface{}, tag reflect.StructTag) (json.RawMessage, error) { + constTag := tag.Get("const") + if constTag != "" { + return handleDefaultConstValue(constTag, v, tag), nil + } + + if isNil(reflect.TypeOf(v), reflect.ValueOf(v)) { + defaultTag := tag.Get("default") + if defaultTag != "" { + return handleDefaultConstValue(defaultTag, v, tag), nil + } + + return []byte("null"), nil + } + + typ, val := dereferencePointers(reflect.TypeOf(v), reflect.ValueOf(v)) + switch typ.Kind() { + case reflect.Map: + if isNil(typ, val) { + return []byte("null"), nil + } + + out := map[string]json.RawMessage{} + + for _, key := range val.MapKeys() { + itemVal := val.MapIndex(key) + + if isNil(itemVal.Type(), itemVal) { + out[key.String()] = []byte("null") + continue + } + + r, err := marshalValue(itemVal.Interface(), tag) + if err != nil { + return nil, err + } + + out[key.String()] = r + } + + return json.Marshal(out) + case reflect.Slice, reflect.Array: + if isNil(typ, val) { + return []byte("null"), nil + } + + out := []json.RawMessage{} + + for i := 0; i < val.Len(); i++ { + itemVal := val.Index(i) + + if isNil(itemVal.Type(), itemVal) { + out = append(out, []byte("null")) + continue + } + + r, err := marshalValue(itemVal.Interface(), tag) + if err != nil { + return nil, err + } + + out = append(out, r) + } + + return json.Marshal(out) + case reflect.Struct: + switch typ { + case reflect.TypeOf(time.Time{}): + return []byte(fmt.Sprintf(`"%s"`, val.Interface().(time.Time).Format(time.RFC3339Nano))), nil + case reflect.TypeOf(big.Int{}): + format := tag.Get("bigint") + if format == "string" { + b := val.Interface().(big.Int) + return []byte(fmt.Sprintf(`"%s"`, (&b).String())), nil + } + case reflect.TypeOf(decimal.Big{}): + format := tag.Get("decimal") + if format == "number" { + b := val.Interface().(decimal.Big) + f, ok := (&b).Float64() + if ok { + return []byte(b.String()), nil + } + + return []byte(fmt.Sprintf(`%f`, f)), nil + } + } + } + + return json.Marshal(v) +} + +func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.StructTag) json.RawMessage { + if tagValue == "null" { + return []byte("null") + } + + typ := dereferenceTypePointer(reflect.TypeOf(val)) + switch typ { + case reflect.TypeOf(time.Time{}): + return []byte(fmt.Sprintf(`"%s"`, tagValue)) + case reflect.TypeOf(big.Int{}): + bigIntTag := tag.Get("bigint") + if bigIntTag == "string" { + return []byte(fmt.Sprintf(`"%s"`, tagValue)) + } + case reflect.TypeOf(decimal.Big{}): + decimalTag := tag.Get("decimal") + if decimalTag != "number" { + return []byte(fmt.Sprintf(`"%s"`, tagValue)) + } + case reflect.TypeOf(types.Date{}): + return []byte(fmt.Sprintf(`"%s"`, tagValue)) + default: + if typ.Kind() == reflect.String { + return []byte(fmt.Sprintf(`"%s"`, tagValue)) + } + } + + return []byte(tagValue) +} + +func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTag, disallowUnknownFields bool) error { + if bytes.Equal(value, []byte("null")) { + if v.CanAddr() { + return json.Unmarshal(value, v.Addr().Interface()) + } else { + return json.Unmarshal(value, v.Interface()) + } + } + + typ := dereferenceTypePointer(v.Type()) + + switch typ.Kind() { + case reflect.Map: + if bytes.Equal(value, []byte("null")) || !isComplexValueType(dereferenceTypePointer(typ.Elem())) { + if v.CanAddr() { + return json.Unmarshal(value, v.Addr().Interface()) + } else { + return json.Unmarshal(value, v.Interface()) + } + } + + var unmarhsaled map[string]json.RawMessage + + if err := json.Unmarshal(value, &unmarhsaled); err != nil { + return err + } + + m := reflect.MakeMap(typ) + + for k, value := range unmarhsaled { + itemVal := reflect.New(typ.Elem()) + + if err := unmarshalValue(value, itemVal, tag, disallowUnknownFields); err != nil { + return err + } + + m.SetMapIndex(reflect.ValueOf(k), itemVal.Elem()) + } + + v.Set(m) + return nil + case reflect.Slice, reflect.Array: + if bytes.Equal(value, []byte("null")) || !isComplexValueType(dereferenceTypePointer(typ.Elem())) { + if v.CanAddr() { + return json.Unmarshal(value, v.Addr().Interface()) + } else { + return json.Unmarshal(value, v.Interface()) + } + } + + var unmarhsaled []json.RawMessage + + if err := json.Unmarshal(value, &unmarhsaled); err != nil { + return err + } + + arrVal := v + + for _, value := range unmarhsaled { + itemVal := reflect.New(typ.Elem()) + + if err := unmarshalValue(value, itemVal, tag, disallowUnknownFields); err != nil { + return err + } + + arrVal = reflect.Append(arrVal, itemVal.Elem()) + } + + v.Set(arrVal) + return nil + case reflect.Struct: + switch typ { + case reflect.TypeOf(time.Time{}): + var s string + if err := json.Unmarshal(value, &s); err != nil { + return err + } + + t, err := time.Parse(time.RFC3339Nano, s) + if err != nil { + return fmt.Errorf("failed to parse string as time.Time: %w", err) + } + + if v.Kind() == reflect.Ptr { + if v.IsNil() { + v.Set(reflect.New(typ)) + } + v = v.Elem() + } + + v.Set(reflect.ValueOf(t)) + return nil + case reflect.TypeOf(big.Int{}): + var b *big.Int + + format := tag.Get("bigint") + if format == "string" { + var s string + if err := json.Unmarshal(value, &s); err != nil { + return err + } + + var ok bool + b, ok = new(big.Int).SetString(s, 10) + if !ok { + return fmt.Errorf("failed to parse string as big.Int") + } + } else { + if err := json.Unmarshal(value, &b); err != nil { + return err + } + } + + if v.Kind() == reflect.Ptr && v.Elem().Kind() == reflect.Ptr { + v = v.Elem() + } + + v.Set(reflect.ValueOf(b)) + return nil + case reflect.TypeOf(decimal.Big{}): + var d *decimal.Big + format := tag.Get("decimal") + if format == "number" { + var ok bool + d, ok = new(decimal.Big).SetString(string(value)) + if !ok { + return fmt.Errorf("failed to parse number as decimal.Big") + } + } else { + if err := json.Unmarshal(value, &d); err != nil { + return err + } + } + + if v.Kind() == reflect.Ptr && v.Elem().Kind() == reflect.Ptr { + v = v.Elem() + } + + v.Set(reflect.ValueOf(d)) + return nil + case reflect.TypeOf(types.Date{}): + var s string + + if err := json.Unmarshal(value, &s); err != nil { + return err + } + + d, err := types.DateFromString(s) + if err != nil { + return fmt.Errorf("failed to parse string as types.Date: %w", err) + } + + if v.Kind() == reflect.Ptr { + if v.IsNil() { + v.Set(reflect.New(typ)) + } + v = v.Elem() + } + + v.Set(reflect.ValueOf(d)) + return nil + } + } + + var val interface{} + + if v.CanAddr() { + val = v.Addr().Interface() + } else { + val = v.Interface() + } + + d := json.NewDecoder(bytes.NewReader(value)) + if disallowUnknownFields { + d.DisallowUnknownFields() + } + return d.Decode(val) +} + +func dereferencePointers(typ reflect.Type, val reflect.Value) (reflect.Type, reflect.Value) { + if typ.Kind() == reflect.Ptr { + typ = typ.Elem() + val = val.Elem() + } else { + return typ, val + } + + return dereferencePointers(typ, val) +} + +func dereferenceTypePointer(typ reflect.Type) reflect.Type { + if typ.Kind() == reflect.Ptr { + typ = typ.Elem() + } else { + return typ + } + + return dereferenceTypePointer(typ) +} + +func isComplexValueType(typ reflect.Type) bool { + switch typ.Kind() { + case reflect.Struct: + switch typ { + case reflect.TypeOf(time.Time{}): + fallthrough + case reflect.TypeOf(big.Int{}): + fallthrough + case reflect.TypeOf(decimal.Big{}): + fallthrough + case reflect.TypeOf(types.Date{}): + return true + } + } + + return false +} + +func isModelType(typ reflect.Type) bool { + if isComplexValueType(typ) { + return false + } + + if typ.Kind() == reflect.Struct { + return true + } + + return false +} diff --git a/pkg/utils/pathparams.go b/pkg/utils/pathparams.go index c2fd728..f309a26 100755 --- a/pkg/utils/pathparams.go +++ b/pkg/utils/pathparams.go @@ -5,9 +5,15 @@ package utils import ( "context" "fmt" + "math/big" "net/url" "reflect" "strings" + "time" + + "github.com/ericlagergren/decimal" + + "github.com/fabra-io/go-sdk/pkg/types" ) func GenerateURL(ctx context.Context, serverURL, path string, pathParams interface{}, globals map[string]map[string]map[string]interface{}) (string, error) { @@ -61,10 +67,11 @@ func GenerateURL(ctx context.Context, serverURL, path string, pathParams interfa func getSimplePathParams(ctx context.Context, parentName string, objType reflect.Type, objValue reflect.Value, explode bool) map[string]string { pathParams := make(map[string]string) + if isNil(objType, objValue) { + return nil + } + if objType.Kind() == reflect.Ptr { - if objValue.IsNil() { - return nil - } objType = objType.Elem() objValue = objValue.Elem() } @@ -94,30 +101,42 @@ func getSimplePathParams(ctx context.Context, parentName string, objType reflect } pathParams[parentName] = strings.Join(ppVals, ",") case reflect.Struct: - var ppVals []string - for i := 0; i < objType.NumField(); i++ { - fieldType := objType.Field(i) - valType := objValue.Field(i) - - ppTag := parseParamTag(pathParamTagKey, fieldType, "simple", explode) - if ppTag == nil { - continue - } + switch objValue.Interface().(type) { + case time.Time: + pathParams[parentName] = valToString(objValue.Interface()) + case types.Date: + pathParams[parentName] = valToString(objValue.Interface()) + case big.Int: + pathParams[parentName] = valToString(objValue.Interface()) + case decimal.Big: + pathParams[parentName] = valToString(objValue.Interface()) + default: + var ppVals []string + for i := 0; i < objType.NumField(); i++ { + fieldType := objType.Field(i) + valType := objValue.Field(i) + + ppTag := parseParamTag(pathParamTagKey, fieldType, "simple", explode) + if ppTag == nil { + continue + } - if fieldType.Type.Kind() == reflect.Pointer { - if valType.IsNil() { + if isNil(fieldType.Type, valType) { continue } - valType = valType.Elem() - } - if explode { - ppVals = append(ppVals, fmt.Sprintf("%s=%s", ppTag.ParamName, valToString(valType.Interface()))) - } else { - ppVals = append(ppVals, fmt.Sprintf("%s,%s", ppTag.ParamName, valToString(valType.Interface()))) + if fieldType.Type.Kind() == reflect.Pointer { + valType = valType.Elem() + } + + if explode { + ppVals = append(ppVals, fmt.Sprintf("%s=%s", ppTag.ParamName, valToString(valType.Interface()))) + } else { + ppVals = append(ppVals, fmt.Sprintf("%s,%s", ppTag.ParamName, valToString(valType.Interface()))) + } } + pathParams[parentName] = strings.Join(ppVals, ",") } - pathParams[parentName] = strings.Join(ppVals, ",") default: pathParams[parentName] = valToString(objValue.Interface()) } diff --git a/pkg/utils/queryparams.go b/pkg/utils/queryparams.go index 87ecef8..0e94bce 100755 --- a/pkg/utils/queryparams.go +++ b/pkg/utils/queryparams.go @@ -76,15 +76,13 @@ func PopulateQueryParams(ctx context.Context, req *http.Request, queryParams int } func populateSerializedParams(tag *paramTag, objType reflect.Type, objValue reflect.Value) (map[string]string, error) { + if isNil(objType, objValue) { + return nil, nil + } + if objType.Kind() == reflect.Pointer { - if objValue.IsNil() { - return nil, nil - } objValue = objValue.Elem() } - if objValue.Interface() == nil { - return nil, nil - } values := map[string]string{} @@ -103,10 +101,11 @@ func populateSerializedParams(tag *paramTag, objType reflect.Type, objValue refl func populateDeepObjectParams(req *http.Request, tag *paramTag, objType reflect.Type, objValue reflect.Value) url.Values { values := url.Values{} + if isNil(objType, objValue) { + return values + } + if objType.Kind() == reflect.Pointer { - if objValue.IsNil() { - return values - } objType = objType.Elem() objValue = objValue.Elem() } @@ -117,10 +116,11 @@ func populateDeepObjectParams(req *http.Request, tag *paramTag, objType reflect. fieldType := objType.Field(i) valType := objValue.Field(i) + if isNil(fieldType.Type, valType) { + continue + } + if fieldType.Type.Kind() == reflect.Pointer { - if valType.IsNil() { - continue - } valType = valType.Elem() } diff --git a/pkg/utils/requestbody.go b/pkg/utils/requestbody.go index 5c1d263..950f39a 100755 --- a/pkg/utils/requestbody.go +++ b/pkg/utils/requestbody.go @@ -5,7 +5,6 @@ package utils import ( "bytes" "context" - "encoding/json" "fmt" "io" "mime/multipart" @@ -26,21 +25,25 @@ var ( urlEncodedEncodingRegex = regexp.MustCompile(`application\/x-www-form-urlencoded.*`) ) -func SerializeRequestBody(ctx context.Context, request interface{}, requestFieldName string, serializationMethod string) (*bytes.Buffer, string, error) { +func SerializeRequestBody(ctx context.Context, request interface{}, nullable, optional bool, requestFieldName, serializationMethod, tag string) (io.Reader, string, error) { requestStructType := reflect.TypeOf(request) requestValType := reflect.ValueOf(request) - if requestStructType.Kind() == reflect.Pointer { - if requestValType.IsNil() { + if isNil(requestStructType, requestValType) { + if !nullable && optional { return nil, "", nil } + return serializeContentType(requestFieldName, SerializationMethodToContentType[serializationMethod], requestValType, tag) + } + + if requestStructType.Kind() == reflect.Pointer { requestStructType = requestStructType.Elem() requestValType = requestValType.Elem() } if requestStructType.Kind() != reflect.Struct { - return serializeContentType(requestFieldName, SerializationMethodToContentType[serializationMethod], requestValType) + return serializeContentType(requestFieldName, SerializationMethodToContentType[serializationMethod], requestValType, tag) } requestField, ok := requestStructType.FieldByName(requestFieldName) @@ -50,24 +53,44 @@ func SerializeRequestBody(ctx context.Context, request interface{}, requestField if tag != nil { // request object (non-flattened) requestVal := requestValType.FieldByName(requestFieldName) - if requestField.Type.Kind() == reflect.Pointer && requestVal.IsNil() { - return nil, "", nil + if isNil(requestField.Type, requestVal) { + if !nullable && optional { + return nil, "", nil + } + + return serializeContentType(requestFieldName, tag.MediaType, requestVal, string(requestField.Tag)) } - return serializeContentType(requestFieldName, tag.MediaType, requestVal) + return serializeContentType(requestFieldName, tag.MediaType, requestVal, string(requestField.Tag)) } } // flattened request object - return serializeContentType(requestFieldName, SerializationMethodToContentType[serializationMethod], requestValType) + return serializeContentType(requestFieldName, SerializationMethodToContentType[serializationMethod], reflect.ValueOf(request), tag) } -func serializeContentType(fieldName string, mediaType string, val reflect.Value) (*bytes.Buffer, string, error) { +func serializeContentType(fieldName string, mediaType string, val reflect.Value, tag string) (*bytes.Buffer, string, error) { buf := &bytes.Buffer{} + if isNil(val.Type(), val) { + // TODO: what does a null mean for other content types? Just returning an empty buffer for now + if jsonEncodingRegex.MatchString(mediaType) { + if _, err := buf.Write([]byte("null")); err != nil { + return nil, "", err + } + } + + return buf, mediaType, nil + } + switch { case jsonEncodingRegex.MatchString(mediaType): - if err := json.NewEncoder(buf).Encode(val.Interface()); err != nil { + data, err := MarshalJSON(val.Interface(), reflect.StructTag(tag), true) + if err != nil { + return nil, "", err + } + + if _, err := buf.Write(data); err != nil { return nil, "", err } case multipartEncodingRegex.MatchString(mediaType): @@ -116,11 +139,11 @@ func encodeMultipartFormData(w io.Writer, data interface{}) (string, error) { fieldType := field.Type valType := requestValType.Field(i) - if fieldType.Kind() == reflect.Pointer { - if valType.IsNil() { - continue - } + if isNil(fieldType, valType) { + continue + } + if fieldType.Kind() == reflect.Pointer { fieldType = fieldType.Elem() valType = valType.Elem() } @@ -137,7 +160,7 @@ func encodeMultipartFormData(w io.Writer, data interface{}) (string, error) { writer.Close() return "", err } - d, err := json.Marshal(valType.Interface()) + d, err := MarshalJSON(valType.Interface(), field.Tag, true) if err != nil { writer.Close() return "", err @@ -231,18 +254,18 @@ func encodeFormData(fieldName string, w io.Writer, data interface{}) error { fieldType := field.Type valType := requestValType.Field(i) - if fieldType.Kind() == reflect.Pointer { - if valType.IsNil() { - continue - } + if isNil(fieldType, valType) { + continue + } + if fieldType.Kind() == reflect.Pointer { fieldType = fieldType.Elem() valType = valType.Elem() } tag := parseFormTag(field) if tag.JSON { - data, err := json.Marshal(valType.Interface()) + data, err := MarshalJSON(valType.Interface(), field.Tag, true) if err != nil { return err } diff --git a/pkg/utils/security.go b/pkg/utils/security.go index c920eab..fa5eff7 100755 --- a/pkg/utils/security.go +++ b/pkg/utils/security.go @@ -3,6 +3,7 @@ package utils import ( + "context" "encoding/base64" "fmt" "net/http" @@ -26,137 +27,142 @@ type securityTag struct { SubType string } -type SecurityClient struct { - client HTTPClient +type securityConfig struct { headers map[string]string queryParams map[string]string } -func newSecurityClient(client HTTPClient) *SecurityClient { +type SecurityClient struct { + HTTPClient + security func(ctx context.Context) (interface{}, error) +} + +func newSecurityClient(client HTTPClient, security func(ctx context.Context) (interface{}, error)) *SecurityClient { return &SecurityClient{ - client: client, - headers: make(map[string]string), - queryParams: make(map[string]string), + HTTPClient: client, + security: security, } } func (c *SecurityClient) Do(req *http.Request) (*http.Response, error) { - for k, v := range c.headers { + securityCtx, err := c.security(req.Context()) + if err != nil { + return nil, err + } + + ctx := securityConfig{ + headers: make(map[string]string), + queryParams: make(map[string]string), + } + parseSecurityStruct(&ctx, securityCtx) + + for k, v := range ctx.headers { req.Header.Set(k, v) } queryParams := req.URL.Query() - for k, v := range c.queryParams { - queryParams.Set(k, v) + for k, v := range ctx.queryParams { + queryParams.Add(k, v) } req.URL.RawQuery = queryParams.Encode() - return c.client.Do(req) + return c.HTTPClient.Do(req) } -func ConfigureSecurityClient(c HTTPClient, security interface{}) *SecurityClient { - client := parseSecurityStruct(c, security) - if client != nil { - return client - } +func ConfigureSecurityClient(c HTTPClient, security func(ctx context.Context) (interface{}, error)) *SecurityClient { + return newSecurityClient(c, security) +} - return newSecurityClient(c) +func trueReflectValue(val reflect.Value) reflect.Value { + kind := val.Type().Kind() + for kind == reflect.Interface || kind == reflect.Ptr { + innerVal := val.Elem() + if !innerVal.IsValid() { + break + } + val = innerVal + kind = val.Type().Kind() + } + return val } -func parseSecurityStruct(c HTTPClient, security interface{}) *SecurityClient { - securityStructType := reflect.TypeOf(security) - securityValType := reflect.ValueOf(security) +func parseSecurityStruct(c *securityConfig, security interface{}) { + securityValType := trueReflectValue(reflect.ValueOf(security)) + securityStructType := securityValType.Type() - if securityStructType.Kind() == reflect.Ptr { - if securityValType.IsNil() { - return nil - } + if isNil(securityStructType, securityValType) { + return + } + if securityStructType.Kind() == reflect.Ptr { securityStructType = securityStructType.Elem() securityValType = securityValType.Elem() } - client := newSecurityClient(c) - for i := 0; i < securityStructType.NumField(); i++ { fieldType := securityStructType.Field(i) valType := securityValType.Field(i) kind := valType.Kind() - if fieldType.Type.Kind() == reflect.Pointer { - if valType.IsNil() { - continue - } + if isNil(fieldType.Type, valType) { + continue + } + if fieldType.Type.Kind() == reflect.Pointer { kind = valType.Elem().Kind() } secTag := parseSecurityTag(fieldType) if secTag != nil { if secTag.Option { - return parseSecurityOption(c, valType.Interface()) + handleSecurityOption(c, valType.Interface()) } else if secTag.Scheme { // Special case for basic auth which could be a flattened struct if secTag.SubType == "basic" && kind != reflect.Struct { - parseSecurityScheme(client, secTag, security) - return client + parseSecurityScheme(c, secTag, security) } else { - parseSecurityScheme(client, secTag, valType.Interface()) + parseSecurityScheme(c, secTag, valType.Interface()) } } } } - - return client } -func parseSecurityOption(c HTTPClient, option interface{}) *SecurityClient { - optionStructType := reflect.TypeOf(option) - optionValType := reflect.ValueOf(option) +func handleSecurityOption(c *securityConfig, option interface{}) error { + optionValType := trueReflectValue(reflect.ValueOf(option)) + optionStructType := optionValType.Type() - if optionStructType.Kind() == reflect.Ptr { - if optionValType.IsNil() { - return nil - } - - optionStructType = optionStructType.Elem() - optionValType = optionValType.Elem() + if isNil(optionStructType, optionValType) { + return nil } - client := newSecurityClient(c) - for i := 0; i < optionStructType.NumField(); i++ { fieldType := optionStructType.Field(i) valType := optionValType.Field(i) secTag := parseSecurityTag(fieldType) if secTag != nil && secTag.Scheme { - parseSecurityScheme(client, secTag, valType.Interface()) + parseSecurityScheme(c, secTag, valType.Interface()) } } - return client + return nil } -func parseSecurityScheme(client *SecurityClient, schemeTag *securityTag, scheme interface{}) { - schemeType := reflect.TypeOf(scheme) - schemeVal := reflect.ValueOf(scheme) - - if schemeType.Kind() == reflect.Ptr { - if schemeVal.IsNil() { - return - } +func parseSecurityScheme(client *securityConfig, schemeTag *securityTag, scheme interface{}) { + schemeVal := trueReflectValue(reflect.ValueOf(scheme)) + schemeType := schemeVal.Type() - schemeType = schemeType.Elem() - schemeVal = schemeVal.Elem() + if isNil(schemeType, schemeVal) { + return } if schemeType.Kind() == reflect.Struct { if schemeTag.Type == "http" && schemeTag.SubType == "basic" { - parseBasicAuthScheme(client, schemeVal.Interface()) + handleBasicAuthScheme(client, schemeVal.Interface()) return } @@ -164,11 +170,11 @@ func parseSecurityScheme(client *SecurityClient, schemeTag *securityTag, scheme fieldType := schemeType.Field(i) valType := schemeVal.Field(i) - if fieldType.Type.Kind() == reflect.Ptr { - if valType.IsNil() { - continue - } + if isNil(fieldType.Type, valType) { + continue + } + if fieldType.Type.Kind() == reflect.Ptr { valType = valType.Elem() } @@ -184,7 +190,7 @@ func parseSecurityScheme(client *SecurityClient, schemeTag *securityTag, scheme } } -func parseSecuritySchemeValue(client *SecurityClient, schemeTag *securityTag, secTag *securityTag, val interface{}) { +func parseSecuritySchemeValue(client *securityConfig, schemeTag *securityTag, secTag *securityTag, val interface{}) { switch schemeTag.Type { case "apiKey": switch schemeTag.SubType { @@ -204,7 +210,7 @@ func parseSecuritySchemeValue(client *SecurityClient, schemeTag *securityTag, se case "http": switch schemeTag.SubType { case "bearer": - client.headers[secTag.Name] = valToString(val) + client.headers[secTag.Name] = prefixBearer(valToString(val)) default: panic("not supported") } @@ -213,7 +219,15 @@ func parseSecuritySchemeValue(client *SecurityClient, schemeTag *securityTag, se } } -func parseBasicAuthScheme(client *SecurityClient, scheme interface{}) { +func prefixBearer(authHeaderValue string) string { + if strings.HasPrefix(strings.ToLower(authHeaderValue), "bearer ") { + return authHeaderValue + } + + return fmt.Sprintf("Bearer %s", authHeaderValue) +} + +func handleBasicAuthScheme(client *securityConfig, scheme interface{}) { schemeStructType := reflect.TypeOf(scheme) schemeValType := reflect.ValueOf(scheme) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 7d98f51..4ef632a 100755 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -3,13 +3,15 @@ package utils import ( - "encoding/json" "fmt" "io" + "math/big" "reflect" "regexp" "strings" "time" + + "github.com/ericlagergren/decimal" ) const ( @@ -29,12 +31,12 @@ var ( } ) -func UnmarshalJsonFromResponseBody(body io.Reader, out interface{}) error { +func UnmarshalJsonFromResponseBody(body io.Reader, out interface{}, tag string) error { data, err := io.ReadAll(body) if err != nil { return fmt.Errorf("error reading response body: %w", err) } - if err := json.Unmarshal(data, &out); err != nil { + if err := UnmarshalJSON(data, out, reflect.StructTag(tag), true, false); err != nil { return fmt.Errorf("error unmarshalling json response body: %w", err) } @@ -42,6 +44,10 @@ func UnmarshalJsonFromResponseBody(body io.Reader, out interface{}) error { } func ReplaceParameters(stringWithParams string, params map[string]string) string { + if len(params) == 0 { + return stringWithParams + } + return paramRegex.ReplaceAllStringFunc(stringWithParams, func(match string) string { match = match[1 : len(match)-1] return params[match] @@ -120,6 +126,10 @@ func valToString(val interface{}) string { switch v := val.(type) { case time.Time: return v.Format(time.RFC3339Nano) + case big.Int: + return v.String() + case decimal.Big: + return v.String() default: return fmt.Sprintf("%v", v) } @@ -143,3 +153,19 @@ func populateFromGlobals(fieldType reflect.StructField, valType reflect.Value, p return valType } + +func isNil(typ reflect.Type, val reflect.Value) bool { + // `reflect.TypeOf(nil) == nil` so calling typ.Kind() will cause a nil pointer + // dereference panic. Catch it and return early. + // https://github.com/golang/go/issues/51649 + // https://github.com/golang/go/issues/54208 + if typ == nil { + return true + } + + if typ.Kind() == reflect.Ptr || typ.Kind() == reflect.Map || typ.Kind() == reflect.Slice || typ.Kind() == reflect.Interface { + return val.IsNil() + } + + return false +} diff --git a/source.go b/source.go index 6ca519d..b4067d9 100755 --- a/source.go +++ b/source.go @@ -1,45 +1,37 @@ // Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. -package fabra +package gosdk import ( + "bytes" "context" "fmt" "github.com/fabra-io/go-sdk/pkg/models/operations" + "github.com/fabra-io/go-sdk/pkg/models/sdkerrors" "github.com/fabra-io/go-sdk/pkg/models/shared" "github.com/fabra-io/go-sdk/pkg/utils" + "io" "net/http" "strings" ) // source - Operations on sources type source struct { - defaultClient HTTPClient - securityClient HTTPClient - serverURL string - language string - sdkVersion string - genVersion string + sdkConfiguration sdkConfiguration } -func newSource(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *source { +func newSource(sdkConfig sdkConfiguration) *source { return &source{ - defaultClient: defaultClient, - securityClient: securityClient, - serverURL: serverURL, - language: language, - sdkVersion: sdkVersion, - genVersion: genVersion, + sdkConfiguration: sdkConfig, } } // CreateSource - Create a new source - func (s *source) CreateSource(ctx context.Context, request shared.SourceInput) (*operations.CreateSourceResponse, error) { - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/source" - bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, fmt.Errorf("error serializing request body: %w", err) } @@ -51,10 +43,12 @@ func (s *source) CreateSource(ctx context.Context, request shared.SourceInput) ( if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) req.Header.Set("Content-Type", reqContentType) - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -63,7 +57,6 @@ func (s *source) CreateSource(ctx context.Context, request shared.SourceInput) ( if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -72,16 +65,25 @@ func (s *source) CreateSource(ctx context.Context, request shared.SourceInput) ( ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *operations.CreateSource200ApplicationJSON - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out operations.CreateSource200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.CreateSource200ApplicationJSONObject = out + res.CreateSource200ApplicationJSONObject = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough @@ -92,17 +94,18 @@ func (s *source) CreateSource(ctx context.Context, request shared.SourceInput) ( } // GetSources - Get all sources - func (s *source) GetSources(ctx context.Context) (*operations.GetSourcesResponse, error) { - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/sources" req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -111,7 +114,6 @@ func (s *source) GetSources(ctx context.Context) (*operations.GetSourcesResponse if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -120,16 +122,25 @@ func (s *source) GetSources(ctx context.Context) (*operations.GetSourcesResponse ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *operations.GetSources200ApplicationJSON - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out operations.GetSources200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.GetSources200ApplicationJSONObject = out + res.GetSources200ApplicationJSONObject = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough diff --git a/sync.go b/sync.go index 102a227..3bf82ca 100755 --- a/sync.go +++ b/sync.go @@ -1,45 +1,37 @@ // Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. -package fabra +package gosdk import ( + "bytes" "context" "fmt" "github.com/fabra-io/go-sdk/pkg/models/operations" + "github.com/fabra-io/go-sdk/pkg/models/sdkerrors" "github.com/fabra-io/go-sdk/pkg/models/shared" "github.com/fabra-io/go-sdk/pkg/utils" + "io" "net/http" "strings" ) // sync - Operations on syncs type sync struct { - defaultClient HTTPClient - securityClient HTTPClient - serverURL string - language string - sdkVersion string - genVersion string + sdkConfiguration sdkConfiguration } -func newSync(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *sync { +func newSync(sdkConfig sdkConfiguration) *sync { return &sync{ - defaultClient: defaultClient, - securityClient: securityClient, - serverURL: serverURL, - language: language, - sdkVersion: sdkVersion, - genVersion: genVersion, + sdkConfiguration: sdkConfig, } } // CreateSync - Create a new sync - func (s *sync) CreateSync(ctx context.Context, request shared.SyncInput) (*operations.CreateSyncResponse, error) { - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/sync" - bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`) if err != nil { return nil, fmt.Errorf("error serializing request body: %w", err) } @@ -51,10 +43,12 @@ func (s *sync) CreateSync(ctx context.Context, request shared.SyncInput) (*opera if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) req.Header.Set("Content-Type", reqContentType) - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -63,7 +57,6 @@ func (s *sync) CreateSync(ctx context.Context, request shared.SyncInput) (*opera if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -72,16 +65,25 @@ func (s *sync) CreateSync(ctx context.Context, request shared.SyncInput) (*opera ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *operations.CreateSync200ApplicationJSON - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out operations.CreateSync200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.CreateSync200ApplicationJSONObject = out + res.CreateSync200ApplicationJSONObject = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough @@ -92,17 +94,18 @@ func (s *sync) CreateSync(ctx context.Context, request shared.SyncInput) (*opera } // GetSyncs - Get all syncs - func (s *sync) GetSyncs(ctx context.Context) (*operations.GetSyncsResponse, error) { - baseURL := s.serverURL + baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails()) url := strings.TrimSuffix(baseURL, "/") + "/syncs" req, err := http.NewRequestWithContext(ctx, "GET", url, nil) if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } + req.Header.Set("Accept", "application/json") + req.Header.Set("user-agent", s.sdkConfiguration.UserAgent) - client := s.securityClient + client := s.sdkConfiguration.SecurityClient httpRes, err := client.Do(req) if err != nil { @@ -111,7 +114,6 @@ func (s *sync) GetSyncs(ctx context.Context) (*operations.GetSyncsResponse, erro if httpRes == nil { return nil, fmt.Errorf("error sending request: no response") } - defer httpRes.Body.Close() contentType := httpRes.Header.Get("Content-Type") @@ -120,16 +122,25 @@ func (s *sync) GetSyncs(ctx context.Context) (*operations.GetSyncsResponse, erro ContentType: contentType, RawResponse: httpRes, } + + rawBody, err := io.ReadAll(httpRes.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + httpRes.Body.Close() + httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody)) switch { case httpRes.StatusCode == 200: switch { case utils.MatchContentType(contentType, `application/json`): - var out *operations.GetSyncs200ApplicationJSON - if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + var out operations.GetSyncs200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil { return nil, err } - res.GetSyncs200ApplicationJSONObject = out + res.GetSyncs200ApplicationJSONObject = &out + default: + return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", contentType), httpRes.StatusCode, string(rawBody), httpRes) } case httpRes.StatusCode == 401: fallthrough