Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): OpenAPI spec update via Stainless API #19

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
- name: Setup go
uses: actions/setup-go@v5

- run: |
go build ./...
- name: Run lints
run: ./scripts/lint
test:
name: test
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 4
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/terminal%2Fterminal-e54ebed8f52d6a057b7005fbd26426924298d8bcd83613179b2b68143d9f8bfa.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/terminal%2Fterminal-4ef9c140aca75dc7f78b703731d689ba4fba551ad5e49dce0af1975e42d01a21.yml
4 changes: 2 additions & 2 deletions cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type CartListResponseResult struct {
ID string `json:"id,required"`
ProductVariantID string `json:"productVariantID,required"`
Quantity int64 `json:"quantity,required"`
Subtotal string `json:"subtotal,required"`
Subtotal float64 `json:"subtotal,required"`
JSON cartListResponseResultJSON `json:"-"`
}

Expand Down Expand Up @@ -118,7 +118,7 @@ type CartSetItemResponseResult struct {
ID string `json:"id,required"`
ProductVariantID string `json:"productVariantID,required"`
Quantity int64 `json:"quantity,required"`
Subtotal string `json:"subtotal,required"`
Subtotal float64 `json:"subtotal,required"`
JSON cartSetItemResponseResultJSON `json:"-"`
}

Expand Down
5 changes: 2 additions & 3 deletions internal/apierror/apierror.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package apierror

import (
"fmt"
"io"
"net/http"
"net/http/httputil"

Expand Down Expand Up @@ -36,8 +35,8 @@ func (r errorJSON) RawJSON() string {
}

func (r *Error) Error() string {
body, _ := io.ReadAll(r.Response.Body)
return fmt.Sprintf("%s \"%s\": %d %s %s", r.Request.Method, r.Request.URL, r.Response.StatusCode, http.StatusText(r.Response.StatusCode), string(body))
// Attempt to re-populate the response body
return fmt.Sprintf("%s \"%s\": %d %s %s", r.Request.Method, r.Request.URL, r.Response.StatusCode, http.StatusText(r.Response.StatusCode), r.JSON.RawJSON())
}

func (r *Error) DumpRequest(body bool) []byte {
Expand Down
3 changes: 2 additions & 1 deletion internal/requestconfig/requestconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ func (cfg *RequestConfig) Execute() (err error) {
}

// If we are not json, return plaintext
isJSON := strings.Contains(res.Header.Get("content-type"), "application/json")
contentType := res.Header.Get("content-type")
isJSON := strings.Contains(contentType, "application/json") || strings.Contains(contentType, "application/vnd.api+json")
if !isJSON {
switch dst := cfg.ResponseBodyInto.(type) {
case *string:
Expand Down
2 changes: 1 addition & 1 deletion product.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (r productListResponseResultJSON) RawJSON() string {
type ProductListResponseResultVariant struct {
ID string `json:"id,required"`
Name string `json:"name,required"`
Price string `json:"price,required"`
Price int64 `json:"price,required"`
JSON productListResponseResultVariantJSON `json:"-"`
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -e

cd "$(dirname "$0")/.."

gofmt ./...

echo "==> Running gofmt -s -w"
gofmt -s -w ./...
8 changes: 8 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

echo "==> Running Go build"
go build ./...
1 change: 0 additions & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ else
echo
fi

# Run tests
echo "==> Running tests"
go test ./... "$@"
20 changes: 11 additions & 9 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ func (r *UserService) Me(ctx context.Context, opts ...option.RequestOption) (res
}

type User struct {
ID string `json:"id,required"`
Email string `json:"email,required,nullable"`
Fingerprint string `json:"fingerprint,required,nullable"`
JSON userJSON `json:"-"`
ID string `json:"id,required"`
Email string `json:"email,required,nullable"`
Fingerprint string `json:"fingerprint,required,nullable"`
StripeCustomerID string `json:"stripeCustomerID,required"`
JSON userJSON `json:"-"`
}

// userJSON contains the JSON metadata for the struct [User]
type userJSON struct {
ID apijson.Field
Email apijson.Field
Fingerprint apijson.Field
raw string
ExtraFields map[string]apijson.Field
ID apijson.Field
Email apijson.Field
Fingerprint apijson.Field
StripeCustomerID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *User) UnmarshalJSON(data []byte) (err error) {
Expand Down