Skip to content

Commit

Permalink
ci: regenerated with OpenAPI Doc v1, Speakeay CLI 1.91.3
Browse files Browse the repository at this point in the history
  • Loading branch information
speakeasybot committed Sep 29, 2023
1 parent b62b3e8 commit 9d818bf
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 81 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func main() {

ctx := context.Background()
res, err := s.PostSendPet(ctx, shared.Pet1{
ID: 847252,
Name: "Sabrina Oberbrunner",
Tag: testwithoutwebhooksgosdk.String("magnam"),
ID: 794362,
Name: "Platinum",
Tag: testwithoutwebhooksgosdk.String("Fresh Washington Royce"),
})
if err != nil {
log.Fatal(err)
Expand All @@ -58,8 +58,6 @@ func main() {

<!-- Start Dev Containers -->



<!-- End Dev Containers -->


Expand All @@ -72,8 +70,6 @@ returned response object will have a `Next` method that can be called to pull do
return value of `Next` is `nil`, then there are no more pages to be fetched.

Here's an example of one such pagination call:


<!-- End Pagination -->


Expand Down
12 changes: 11 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ Based on:
### Generated
- [go v0.1.1] .
### Releases
- [Go v0.1.1] https://github.com/speakeasy-sdks/test-without-webhooks-go-sdk/releases/tag/v0.1.1 - .
- [Go v0.1.1] https://github.com/speakeasy-sdks/test-without-webhooks-go-sdk/releases/tag/v0.1.1 - .

## 2023-09-29 01:11:39
### Changes
Based on:
- OpenAPI Doc v1
- Speakeasy CLI 1.91.3 (2.139.1) https://github.com/speakeasy-api/speakeasy
### Generated
- [go v0.2.0] .
### Releases
- [Go v0.2.0] https://github.com/speakeasy-sdks/test-without-webhooks-go-sdk/releases/tag/v0.2.0 - .
6 changes: 3 additions & 3 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ func main() {

ctx := context.Background()
res, err := s.PostSendPet(ctx, shared.Pet1{
ID: 548814,
Name: "Kelvin Sporer",
Tag: testwithoutwebhooksgosdk.String("corrupti"),
ID: 794362,
Name: "Platinum",
Tag: testwithoutwebhooksgosdk.String("Fresh Washington Royce"),
})
if err != nil {
log.Fatal(err)
Expand Down
10 changes: 5 additions & 5 deletions docs/models/operations/postsendpetresponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

## Fields

| Field | Type | Required | Description |
| ------------------------------------------------------ | ------------------------------------------------------ | ------------------------------------------------------ | ------------------------------------------------------ |
| `ContentType` | *string* | :heavy_check_mark: | N/A |
| `StatusCode` | *int* | :heavy_check_mark: | N/A |
| `RawResponse` | [*http.Response](https://pkg.go.dev/net/http#Response) | :heavy_minus_sign: | N/A |
| 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 |
7 changes: 4 additions & 3 deletions docs/sdks/testwithoutwebhooks/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# TestWithoutWebhooks SDK


## Overview

### Available Operations
Expand All @@ -25,9 +26,9 @@ func main() {

ctx := context.Background()
res, err := s.TestWithoutWebhooks.PostSendPet(ctx, shared.Pet1{
ID: 891773,
Name: "Lucia Goldner",
Tag: testwithoutwebhooksgosdk.String("minus"),
ID: 794362,
Name: "Platinum",
Tag: testwithoutwebhooksgosdk.String("Fresh Washington Royce"),
})
if err != nil {
log.Fatal(err)
Expand Down
8 changes: 4 additions & 4 deletions gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ configVersion: 1.0.0
management:
docChecksum: 0f4dc7d494564b62ed0526ffebf7d3cd
docVersion: v1
speakeasyVersion: 1.89.0
generationVersion: 2.125.1
speakeasyVersion: 1.91.3
generationVersion: 2.139.1
generation:
comments:
disableComments: false
Expand All @@ -14,10 +14,10 @@ generation:
tagNamespacingDisabled: false
features:
go:
core: 2.88.4
core: 2.90.0
globalServerURLs: 2.82.0
go:
version: 0.1.1
version: 0.2.0
clientServerStatusCodesAsErrors: true
maxMethodParams: 0
packageName: github.com/speakeasy-sdks/test-without-webhooks-go-sdk
5 changes: 4 additions & 1 deletion pkg/models/operations/postsendpet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
)

type PostSendPetResponse 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
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/utils/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa
}

if v.Kind() == reflect.Ptr {
if v.IsNil() {
v.Set(reflect.New(typ))
}
v = v.Elem()
}

Expand Down Expand Up @@ -498,6 +501,9 @@ func unmarshalValue(value json.RawMessage, v reflect.Value, tag reflect.StructTa
}

if v.Kind() == reflect.Ptr {
if v.IsNil() {
v.Set(reflect.New(typ))
}
v = v.Elem()
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/requestbody.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func SerializeRequestBody(ctx context.Context, request interface{}, nullable, op
requestValType := reflect.ValueOf(request)

if isNil(requestStructType, requestValType) {
if optional || !nullable {
if !nullable && optional {
return nil, "", nil
}

Expand All @@ -54,11 +54,11 @@ func SerializeRequestBody(ctx context.Context, request interface{}, nullable, op
// request object (non-flattened)
requestVal := requestValType.FieldByName(requestFieldName)
if isNil(requestField.Type, requestVal) {
if optional || !nullable {
if !nullable && optional {
return nil, "", nil
}

return serializeContentType(requestFieldName, SerializationMethodToContentType[serializationMethod], requestVal, tag.MediaType)
return serializeContentType(requestFieldName, tag.MediaType, requestVal, string(requestField.Tag))
}

return serializeContentType(requestFieldName, tag.MediaType, requestVal, string(requestField.Tag))
Expand Down
114 changes: 63 additions & 51 deletions pkg/utils/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package utils

import (
"context"
"encoding/base64"
"fmt"
"net/http"
Expand All @@ -26,60 +27,86 @@ 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)
}

for k, v := range queryParams {
for _, z := range v {
queryParams.Add(k, z)
}
}

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 isNil(securityStructType, securityValType) {
return nil
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)
Expand All @@ -97,66 +124,51 @@ func parseSecurityStruct(c HTTPClient, security interface{}) *SecurityClient {
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 isNil(optionStructType, optionValType) {
return nil
}

if optionStructType.Kind() == reflect.Ptr {
optionStructType = optionStructType.Elem()
optionValType = optionValType.Elem()
}

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)
func parseSecurityScheme(client *securityConfig, schemeTag *securityTag, scheme interface{}) {
schemeVal := trueReflectValue(reflect.ValueOf(scheme))
schemeType := schemeVal.Type()

if isNil(schemeType, schemeVal) {
return
}

if schemeType.Kind() == reflect.Ptr {
schemeType = schemeType.Elem()
schemeVal = schemeVal.Elem()
}

if schemeType.Kind() == reflect.Struct {
if schemeTag.Type == "http" && schemeTag.SubType == "basic" {
parseBasicAuthScheme(client, schemeVal.Interface())
handleBasicAuthScheme(client, schemeVal.Interface())
return
}

Expand Down Expand Up @@ -184,7 +196,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 {
Expand Down Expand Up @@ -221,7 +233,7 @@ func prefixBearer(authHeaderValue string) string {
return fmt.Sprintf("Bearer %s", authHeaderValue)
}

func parseBasicAuthScheme(client *SecurityClient, scheme interface{}) {
func handleBasicAuthScheme(client *securityConfig, scheme interface{}) {
schemeStructType := reflect.TypeOf(scheme)
schemeValType := reflect.ValueOf(scheme)

Expand Down
Loading

0 comments on commit 9d818bf

Please sign in to comment.