Skip to content
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
113 changes: 56 additions & 57 deletions .speakeasy/gen.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ generation:
generateNewTests: true
skipResponseBodyAssertions: true
go:
version: 0.15.3
version: 0.15.4
additionalDependencies: {}
allowUnknownFieldsInWeakUnions: false
baseErrorName: GleanError
Expand Down
4 changes: 2 additions & 2 deletions .speakeasy/glean-merged-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ openapi: 3.1.0
info:
version: "0.9.0"
title: Glean API
x-source-commit-sha: 3e6bf297e8208a1324189f812c53bc04766b0213
x-open-api-commit-sha: 2419017440d6eea54a5cbdadbf6e265ebc3f3cb5
x-source-commit-sha: ae68c59fa1e1a61dfd7c494be7d2e118303de0f2
x-open-api-commit-sha: 26c5b4d7b8bb3519275c7b2353b0d3da933032f7
description: |
# Introduction
In addition to the data sources that Glean has built-in support for, Glean also provides a REST API that enables customers to put arbitrary content in the search index. This is useful, for example, for doing permissions-aware search over content in internal tools that reside on-prem as well as for searching over applications that Glean does not currently support first class. In addition these APIs allow the customer to push organization data (people info, organization structure etc) into Glean.
Expand Down
12 changes: 6 additions & 6 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
speakeasyVersion: 1.796.3
speakeasyVersion: 1.796.4
sources:
Glean API:
sourceNamespace: glean-api-specs
sourceRevisionDigest: sha256:0e14ee68a5a49a4890c842cfcded22f82b40f1afa4ae61f5c5accae7bdb50177
sourceBlobDigest: sha256:b357f61fbd8cbd644c4e2a50c5a7860c6e80b4bf4fa5d7cd1b4937ad66a4a3d0
sourceRevisionDigest: sha256:69565c16183739561291ea3ae128815c87b004e0f61e184b099efb1fe245b662
sourceBlobDigest: sha256:fea7a26be8ee1df4f4df9e877a2173a5f51a4bf90490fb3a9b8b28f4e604dbbb
tags:
- latest
petstore-oas:
Expand All @@ -17,10 +17,10 @@ targets:
glean:
source: Glean API
sourceNamespace: glean-api-specs
sourceRevisionDigest: sha256:0e14ee68a5a49a4890c842cfcded22f82b40f1afa4ae61f5c5accae7bdb50177
sourceBlobDigest: sha256:b357f61fbd8cbd644c4e2a50c5a7860c6e80b4bf4fa5d7cd1b4937ad66a4a3d0
sourceRevisionDigest: sha256:69565c16183739561291ea3ae128815c87b004e0f61e184b099efb1fe245b662
sourceBlobDigest: sha256:fea7a26be8ee1df4f4df9e877a2173a5f51a4bf90490fb3a9b8b28f4e604dbbb
codeSamplesNamespace: glean-api-specs-go-code-samples
codeSamplesRevisionDigest: sha256:56829881ff988b545eb375177e647bf8c766df84a97941ac8bc40dd73a99936e
codeSamplesRevisionDigest: sha256:6d999974f05e36f0ddc2e1963fa70d061b74b714851ccfe30aa3f3727410fde9
petstore:
source: petstore-oas
sourceNamespace: petstore-oas
Expand Down
12 changes: 11 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -888,4 +888,14 @@ Based on:
### Generated
- [go v0.15.3] .
### Releases
- [Go v0.15.3] https://github.com/gleanwork/api-client-go/releases/tag/v0.15.3 - .
- [Go v0.15.3] https://github.com/gleanwork/api-client-go/releases/tag/v0.15.3 - .

## 2026-09-04 02:36:16
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.796.4 (2.935.1) https://github.com/speakeasy-api/speakeasy
### Generated
- [go v0.15.4] .
### Releases
- [Go v0.15.4] https://github.com/gleanwork/api-client-go/releases/tag/v0.15.4 - .
12 changes: 10 additions & 2 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,17 @@ func (s *Chat) CreateStream(ctx context.Context, request operations.PlatformChat
timeout = s.sdkConfiguration.Timeout
}

var streamCancel context.CancelFunc

if timeout != nil {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, *timeout)
defer cancel()
streamCancel = cancel
defer func() {
if streamCancel != nil {
streamCancel()
}
}()
}

