diff --git a/api/api_backup.gen.go b/api/api_backup.gen.go index b7b4838..aa99ee9 100644 --- a/api/api_backup.gen.go +++ b/api/api_backup.gen.go @@ -12,7 +12,6 @@ package api import ( _context "context" - _io "io" _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" @@ -55,22 +54,6 @@ type BackupApi interface { GetBackupShardIdExecute(r ApiGetBackupShardIdRequest) (*_nethttp.Response, error) } -// backupApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type backupApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *backupApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *backupApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // BackupApiService BackupApi service type BackupApiService service diff --git a/api/api_bucket_schemas.gen.go b/api/api_bucket_schemas.gen.go index 3ab815b..2609917 100644 --- a/api/api_bucket_schemas.gen.go +++ b/api/api_bucket_schemas.gen.go @@ -12,7 +12,6 @@ package api import ( _context "context" - _io "io" _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" @@ -85,22 +84,6 @@ type BucketSchemasApi interface { UpdateMeasurementSchemaExecute(r ApiUpdateMeasurementSchemaRequest) (MeasurementSchema, error) } -// bucketSchemasApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type bucketSchemasApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *bucketSchemasApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *bucketSchemasApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // BucketSchemasApiService BucketSchemasApi service type BucketSchemasApiService service diff --git a/api/api_buckets.gen.go b/api/api_buckets.gen.go index d9be99f..1c652c2 100644 --- a/api/api_buckets.gen.go +++ b/api/api_buckets.gen.go @@ -12,7 +12,6 @@ package api import ( _context "context" - _io "io" _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" @@ -94,22 +93,6 @@ type BucketsApi interface { PostBucketsExecute(r ApiPostBucketsRequest) (Bucket, error) } -// bucketsApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type bucketsApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *bucketsApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *bucketsApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // BucketsApiService BucketsApi service type BucketsApiService service diff --git a/api/api_delete.gen.go b/api/api_delete.gen.go index b74795e..6acba33 100644 --- a/api/api_delete.gen.go +++ b/api/api_delete.gen.go @@ -12,7 +12,6 @@ package api import ( _context "context" - _io "io" _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" @@ -38,22 +37,6 @@ type DeleteApi interface { PostDeleteExecute(r ApiPostDeleteRequest) error } -// deleteApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type deleteApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *deleteApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *deleteApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // DeleteApiService DeleteApi service type DeleteApiService service diff --git a/api/api_health.gen.go b/api/api_health.gen.go index 778988e..cdd485f 100644 --- a/api/api_health.gen.go +++ b/api/api_health.gen.go @@ -12,7 +12,6 @@ package api import ( _context "context" - _io "io" _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" @@ -39,22 +38,6 @@ type HealthApi interface { GetHealthExecute(r ApiGetHealthRequest) (HealthCheck, error) } -// healthApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type healthApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *healthApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *healthApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // HealthApiService HealthApi service type HealthApiService service diff --git a/api/api_organizations.gen.go b/api/api_organizations.gen.go index b936107..69a44b7 100644 --- a/api/api_organizations.gen.go +++ b/api/api_organizations.gen.go @@ -12,7 +12,6 @@ package api import ( _context "context" - _io "io" _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" @@ -136,22 +135,6 @@ type OrganizationsApi interface { PostOrgsIDMembersExecute(r ApiPostOrgsIDMembersRequest) (ResourceMember, error) } -// organizationsApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type organizationsApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *organizationsApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *organizationsApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // OrganizationsApiService OrganizationsApi service type OrganizationsApiService service diff --git a/api/api_query.gen.go b/api/api_query.gen.go index 46e2c2f..575527f 100644 --- a/api/api_query.gen.go +++ b/api/api_query.gen.go @@ -12,7 +12,6 @@ package api import ( _context "context" - _io "io" _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" @@ -39,22 +38,6 @@ type QueryApi interface { PostQueryExecute(r ApiPostQueryRequest) (*_nethttp.Response, error) } -// queryApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type queryApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *queryApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *queryApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // QueryApiService QueryApi service type QueryApiService service diff --git a/api/api_restore.gen.go b/api/api_restore.gen.go index 63de194..a36e30f 100644 --- a/api/api_restore.gen.go +++ b/api/api_restore.gen.go @@ -16,7 +16,6 @@ import ( _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" - "os" "strings" ) @@ -79,22 +78,6 @@ type RestoreApi interface { PostRestoreShardIdExecute(r ApiPostRestoreShardIdRequest) error } -// restoreApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type restoreApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *restoreApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *restoreApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // RestoreApiService RestoreApi service type RestoreApiService service @@ -259,16 +242,16 @@ func (a *RestoreApiService) PostRestoreBucketMetadataIdExecute(r ApiPostRestoreB type ApiPostRestoreKVRequest struct { ctx _context.Context ApiService RestoreApi - body **os.File + body _io.ReadCloser zapTraceSpan *string contentEncoding *string } -func (r ApiPostRestoreKVRequest) Body(body *os.File) ApiPostRestoreKVRequest { - r.body = &body +func (r ApiPostRestoreKVRequest) Body(body _io.ReadCloser) ApiPostRestoreKVRequest { + r.body = body return r } -func (r ApiPostRestoreKVRequest) GetBody() **os.File { +func (r ApiPostRestoreKVRequest) GetBody() _io.ReadCloser { return r.body } @@ -396,16 +379,16 @@ func (a *RestoreApiService) PostRestoreKVExecute(r ApiPostRestoreKVRequest) erro type ApiPostRestoreSQLRequest struct { ctx _context.Context ApiService RestoreApi - body **os.File + body _io.ReadCloser zapTraceSpan *string contentEncoding *string } -func (r ApiPostRestoreSQLRequest) Body(body *os.File) ApiPostRestoreSQLRequest { - r.body = &body +func (r ApiPostRestoreSQLRequest) Body(body _io.ReadCloser) ApiPostRestoreSQLRequest { + r.body = body return r } -func (r ApiPostRestoreSQLRequest) GetBody() **os.File { +func (r ApiPostRestoreSQLRequest) GetBody() _io.ReadCloser { return r.body } @@ -534,7 +517,7 @@ type ApiPostRestoreShardIdRequest struct { ctx _context.Context ApiService RestoreApi shardID string - body **os.File + body _io.ReadCloser zapTraceSpan *string contentEncoding *string } @@ -547,11 +530,11 @@ func (r ApiPostRestoreShardIdRequest) GetShardID() string { return r.shardID } -func (r ApiPostRestoreShardIdRequest) Body(body *os.File) ApiPostRestoreShardIdRequest { - r.body = &body +func (r ApiPostRestoreShardIdRequest) Body(body _io.ReadCloser) ApiPostRestoreShardIdRequest { + r.body = body return r } -func (r ApiPostRestoreShardIdRequest) GetBody() **os.File { +func (r ApiPostRestoreShardIdRequest) GetBody() _io.ReadCloser { return r.body } diff --git a/api/api_setup.gen.go b/api/api_setup.gen.go index 1f0e43b..eb09226 100644 --- a/api/api_setup.gen.go +++ b/api/api_setup.gen.go @@ -12,7 +12,6 @@ package api import ( _context "context" - _io "io" _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" @@ -54,22 +53,6 @@ type SetupApi interface { PostSetupExecute(r ApiPostSetupRequest) (OnboardingResponse, error) } -// setupApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type setupApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *setupApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *setupApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // SetupApiService SetupApi service type SetupApiService service diff --git a/api/api_tasks.gen.go b/api/api_tasks.gen.go index 3ed9961..e016c7f 100644 --- a/api/api_tasks.gen.go +++ b/api/api_tasks.gen.go @@ -12,7 +12,6 @@ package api import ( _context "context" - _io "io" _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" @@ -198,22 +197,6 @@ type TasksApi interface { PostTasksIDRunsIDRetryExecute(r ApiPostTasksIDRunsIDRetryRequest) (Run, error) } -// tasksApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type tasksApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *tasksApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *tasksApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // TasksApiService TasksApi service type TasksApiService service diff --git a/api/api_users.gen.go b/api/api_users.gen.go index a3b966b..7d3b77e 100644 --- a/api/api_users.gen.go +++ b/api/api_users.gen.go @@ -12,7 +12,6 @@ package api import ( _context "context" - _io "io" _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" @@ -107,22 +106,6 @@ type UsersApi interface { PostUsersIDPasswordExecute(r ApiPostUsersIDPasswordRequest) error } -// usersApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type usersApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *usersApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *usersApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // UsersApiService UsersApi service type UsersApiService service diff --git a/api/api_write.gen.go b/api/api_write.gen.go index 24cf086..25e4cfb 100644 --- a/api/api_write.gen.go +++ b/api/api_write.gen.go @@ -12,7 +12,6 @@ package api import ( _context "context" - _io "io" _ioutil "io/ioutil" _nethttp "net/http" _neturl "net/url" @@ -38,22 +37,6 @@ type WriteApi interface { PostWriteExecute(r ApiPostWriteRequest) error } -// writeApiGzipReadCloser supports streaming gzip response-bodies directly from the server. -type writeApiGzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} - -func (gzrc *writeApiGzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *writeApiGzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // WriteApiService WriteApi service type WriteApiService service diff --git a/api/templates/README.md b/api/templates/README.md index 098facb..db1c6a4 100644 --- a/api/templates/README.md +++ b/api/templates/README.md @@ -14,10 +14,11 @@ multiple locations. `api.mustache` * Add `GetX()` methods for each request parameter `X`, for use in unit tests * Add checks for `isByteArray` to generate `[]byte` request fields instead of `*string` +* Add checks for `isBinary` to generate `io.ReadCloser` request fields instead of `**os.File` * Update creation of `GenericOpenAPIError` to track sub-error models by reference * Add checks for `isResponseBinary` to directly return the raw `*http.Response`, instead of pulling the entire body into memory and transforming it into an `*os.File` -* GUnzip response bodies before unmarshalling when `Content-Encoding: gzip` is set +* GUnzip non-binary response bodies before unmarshalling when `Content-Encoding: gzip` is set * Remove `*http.Response`s from the return values of generated operations `client.mustache` diff --git a/api/templates/api.mustache b/api/templates/api.mustache index b94a6dc..f4cd5d7 100644 --- a/api/templates/api.mustache +++ b/api/templates/api.mustache @@ -42,21 +42,6 @@ type {{classname}} interface { } {{/generateInterfaces}} -// {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}GzipReadCloser supports streaming gzip response-bodies directly from the server. -type {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}GzipReadCloser struct { - underlying _io.ReadCloser - gzip _io.ReadCloser -} -func (gzrc *{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}GzipReadCloser) Read(p []byte) (int, error) { - return gzrc.gzip.Read(p) -} -func (gzrc *{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}GzipReadCloser) Close() error { - if err := gzrc.gzip.Close(); err != nil { - return err - } - return gzrc.underlying.Close() -} - // {{classname}}Service {{classname}} service type {{classname}}Service service {{#operation}} @@ -68,15 +53,15 @@ type {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request s ApiService *{{classname}}Service {{/generateInterfaces}} {{#allParams}} - {{paramName}} {{#isByteArray}}[]byte{{/isByteArray}}{{^isByteArray}}{{^isPathParam}}*{{/isPathParam}}{{{dataType}}}{{/isByteArray}} + {{paramName}} {{#isByteArray}}[]byte{{/isByteArray}}{{#isBinary}}_io.ReadCloser{{/isBinary}}{{^isByteArray}}{{^isBinary}}{{^isPathParam}}*{{/isPathParam}}{{{dataType}}}{{/isBinary}}{{/isByteArray}} {{/allParams}} } {{#allParams}} -func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) {{vendorExtensions.x-export-param-name}}({{paramName}} {{#isByteArray}}[]byte{{/isByteArray}}{{^isByteArray}}{{{dataType}}}{{/isByteArray}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request { - r.{{paramName}} = {{^isByteArray}}{{^isPathParam}}&{{/isPathParam}}{{/isByteArray}}{{paramName}} +func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) {{vendorExtensions.x-export-param-name}}({{paramName}} {{#isByteArray}}[]byte{{/isByteArray}}{{#isBinary}}_io.ReadCloser{{/isBinary}}{{^isByteArray}}{{^isBinary}}{{{dataType}}}{{/isBinary}}{{/isByteArray}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request { + r.{{paramName}} = {{^isByteArray}}{{^isBinary}}{{^isPathParam}}&{{/isPathParam}}{{/isBinary}}{{/isByteArray}}{{paramName}} return r } -func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) Get{{vendorExtensions.x-export-param-name}}() {{#isByteArray}}[]byte{{/isByteArray}}{{^isByteArray}}{{^isPathParam}}*{{/isPathParam}}{{{dataType}}}{{/isByteArray}} { +func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) Get{{vendorExtensions.x-export-param-name}}() {{#isByteArray}}[]byte{{/isByteArray}}{{#isBinary}}_io.ReadCloser{{/isBinary}}{{^isByteArray}}{{^isBinary}}{{^isPathParam}}*{{/isPathParam}}{{{dataType}}}{{/isBinary}}{{/isByteArray}} { return r.{{paramName}} } @@ -350,11 +335,11 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class } if localVarHTTPResponse.StatusCode >= 300 { - body, err := GunzipIfNeeded(localVarHTTPResponse) - if err != nil { - body.Close() - return {{#returnType}}localVarReturnValue, {{/returnType}}err - } + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return {{#returnType}}localVarReturnValue, {{/returnType}}err + } localVarBody, err := _ioutil.ReadAll(body) body.Close() if err != nil { @@ -396,11 +381,11 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class localVarReturnValue = localVarHTTPResponse {{/isResponseBinary}} {{^isResponseBinary}} - body, err := GunzipIfNeeded(localVarHTTPResponse) - if err != nil { - body.Close() - return {{#returnType}}localVarReturnValue, {{/returnType}}err - } + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return {{#returnType}}localVarReturnValue, {{/returnType}}err + } localVarBody, err := _ioutil.ReadAll(body) body.Close() if err != nil {