From d7946a439fa1a28fdf9d71b22e451c15c68d3a76 Mon Sep 17 00:00:00 2001 From: dsinghvi Date: Thu, 12 Dec 2024 15:32:45 -0500 Subject: [PATCH] fix seed --- .../src/GeneratedSdkClientClassImpl.ts | 7 +- .../GeneratedDefaultEndpointImplementation.ts | 5 +- .../endpoint-response/getSuccessReturnType.ts | 9 +- .../GeneratedSdkEndpointTypeSchemasImpl.ts | 6 +- .../no-undefined-type-reference.ts | 3 +- .../bytes/.mock/definition/service.yml | 6 + seed/csharp-model/bytes/src/SeedBytes.sln | 20 +-- .../bytes/.mock/definition/service.yml | 6 + seed/csharp-sdk/bytes/src/SeedBytes.sln | 20 +-- .../src/SeedBytes/Service/ServiceClient.cs | 23 +++ .../bytes/.mock/definition/service.yml | 6 + .../bytes/.mock/definition/service.yml | 6 + .../go-sdk/bytes/.mock/definition/service.yml | 6 + seed/go-sdk/bytes/service/client.go | 36 +++++ .../bytes/.mock/definition/service.yml | 6 + .../bytes/.mock/definition/service.yml | 6 + .../resources/service/ServiceClient.java | 36 +++++ .../bytes/.mock/definition/service.yml | 6 + .../bytes/.mock/definition/service.yml | 6 + .../bytes/.mock/definition/service.yml | 6 + .../bytes/src/Service/ServiceClient.php | 28 ++++ .../bytes/.mock/definition/service.yml | 6 + .../bytes/.mock/definition/service.yml | 6 + .../bytes/.mock/definition/service.yml | 6 + seed/python-sdk/bytes/snippet-templates.json | 56 ++++++++ .../bytes/src/seed/service/client.py | 56 ++++++++ .../bytes/.mock/definition/service.yml | 6 + .../bytes/.mock/definition/service.yml | 6 + seed/ruby-sdk/bytes/fern_bytes.gemspec | 4 - seed/ruby-sdk/bytes/lib/fern_bytes.rb | 42 ------ .../bytes/lib/fern_bytes/service/client.rb | 70 ---------- seed/ruby-sdk/bytes/lib/requests.rb | 132 ------------------ seed/ruby-sdk/bytes/lib/types_export.rb | 1 - seed/ruby-sdk/bytes/snippet.json | 4 - .../api/resources/service/client/Client.ts | 4 +- 35 files changed, 361 insertions(+), 291 deletions(-) delete mode 100644 seed/ruby-sdk/bytes/lib/fern_bytes/service/client.rb delete mode 100644 seed/ruby-sdk/bytes/lib/requests.rb delete mode 100644 seed/ruby-sdk/bytes/lib/types_export.rb diff --git a/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts b/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts index 9e646da53f1..6b8e24aeb1a 100644 --- a/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts +++ b/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts @@ -238,7 +238,12 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass { const getDefaultEndpointImplementation = ({ response }: { - response: HttpResponseBody.Json | HttpResponseBody.FileDownload | HttpResponseBody.Text | HttpResponseBody.Bytes | undefined; + response: + | HttpResponseBody.Json + | HttpResponseBody.FileDownload + | HttpResponseBody.Text + | HttpResponseBody.Bytes + | undefined; }) => { return new GeneratedDefaultEndpointImplementation({ endpoint, diff --git a/generators/typescript/sdk/client-class-generator/src/endpoints/default/GeneratedDefaultEndpointImplementation.ts b/generators/typescript/sdk/client-class-generator/src/endpoints/default/GeneratedDefaultEndpointImplementation.ts index 8dbb5ad9ca4..fe3272d907f 100644 --- a/generators/typescript/sdk/client-class-generator/src/endpoints/default/GeneratedDefaultEndpointImplementation.ts +++ b/generators/typescript/sdk/client-class-generator/src/endpoints/default/GeneratedDefaultEndpointImplementation.ts @@ -425,12 +425,15 @@ export class GeneratedDefaultEndpointImplementation implements GeneratedEndpoint withCredentials: this.includeCredentialsOnCrossOriginRequests }; + let cast: ts.TypeNode | undefined = undefined; + if (this.endpoint.response?.body?.type === "text") { fetcherArgs.responseType = "text"; } if (this.endpoint.response?.body?.type === "bytes") { fetcherArgs.responseType = "arrayBuffer"; + cast = ts.factory.createTypeReferenceNode("ArrayBuffer"); } return [ @@ -444,7 +447,7 @@ export class GeneratedDefaultEndpointImplementation implements GeneratedEndpoint undefined, context.coreUtilities.fetcher.fetcher._invoke(fetcherArgs, { referenceToFetcher: this.generatedSdkClientClass.getReferenceToFetcher(context), - cast: undefined + cast }) ) ], diff --git a/generators/typescript/sdk/client-class-generator/src/endpoints/default/endpoint-response/getSuccessReturnType.ts b/generators/typescript/sdk/client-class-generator/src/endpoints/default/endpoint-response/getSuccessReturnType.ts index 197ba384be7..4c700d991bb 100644 --- a/generators/typescript/sdk/client-class-generator/src/endpoints/default/endpoint-response/getSuccessReturnType.ts +++ b/generators/typescript/sdk/client-class-generator/src/endpoints/default/endpoint-response/getSuccessReturnType.ts @@ -28,14 +28,7 @@ export function getSuccessReturnType( includeContentHeadersOnResponse: opts.includeContentHeadersOnResponse }); } - case "fileDownload": { - return getFileType({ - targetRuntime: context.targetRuntime, - context, - includeContentHeadersOnResponse: opts.includeContentHeadersOnResponse - }); - } - case "bytes": + case "bytes": return ts.factory.createTypeReferenceNode("ArrayBuffer"); case "json": return context.type.getReferenceToType(response.value.responseBodyType).typeNode; diff --git a/generators/typescript/sdk/sdk-endpoint-type-schemas-generator/src/GeneratedSdkEndpointTypeSchemasImpl.ts b/generators/typescript/sdk/sdk-endpoint-type-schemas-generator/src/GeneratedSdkEndpointTypeSchemasImpl.ts index 3d01606b898..3d52573f37f 100644 --- a/generators/typescript/sdk/sdk-endpoint-type-schemas-generator/src/GeneratedSdkEndpointTypeSchemasImpl.ts +++ b/generators/typescript/sdk/sdk-endpoint-type-schemas-generator/src/GeneratedSdkEndpointTypeSchemasImpl.ts @@ -272,11 +272,7 @@ export class GeneratedSdkEndpointTypeSchemasImpl implements GeneratedSdkEndpoint } if (this.endpoint.response.body.type === "bytes") { - return ts.factory.createAsExpression( - referenceToRawResponse, - context.type.getReferenceToType(TypeReference.primitive({ v1: PrimitiveTypeV1.String, v2: undefined })) - .typeNode - ); + return referenceToRawResponse; } if (this.endpoint.response.body.value.responseBodyType.type === "unknown") { diff --git a/packages/cli/fern-definition/validator/src/rules/no-undefined-type-reference/no-undefined-type-reference.ts b/packages/cli/fern-definition/validator/src/rules/no-undefined-type-reference/no-undefined-type-reference.ts index 996e3ee763e..25ac5d49186 100644 --- a/packages/cli/fern-definition/validator/src/rules/no-undefined-type-reference/no-undefined-type-reference.ts +++ b/packages/cli/fern-definition/validator/src/rules/no-undefined-type-reference/no-undefined-type-reference.ts @@ -83,7 +83,8 @@ export const NoUndefinedTypeReferenceRule: Rule = { if (parsedBytesType != null) { if (location === TypeReferenceLocation.RequestReference) { return []; - } if (location === TypeReferenceLocation.Response) { + } + if (location === TypeReferenceLocation.Response) { return []; } else { return [ diff --git a/seed/csharp-model/bytes/.mock/definition/service.yml b/seed/csharp-model/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/csharp-model/bytes/.mock/definition/service.yml +++ b/seed/csharp-model/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/csharp-model/bytes/src/SeedBytes.sln b/seed/csharp-model/bytes/src/SeedBytes.sln index d2eb699bd5f..d129e24cacd 100644 --- a/seed/csharp-model/bytes/src/SeedBytes.sln +++ b/seed/csharp-model/bytes/src/SeedBytes.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeedBytes", "SeedBytes\SeedBytes.csproj", "{EDDE2A4C-13F0-4134-9038-CDAF0053119C}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeedBytes", "SeedBytes\SeedBytes.csproj", "{2FCEDF32-0F43-4F18-AC12-4116453C32BB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeedBytes.Test", "SeedBytes.Test\SeedBytes.Test.csproj", "{5A8073BD-0677-4BFE-B70A-C5EE6EE35910}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeedBytes.Test", "SeedBytes.Test\SeedBytes.Test.csproj", "{D1FFA8EC-1A36-4378-B6D4-0517E56BAC47}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -16,13 +16,13 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {EDDE2A4C-13F0-4134-9038-CDAF0053119C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EDDE2A4C-13F0-4134-9038-CDAF0053119C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EDDE2A4C-13F0-4134-9038-CDAF0053119C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EDDE2A4C-13F0-4134-9038-CDAF0053119C}.Release|Any CPU.Build.0 = Release|Any CPU - {5A8073BD-0677-4BFE-B70A-C5EE6EE35910}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5A8073BD-0677-4BFE-B70A-C5EE6EE35910}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5A8073BD-0677-4BFE-B70A-C5EE6EE35910}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5A8073BD-0677-4BFE-B70A-C5EE6EE35910}.Release|Any CPU.Build.0 = Release|Any CPU + {2FCEDF32-0F43-4F18-AC12-4116453C32BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2FCEDF32-0F43-4F18-AC12-4116453C32BB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2FCEDF32-0F43-4F18-AC12-4116453C32BB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2FCEDF32-0F43-4F18-AC12-4116453C32BB}.Release|Any CPU.Build.0 = Release|Any CPU + {D1FFA8EC-1A36-4378-B6D4-0517E56BAC47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D1FFA8EC-1A36-4378-B6D4-0517E56BAC47}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D1FFA8EC-1A36-4378-B6D4-0517E56BAC47}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D1FFA8EC-1A36-4378-B6D4-0517E56BAC47}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/seed/csharp-sdk/bytes/.mock/definition/service.yml b/seed/csharp-sdk/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/csharp-sdk/bytes/.mock/definition/service.yml +++ b/seed/csharp-sdk/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/csharp-sdk/bytes/src/SeedBytes.sln b/seed/csharp-sdk/bytes/src/SeedBytes.sln index 0845a83f4e3..b75e0506e3a 100644 --- a/seed/csharp-sdk/bytes/src/SeedBytes.sln +++ b/seed/csharp-sdk/bytes/src/SeedBytes.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeedBytes", "SeedBytes\SeedBytes.csproj", "{8E696D7E-E314-4826-90C2-C9D1FCDCE3EA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeedBytes", "SeedBytes\SeedBytes.csproj", "{BEC5C944-1909-4ECF-BE24-09F90C3A4F5A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeedBytes.Test", "SeedBytes.Test\SeedBytes.Test.csproj", "{67861B6A-2F08-4CD8-B710-F0FD02091AAC}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeedBytes.Test", "SeedBytes.Test\SeedBytes.Test.csproj", "{B3CC741B-6998-484E-A8EC-436A74028230}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -16,13 +16,13 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8E696D7E-E314-4826-90C2-C9D1FCDCE3EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8E696D7E-E314-4826-90C2-C9D1FCDCE3EA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8E696D7E-E314-4826-90C2-C9D1FCDCE3EA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8E696D7E-E314-4826-90C2-C9D1FCDCE3EA}.Release|Any CPU.Build.0 = Release|Any CPU - {67861B6A-2F08-4CD8-B710-F0FD02091AAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {67861B6A-2F08-4CD8-B710-F0FD02091AAC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {67861B6A-2F08-4CD8-B710-F0FD02091AAC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {67861B6A-2F08-4CD8-B710-F0FD02091AAC}.Release|Any CPU.Build.0 = Release|Any CPU + {BEC5C944-1909-4ECF-BE24-09F90C3A4F5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BEC5C944-1909-4ECF-BE24-09F90C3A4F5A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BEC5C944-1909-4ECF-BE24-09F90C3A4F5A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BEC5C944-1909-4ECF-BE24-09F90C3A4F5A}.Release|Any CPU.Build.0 = Release|Any CPU + {B3CC741B-6998-484E-A8EC-436A74028230}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B3CC741B-6998-484E-A8EC-436A74028230}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B3CC741B-6998-484E-A8EC-436A74028230}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B3CC741B-6998-484E-A8EC-436A74028230}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/seed/csharp-sdk/bytes/src/SeedBytes/Service/ServiceClient.cs b/seed/csharp-sdk/bytes/src/SeedBytes/Service/ServiceClient.cs index 505763493d9..348f3e4a422 100644 --- a/seed/csharp-sdk/bytes/src/SeedBytes/Service/ServiceClient.cs +++ b/seed/csharp-sdk/bytes/src/SeedBytes/Service/ServiceClient.cs @@ -45,4 +45,27 @@ public async Task UploadAsync( responseBody ); } + + public async Task DownloadAsync( + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var response = await _client.MakeRequestAsync( + new RawClient.JsonApiRequest + { + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethod.Get, + Path = "download-content", + Options = options, + }, + cancellationToken + ); + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new SeedBytesApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody + ); + } } diff --git a/seed/go-fiber/bytes/.mock/definition/service.yml b/seed/go-fiber/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/go-fiber/bytes/.mock/definition/service.yml +++ b/seed/go-fiber/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/go-model/bytes/.mock/definition/service.yml b/seed/go-model/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/go-model/bytes/.mock/definition/service.yml +++ b/seed/go-model/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/go-sdk/bytes/.mock/definition/service.yml b/seed/go-sdk/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/go-sdk/bytes/.mock/definition/service.yml +++ b/seed/go-sdk/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/go-sdk/bytes/service/client.go b/seed/go-sdk/bytes/service/client.go index 05336ab7e0e..bb87012af06 100644 --- a/seed/go-sdk/bytes/service/client.go +++ b/seed/go-sdk/bytes/service/client.go @@ -8,6 +8,7 @@ import ( core "github.com/bytes/fern/core" internal "github.com/bytes/fern/internal" option "github.com/bytes/fern/option" + io "io" http "net/http" ) @@ -67,3 +68,38 @@ func (c *Client) Upload( } return nil } + +func (c *Client) Download( + ctx context.Context, + opts ...option.RequestOption, +) (io.Reader, error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "", + ) + endpointURL := baseURL + "/download-content" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + + response := bytes.NewBuffer(nil) + if err := c.caller.Call( + ctx, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodGet, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: response, + }, + ); err != nil { + return nil, err + } + return response, nil +} diff --git a/seed/java-model/bytes/.mock/definition/service.yml b/seed/java-model/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/java-model/bytes/.mock/definition/service.yml +++ b/seed/java-model/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/java-sdk/bytes/.mock/definition/service.yml b/seed/java-sdk/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/java-sdk/bytes/.mock/definition/service.yml +++ b/seed/java-sdk/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/java-sdk/bytes/src/main/java/com/seed/bytes/resources/service/ServiceClient.java b/seed/java-sdk/bytes/src/main/java/com/seed/bytes/resources/service/ServiceClient.java index 54b342c6d1f..9a83c5cc179 100644 --- a/seed/java-sdk/bytes/src/main/java/com/seed/bytes/resources/service/ServiceClient.java +++ b/seed/java-sdk/bytes/src/main/java/com/seed/bytes/resources/service/ServiceClient.java @@ -7,6 +7,7 @@ import com.seed.bytes.core.InputStreamRequestBody; import com.seed.bytes.core.ObjectMappers; import com.seed.bytes.core.RequestOptions; +import com.seed.bytes.core.ResponseBodyInputStream; import com.seed.bytes.core.SeedBytesApiException; import com.seed.bytes.core.SeedBytesException; import java.io.ByteArrayInputStream; @@ -69,4 +70,39 @@ public void upload(byte[] request) { public void upload(byte[] request, RequestOptions requestOptions) { upload(new ByteArrayInputStream(request), requestOptions); } + + public InputStream download() { + return download(null); + } + + public InputStream download(RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("download-content") + .build(); + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("GET", null) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Content-Type", "application/json") + .build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + try { + Response response = client.newCall(okhttpRequest).execute(); + ResponseBody responseBody = response.body(); + if (response.isSuccessful()) { + return new ResponseBodyInputStream(response); + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + throw new SeedBytesApiException( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + } catch (IOException e) { + throw new SeedBytesException("Network error executing HTTP request", e); + } + } } diff --git a/seed/openapi/bytes/.mock/definition/service.yml b/seed/openapi/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/openapi/bytes/.mock/definition/service.yml +++ b/seed/openapi/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/php-model/bytes/.mock/definition/service.yml b/seed/php-model/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/php-model/bytes/.mock/definition/service.yml +++ b/seed/php-model/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/php-sdk/bytes/.mock/definition/service.yml b/seed/php-sdk/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/php-sdk/bytes/.mock/definition/service.yml +++ b/seed/php-sdk/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/php-sdk/bytes/src/Service/ServiceClient.php b/seed/php-sdk/bytes/src/Service/ServiceClient.php index b2955d0e9e2..a424297b6a3 100644 --- a/seed/php-sdk/bytes/src/Service/ServiceClient.php +++ b/seed/php-sdk/bytes/src/Service/ServiceClient.php @@ -55,4 +55,32 @@ public function upload(?array $options = null): void body: $response->getBody()->getContents(), ); } + + /** + * @param ?array{ + * baseUrl?: string, + * } $options + * @throws SeedException + * @throws SeedApiException + */ + public function download(?array $options = null): void + { + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? '', + path: "download-content", + method: HttpMethod::GET, + ), + ); + $statusCode = $response->getStatusCode(); + } catch (ClientExceptionInterface $e) { + throw new SeedException(message: $e->getMessage(), previous: $e); + } + throw new SeedApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } } diff --git a/seed/postman/bytes/.mock/definition/service.yml b/seed/postman/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/postman/bytes/.mock/definition/service.yml +++ b/seed/postman/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/pydantic/bytes/.mock/definition/service.yml b/seed/pydantic/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/pydantic/bytes/.mock/definition/service.yml +++ b/seed/pydantic/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/python-sdk/bytes/.mock/definition/service.yml b/seed/python-sdk/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/python-sdk/bytes/.mock/definition/service.yml +++ b/seed/python-sdk/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/python-sdk/bytes/snippet-templates.json b/seed/python-sdk/bytes/snippet-templates.json index 19cecfea4d9..b38475df070 100644 --- a/seed/python-sdk/bytes/snippet-templates.json +++ b/seed/python-sdk/bytes/snippet-templates.json @@ -88,5 +88,61 @@ "type": "v1" } } + }, + { + "sdk": { + "package": "fern_bytes", + "version": "0.0.1", + "type": "python" + }, + "endpointId": { + "path": "/download-content", + "method": "GET", + "identifierOverride": "endpoint_service.download" + }, + "snippetTemplate": { + "clientInstantiation": { + "imports": [ + "from seed import SeedBytes" + ], + "isOptional": true, + "templateString": "client = SeedBytes(base_url=\"https://yourhost.com/path/to/api\", )", + "templateInputs": [], + "inputDelimiter": ",", + "type": "generic" + }, + "functionInvocation": { + "imports": [], + "isOptional": true, + "templateString": "client.service.download(\n\t$FERN_INPUT\n)", + "templateInputs": [], + "inputDelimiter": ",\n\t", + "type": "generic" + }, + "type": "v1" + }, + "additionalTemplates": { + "async": { + "clientInstantiation": { + "imports": [ + "from seed import AsyncSeedBytes" + ], + "isOptional": true, + "templateString": "client = AsyncSeedBytes(base_url=\"https://yourhost.com/path/to/api\", )", + "templateInputs": [], + "inputDelimiter": ",", + "type": "generic" + }, + "functionInvocation": { + "imports": [], + "isOptional": true, + "templateString": "await client.service.download(\n\t$FERN_INPUT\n)", + "templateInputs": [], + "inputDelimiter": ",\n\t", + "type": "generic" + }, + "type": "v1" + } + } } ] \ No newline at end of file diff --git a/seed/python-sdk/bytes/src/seed/service/client.py b/seed/python-sdk/bytes/src/seed/service/client.py index 0a29c114dde..5a8db133002 100644 --- a/seed/python-sdk/bytes/src/seed/service/client.py +++ b/seed/python-sdk/bytes/src/seed/service/client.py @@ -48,6 +48,34 @@ def upload( raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + def download(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Iterator[bytes]: + """ + Parameters + ---------- + request_options : typing.Optional[RequestOptions] + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. + + Yields + ------ + typing.Iterator[bytes] + """ + with self._client_wrapper.httpx_client.stream( + "download-content", + method="GET", + request_options=request_options, + ) as _response: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + for _chunk in _response.iter_bytes(chunk_size=_chunk_size): + yield _chunk + return + _response.read() + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + class AsyncServiceClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): @@ -85,3 +113,31 @@ async def upload( except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + + async def download(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.AsyncIterator[bytes]: + """ + Parameters + ---------- + request_options : typing.Optional[RequestOptions] + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. + + Yields + ------ + typing.AsyncIterator[bytes] + """ + async with self._client_wrapper.httpx_client.stream( + "download-content", + method="GET", + request_options=request_options, + ) as _response: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size): + yield _chunk + return + await _response.aread() + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) diff --git a/seed/ruby-model/bytes/.mock/definition/service.yml b/seed/ruby-model/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/ruby-model/bytes/.mock/definition/service.yml +++ b/seed/ruby-model/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/ruby-sdk/bytes/.mock/definition/service.yml b/seed/ruby-sdk/bytes/.mock/definition/service.yml index b0610fa616c..711358d8f3a 100644 --- a/seed/ruby-sdk/bytes/.mock/definition/service.yml +++ b/seed/ruby-sdk/bytes/.mock/definition/service.yml @@ -8,3 +8,9 @@ service: request: content-type: "application/octet-stream" body: bytes + + download: + path: /download-content + method: GET + response: + type: bytes \ No newline at end of file diff --git a/seed/ruby-sdk/bytes/fern_bytes.gemspec b/seed/ruby-sdk/bytes/fern_bytes.gemspec index 15e031f3696..2c5d793db9d 100644 --- a/seed/ruby-sdk/bytes/fern_bytes.gemspec +++ b/seed/ruby-sdk/bytes/fern_bytes.gemspec @@ -18,8 +18,4 @@ Gem::Specification.new do |spec| spec.bindir = "exe" spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency "async-http-faraday", ">= 0.0", "< 1.0" - spec.add_dependency "faraday", ">= 1.10", "< 3.0" - spec.add_dependency "faraday-net_http", ">= 1.0", "< 4.0" - spec.add_dependency "faraday-retry", ">= 1.0", "< 3.0" end diff --git a/seed/ruby-sdk/bytes/lib/fern_bytes.rb b/seed/ruby-sdk/bytes/lib/fern_bytes.rb index c859fd06100..8e9b8f90fa4 100644 --- a/seed/ruby-sdk/bytes/lib/fern_bytes.rb +++ b/seed/ruby-sdk/bytes/lib/fern_bytes.rb @@ -1,43 +1 @@ # frozen_string_literal: true - -require_relative "types_export" -require_relative "requests" -require_relative "fern_bytes/service/client" - -module SeedBytesClient - class Client - # @return [SeedBytesClient::ServiceClient] - attr_reader :service - - # @param base_url [String] - # @param max_retries [Long] The number of times to retry a failed request, defaults to 2. - # @param timeout_in_seconds [Long] - # @return [SeedBytesClient::Client] - def initialize(base_url: nil, max_retries: nil, timeout_in_seconds: nil) - @request_client = SeedBytesClient::RequestClient.new( - base_url: base_url, - max_retries: max_retries, - timeout_in_seconds: timeout_in_seconds - ) - @service = SeedBytesClient::ServiceClient.new(request_client: @request_client) - end - end - - class AsyncClient - # @return [SeedBytesClient::AsyncServiceClient] - attr_reader :service - - # @param base_url [String] - # @param max_retries [Long] The number of times to retry a failed request, defaults to 2. - # @param timeout_in_seconds [Long] - # @return [SeedBytesClient::AsyncClient] - def initialize(base_url: nil, max_retries: nil, timeout_in_seconds: nil) - @async_request_client = SeedBytesClient::AsyncRequestClient.new( - base_url: base_url, - max_retries: max_retries, - timeout_in_seconds: timeout_in_seconds - ) - @service = SeedBytesClient::AsyncServiceClient.new(request_client: @async_request_client) - end - end -end diff --git a/seed/ruby-sdk/bytes/lib/fern_bytes/service/client.rb b/seed/ruby-sdk/bytes/lib/fern_bytes/service/client.rb deleted file mode 100644 index d01a4ba9f01..00000000000 --- a/seed/ruby-sdk/bytes/lib/fern_bytes/service/client.rb +++ /dev/null @@ -1,70 +0,0 @@ -# frozen_string_literal: true - -require_relative "../../requests" -require "async" - -module SeedBytesClient - class ServiceClient - # @return [SeedBytesClient::RequestClient] - attr_reader :request_client - - # @param request_client [SeedBytesClient::RequestClient] - # @return [SeedBytesClient::ServiceClient] - def initialize(request_client:) - @request_client = request_client - end - - # @param request [String, IO] Base64 encoded bytes, or an IO object (e.g. Faraday::UploadIO, etc.) - # @param request_options [SeedBytesClient::RequestOptions] - # @return [Void] - def upload(request:, request_options: nil) - @request_client.conn.post do |req| - req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil? - req.headers = { - **(req.headers || {}), - **@request_client.get_headers, - **(request_options&.additional_headers || {}) - }.compact - unless request_options.nil? || request_options&.additional_query_parameters.nil? - req.params = { **(request_options&.additional_query_parameters || {}) }.compact - end - req.headers["Content-Type"] = "application/octet-stream" - req.body = request - req.url "#{@request_client.get_url(request_options: request_options)}/upload-content" - end - end - end - - class AsyncServiceClient - # @return [SeedBytesClient::AsyncRequestClient] - attr_reader :request_client - - # @param request_client [SeedBytesClient::AsyncRequestClient] - # @return [SeedBytesClient::AsyncServiceClient] - def initialize(request_client:) - @request_client = request_client - end - - # @param request [String, IO] Base64 encoded bytes, or an IO object (e.g. Faraday::UploadIO, etc.) - # @param request_options [SeedBytesClient::RequestOptions] - # @return [Void] - def upload(request:, request_options: nil) - Async do - @request_client.conn.post do |req| - req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil? - req.headers = { - **(req.headers || {}), - **@request_client.get_headers, - **(request_options&.additional_headers || {}) - }.compact - unless request_options.nil? || request_options&.additional_query_parameters.nil? - req.params = { **(request_options&.additional_query_parameters || {}) }.compact - end - req.headers["Content-Type"] = "application/octet-stream" - req.body = request - req.url "#{@request_client.get_url(request_options: request_options)}/upload-content" - end - end - end - end -end diff --git a/seed/ruby-sdk/bytes/lib/requests.rb b/seed/ruby-sdk/bytes/lib/requests.rb deleted file mode 100644 index cd79d2a2e9d..00000000000 --- a/seed/ruby-sdk/bytes/lib/requests.rb +++ /dev/null @@ -1,132 +0,0 @@ -# frozen_string_literal: true - -require "faraday" -require "faraday/retry" -require "async/http/faraday" - -module SeedBytesClient - class RequestClient - # @return [Faraday] - attr_reader :conn - # @return [String] - attr_reader :base_url - - # @param base_url [String] - # @param max_retries [Long] The number of times to retry a failed request, defaults to 2. - # @param timeout_in_seconds [Long] - # @return [SeedBytesClient::RequestClient] - def initialize(base_url: nil, max_retries: nil, timeout_in_seconds: nil) - @base_url = base_url - @conn = Faraday.new do |faraday| - faraday.request :json - faraday.response :raise_error, include_request: true - faraday.request :retry, { max: max_retries } unless max_retries.nil? - faraday.options.timeout = timeout_in_seconds unless timeout_in_seconds.nil? - end - end - - # @param request_options [SeedBytesClient::RequestOptions] - # @return [String] - def get_url(request_options: nil) - request_options&.base_url || @base_url - end - - # @return [Hash{String => String}] - def get_headers - { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "fern_bytes", "X-Fern-SDK-Version": "0.0.1" } - end - end - - class AsyncRequestClient - # @return [Faraday] - attr_reader :conn - # @return [String] - attr_reader :base_url - - # @param base_url [String] - # @param max_retries [Long] The number of times to retry a failed request, defaults to 2. - # @param timeout_in_seconds [Long] - # @return [SeedBytesClient::AsyncRequestClient] - def initialize(base_url: nil, max_retries: nil, timeout_in_seconds: nil) - @base_url = base_url - @conn = Faraday.new do |faraday| - faraday.request :json - faraday.response :raise_error, include_request: true - faraday.adapter :async_http - faraday.request :retry, { max: max_retries } unless max_retries.nil? - faraday.options.timeout = timeout_in_seconds unless timeout_in_seconds.nil? - end - end - - # @param request_options [SeedBytesClient::RequestOptions] - # @return [String] - def get_url(request_options: nil) - request_options&.base_url || @base_url - end - - # @return [Hash{String => String}] - def get_headers - { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "fern_bytes", "X-Fern-SDK-Version": "0.0.1" } - end - end - - # Additional options for request-specific configuration when calling APIs via the - # SDK. - class RequestOptions - # @return [String] - attr_reader :base_url - # @return [Hash{String => Object}] - attr_reader :additional_headers - # @return [Hash{String => Object}] - attr_reader :additional_query_parameters - # @return [Hash{String => Object}] - attr_reader :additional_body_parameters - # @return [Long] - attr_reader :timeout_in_seconds - - # @param base_url [String] - # @param additional_headers [Hash{String => Object}] - # @param additional_query_parameters [Hash{String => Object}] - # @param additional_body_parameters [Hash{String => Object}] - # @param timeout_in_seconds [Long] - # @return [SeedBytesClient::RequestOptions] - def initialize(base_url: nil, additional_headers: nil, additional_query_parameters: nil, - additional_body_parameters: nil, timeout_in_seconds: nil) - @base_url = base_url - @additional_headers = additional_headers - @additional_query_parameters = additional_query_parameters - @additional_body_parameters = additional_body_parameters - @timeout_in_seconds = timeout_in_seconds - end - end - - # Additional options for request-specific configuration when calling APIs via the - # SDK. - class IdempotencyRequestOptions - # @return [String] - attr_reader :base_url - # @return [Hash{String => Object}] - attr_reader :additional_headers - # @return [Hash{String => Object}] - attr_reader :additional_query_parameters - # @return [Hash{String => Object}] - attr_reader :additional_body_parameters - # @return [Long] - attr_reader :timeout_in_seconds - - # @param base_url [String] - # @param additional_headers [Hash{String => Object}] - # @param additional_query_parameters [Hash{String => Object}] - # @param additional_body_parameters [Hash{String => Object}] - # @param timeout_in_seconds [Long] - # @return [SeedBytesClient::IdempotencyRequestOptions] - def initialize(base_url: nil, additional_headers: nil, additional_query_parameters: nil, - additional_body_parameters: nil, timeout_in_seconds: nil) - @base_url = base_url - @additional_headers = additional_headers - @additional_query_parameters = additional_query_parameters - @additional_body_parameters = additional_body_parameters - @timeout_in_seconds = timeout_in_seconds - end - end -end diff --git a/seed/ruby-sdk/bytes/lib/types_export.rb b/seed/ruby-sdk/bytes/lib/types_export.rb deleted file mode 100644 index 8e9b8f90fa4..00000000000 --- a/seed/ruby-sdk/bytes/lib/types_export.rb +++ /dev/null @@ -1 +0,0 @@ -# frozen_string_literal: true diff --git a/seed/ruby-sdk/bytes/snippet.json b/seed/ruby-sdk/bytes/snippet.json index 0614251dd46..e69de29bb2d 100644 --- a/seed/ruby-sdk/bytes/snippet.json +++ b/seed/ruby-sdk/bytes/snippet.json @@ -1,4 +0,0 @@ -{ - "endpoints": [], - "types": {} -} \ No newline at end of file diff --git a/seed/ts-sdk/bytes/src/api/resources/service/client/Client.ts b/seed/ts-sdk/bytes/src/api/resources/service/client/Client.ts index 9e0a5fe9d1f..40eb127ae95 100644 --- a/seed/ts-sdk/bytes/src/api/resources/service/client/Client.ts +++ b/seed/ts-sdk/bytes/src/api/resources/service/client/Client.ts @@ -83,7 +83,7 @@ export class Service { * @param {Service.RequestOptions} requestOptions - Request-specific configuration. */ public async download(requestOptions?: Service.RequestOptions): Promise { - const _response = await core.fetcher({ + const _response = await core.fetcher({ url: urlJoin(await core.Supplier.get(this._options.environment), "download-content"), method: "GET", headers: { @@ -103,7 +103,7 @@ export class Service { abortSignal: requestOptions?.abortSignal, }); if (_response.ok) { - return _response.body as string; + return _response.body; } if (_response.error.reason === "status-code") {