req, err := http.NewRequestWithContext(ctx, "POST", opURL, bodyReader)
Expand Down Expand Up @@ -488,7 +495,8 @@ func (s *Chat) CreateStream(ctx context.Context, request operations.PlatformChat
return components.PlatformChatStreamEventServerSentEvent{}, err
}
return e, nil
}, "")
}, "", stream.WithCancel[components.PlatformChatStreamEventServerSentEvent](streamCancel))
streamCancel = nil
res.PlatformChatStreamEventServerSentEvent = out
default:
rawBody, err := utils.ConsumeRawBody(httpRes)
Expand Down
11 changes: 10 additions & 1 deletion clientchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -2102,10 +2102,17 @@ func (s *ClientChat) RetrieveFile(ctx context.Context, fileID string, preview *b
timeout = s.sdkConfiguration.Timeout
}

var streamCancel context.CancelFunc

if timeout != nil {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, *timeout)
defer cancel()
streamCancel = cancel
defer func() {
if streamCancel != nil {
streamCancel()
}
}()
}

req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil)
Expand Down Expand Up @@ -2229,6 +2236,8 @@ func (s *ClientChat) RetrieveFile(ctx context.Context, fileID string, preview *b
case httpRes.StatusCode == 200:
switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/octet-stream`):
httpRes.Body = utils.BodyWithCancel(httpRes.Body, streamCancel)
streamCancel = nil
res.ResponseStream = httpRes.Body

return res, nil
Expand Down
13 changes: 12 additions & 1 deletion entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,17 @@ func (s *Entities) RetrievePersonPhoto(ctx context.Context, personID string, ds
timeout = s.sdkConfiguration.Timeout
}

var streamCancel context.CancelFunc

if timeout != nil {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, *timeout)
defer cancel()
streamCancel = cancel
defer func() {
if streamCancel != nil {
streamCancel()
}
}()
}

req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil)
Expand Down Expand Up @@ -668,10 +675,14 @@ func (s *Entities) RetrievePersonPhoto(ctx context.Context, personID string, ds

switch {
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `image/png`):
httpRes.Body = utils.BodyWithCancel(httpRes.Body, streamCancel)
streamCancel = nil
res.TwoHundredImagePngResponseStream = httpRes.Body

return res, nil
case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `image/jpeg`):
httpRes.Body = utils.BodyWithCancel(httpRes.Body, streamCancel)
streamCancel = nil
res.TwoHundredImageJpegResponseStream = httpRes.Body

return res, nil
Expand Down
11 changes: 7 additions & 4 deletions glean.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package apiclientgo

// Generated from OpenAPI doc version 0.9.0 and generator version 2.934.1
// Generated from OpenAPI doc version 0.9.0 and generator version 2.935.1

import (
"context"
Expand Down Expand Up @@ -161,10 +161,13 @@ func WithTimeout(timeout time.Duration) SDKOption {
// New creates a new instance of the SDK with the provided options
func New(opts ...SDKOption) *Glean {
sdk := &Glean{
SDKVersion: "0.15.3",
SDKVersion: "0.15.4",
sdkConfiguration: config.SDKConfiguration{
UserAgent: "speakeasy-sdk/go 0.15.3 2.934.1 0.9.0 github.com/gleanwork/api-client-go",
ServerList: ServerList,
UserAgent: "speakeasy-sdk/go 0.15.4 2.935.1 0.9.0 github.com/gleanwork/api-client-go",
SDKVersion: "0.15.4",
GenVersion: "2.935.1",
OpenAPIDocVersion: "0.9.0",
ServerList: ServerList,
ServerVariables: []map[string]string{
{
"instance": "instance-name",
Expand Down
21 changes: 12 additions & 9 deletions internal/config/sdkconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ type HTTPClient interface {
}

type SDKConfiguration struct {
Client HTTPClient
Security func(context.Context) (interface{}, error)
ServerURL string
ServerIndex int
ServerList []string
ServerVariables []map[string]string
UserAgent string
RetryConfig *retry.Config
Timeout *time.Duration
Client HTTPClient
Security func(context.Context) (interface{}, error)
ServerURL string
ServerIndex int
ServerList []string
ServerVariables []map[string]string
UserAgent string
SDKVersion string
GenVersion string
OpenAPIDocVersion string
RetryConfig *retry.Config
Timeout *time.Duration
}

func (c *SDKConfiguration) GetServerDetails() (string, map[string]string) {
Expand Down
36 changes: 29 additions & 7 deletions internal/utils/retries.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func Retry(ctx context.Context, r Retries, operation func() (*http.Response, err
err := retryWithBackoff(ctx, r.Config.Backoff, func() error {
if resp != nil {
resp.Body.Close()
resp = nil
}

select {
Expand Down Expand Up @@ -143,21 +144,31 @@ func Retry(ctx context.Context, r Retries, operation func() (*http.Response, err
return nil
})

var tempErr *retry.TemporaryError
if err != nil && !errors.As(err, &tempErr) {
return nil, err
}

return resp, nil
return retryResult(resp, err)
default:
return operation()
}
}

func retryResult(resp *http.Response, err error) (*http.Response, error) {
var tempErr *retry.TemporaryError
if err != nil && !errors.As(err, &tempErr) {
if resp != nil {
resp.Body.Close()
}
return nil, err
}

if resp == nil {
return nil, err
}

return resp, nil
}

func retryWithBackoff(ctx context.Context, s *retry.BackoffStrategy, operation func() error) error {
var (
err error
next time.Duration
attempt int
start = time.Now()
maxElapsedTime = time.Duration(s.MaxElapsedTime) * time.Millisecond
Expand All @@ -169,6 +180,7 @@ func retryWithBackoff(ctx context.Context, s *retry.BackoffStrategy, operation f
}()

for {
var next time.Duration
err = operation()
if err == nil {
return nil
Expand All @@ -179,13 +191,23 @@ func retryWithBackoff(ctx context.Context, s *retry.BackoffStrategy, operation f
return permanent.Unwrap()
}

if ctxErr := ctx.Err(); ctxErr != nil {
return ctxErr
}

if time.Since(start) >= maxElapsedTime {
return err
}

var temporary *retry.TemporaryError
hasRetryAfter := false
if errors.As(err, &temporary) {
next = temporary.RetryAfter()
hasRetryAfter = next > 0
}

if hasRetryAfter && next > maxElapsedTime-time.Since(start) {
return err
}

if next <= 0 {
Expand Down
34 changes: 34 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"time"
)

Expand Down Expand Up @@ -384,3 +385,36 @@ func ConsumeRawBody(res *http.Response) ([]byte, error) {

return rawBody, nil
}

type bodyWithCancel struct {
io.ReadCloser
cancel context.CancelFunc
once sync.Once
}

func (b *bodyWithCancel) Read(p []byte) (int, error) {
n, err := b.ReadCloser.Read(p)
if err != nil {
b.release()
}
return n, err
}

func (b *bodyWithCancel) Close() error {
err := b.ReadCloser.Close()
b.release()
return err
}

func (b *bodyWithCancel) release() {
b.once.Do(b.cancel)
}

// BodyWithCancel returns body wrapped so that cancel runs once reading ends or
// the body is closed. A nil cancel returns body unchanged.
func BodyWithCancel(body io.ReadCloser, cancel context.CancelFunc) io.ReadCloser {
if cancel == nil {
return body
}
return &bodyWithCancel{ReadCloser: body, cancel: cancel}
}
9 changes: 8 additions & 1 deletion models/components/customfieldvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ func CreateCustomFieldValueCustomFieldValuePerson(customFieldValuePerson CustomF
}
}

func (u *CustomFieldValue) UnmarshalJSON(data []byte) error {
func (u *CustomFieldValue) UnmarshalJSON(data []byte) (err error) {
previous := *u
*u = CustomFieldValue{}
defer func() {
if err != nil {
*u = previous
}
}()

var candidates []utils.UnionCandidate

Expand Down
9 changes: 8 additions & 1 deletion models/components/documentorerrorunion.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ func CreateDocumentOrErrorUnionDocumentOrError(documentOrError DocumentOrError)
}
}

func (u *DocumentOrErrorUnion) UnmarshalJSON(data []byte) error {
func (u *DocumentOrErrorUnion) UnmarshalJSON(data []byte) (err error) {
previous := *u
*u = DocumentOrErrorUnion{}
defer func() {
if err != nil {
*u = previous
}
}()

var candidates []utils.UnionCandidate

Expand Down
9 changes: 8 additions & 1 deletion models/components/documentspecunion.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,14 @@ func CreateDocumentSpecUnionDocumentSpec4(documentSpec4 DocumentSpec4) DocumentS
}
}

func (u *DocumentSpecUnion) UnmarshalJSON(data []byte) error {
func (u *DocumentSpecUnion) UnmarshalJSON(data []byte) (err error) {
previous := *u
*u = DocumentSpecUnion{}
defer func() {
if err != nil {
*u = previous
}
}()

var candidates []utils.UnionCandidate

Expand Down
9 changes: 8 additions & 1 deletion models/components/getshortcutrequestunion.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ func CreateGetShortcutRequestUnionGetShortcutRequest(getShortcutRequest GetShort
}
}

func (u *GetShortcutRequestUnion) UnmarshalJSON(data []byte) error {
func (u *GetShortcutRequestUnion) UnmarshalJSON(data []byte) (err error) {
previous := *u
*u = GetShortcutRequestUnion{}
defer func() {
if err != nil {
*u = previous
}
}()

var candidates []utils.UnionCandidate

Expand Down
Loading
Loading