Skip to content

Commit 3f535e1

Browse files
Merge pull request #652 from HubSpot/feature/codegenSourceCode
Codegen: CMS Source Code
2 parents 36de5ba + 9bc1dff commit 3f535e1

File tree

10 files changed

+36
-22
lines changed

10 files changed

+36
-22
lines changed

codegen/cms/source_code/apis/ContentApi.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,33 @@ export class ContentApiResponseProcessor {
374374
* @params response Response returned by the server for a request to download
375375
* @throws ApiException if the response code was not in [200, 299]
376376
*/
377-
public async downloadWithHttpInfo(response: ResponseContext): Promise<HttpInfo< void>> {
377+
public async downloadWithHttpInfo(response: ResponseContext): Promise<HttpInfo<HttpFile >> {
378378
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
379+
if (isCodeInRange("200", response.httpStatusCode)) {
380+
const body: HttpFile = await response.getBodyAsFile() as any as HttpFile;
381+
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
382+
}
383+
if (isCodeInRange("403", response.httpStatusCode)) {
384+
throw new ApiException<undefined>(response.httpStatusCode, "Insufficient permissions to access the file", undefined, response.headers);
385+
}
386+
if (isCodeInRange("404", response.httpStatusCode)) {
387+
throw new ApiException<undefined>(response.httpStatusCode, "File not found at the specified path", undefined, response.headers);
388+
}
379389
if (isCodeInRange("0", response.httpStatusCode)) {
380390
const body: Error = ObjectSerializer.deserialize(
381391
ObjectSerializer.parse(await response.body.text(), contentType),
382-
"Error", ""
392+
"Error", "binary"
383393
) as Error;
384394
throw new ApiException<Error>(response.httpStatusCode, "An error occurred.", body, response.headers);
385395
}
386396

387397
// Work around for missing responses in specification, e.g. for petstore.yaml
388398
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
389-
return new HttpInfo(response.httpStatusCode, response.headers, response.body, undefined);
399+
const body: HttpFile = ObjectSerializer.deserialize(
400+
ObjectSerializer.parse(await response.body.text(), contentType),
401+
"HttpFile", "binary"
402+
) as HttpFile;
403+
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
390404
}
391405

392406
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);

codegen/cms/source_code/models/ActionResponse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Source Code
3-
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
2+
* CMS Source Code
3+
* API for managing and retrieving source code files and metadata
44
*
55
* OpenAPI spec version: v3
66
*

codegen/cms/source_code/models/AssetFileMetadata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Source Code
3-
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
2+
* CMS Source Code
3+
* API for managing and retrieving source code files and metadata
44
*
55
* OpenAPI spec version: v3
66
*

codegen/cms/source_code/models/ErrorDetail.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Source Code
3-
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
2+
* CMS Source Code
3+
* API for managing and retrieving source code files and metadata
44
*
55
* OpenAPI spec version: v3
66
*

codegen/cms/source_code/models/FileExtractRequest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Source Code
3-
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
2+
* CMS Source Code
3+
* API for managing and retrieving source code files and metadata
44
*
55
* OpenAPI spec version: v3
66
*

codegen/cms/source_code/models/ModelError.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Source Code
3-
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
2+
* CMS Source Code
3+
* API for managing and retrieving source code files and metadata
44
*
55
* OpenAPI spec version: v3
66
*

codegen/cms/source_code/models/TaskLocator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Source Code
3-
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
2+
* CMS Source Code
3+
* API for managing and retrieving source code files and metadata
44
*
55
* OpenAPI spec version: v3
66
*

codegen/cms/source_code/types/ObjectParamAPI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class ObjectContentApi {
157157
* Download a file
158158
* @param param the request object
159159
*/
160-
public downloadWithHttpInfo(param: ContentApiDownloadRequest, options?: ConfigurationOptions): Promise<HttpInfo<void>> {
160+
public downloadWithHttpInfo(param: ContentApiDownloadRequest, options?: ConfigurationOptions): Promise<HttpInfo<HttpFile>> {
161161
return this.api.downloadWithHttpInfo(param.environment, param.path, options).toPromise();
162162
}
163163

@@ -166,7 +166,7 @@ export class ObjectContentApi {
166166
* Download a file
167167
* @param param the request object
168168
*/
169-
public download(param: ContentApiDownloadRequest, options?: ConfigurationOptions): Promise<void> {
169+
public download(param: ContentApiDownloadRequest, options?: ConfigurationOptions): Promise<HttpFile> {
170170
return this.api.download(param.environment, param.path, options).toPromise();
171171
}
172172

codegen/cms/source_code/types/ObservableAPI.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export class ObservableContentApi {
226226
* @param environment The environment of the file (\&quot;draft\&quot; or \&quot;published\&quot;).
227227
* @param path The file system location of the file.
228228
*/
229-
public downloadWithHttpInfo(environment: string, path: string, _options?: ConfigurationOptions): Observable<HttpInfo<void>> {
229+
public downloadWithHttpInfo(environment: string, path: string, _options?: ConfigurationOptions): Observable<HttpInfo<HttpFile>> {
230230
let _config = this.configuration;
231231
let allMiddleware: Middleware[] = [];
232232
if (_options && _options.middleware){
@@ -280,8 +280,8 @@ export class ObservableContentApi {
280280
* @param environment The environment of the file (\&quot;draft\&quot; or \&quot;published\&quot;).
281281
* @param path The file system location of the file.
282282
*/
283-
public download(environment: string, path: string, _options?: ConfigurationOptions): Observable<void> {
284-
return this.downloadWithHttpInfo(environment, path, _options).pipe(map((apiResponse: HttpInfo<void>) => apiResponse.data));
283+
public download(environment: string, path: string, _options?: ConfigurationOptions): Observable<HttpFile> {
284+
return this.downloadWithHttpInfo(environment, path, _options).pipe(map((apiResponse: HttpInfo<HttpFile>) => apiResponse.data));
285285
}
286286

287287
}

codegen/cms/source_code/types/PromiseAPI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class PromiseContentApi {
168168
* @param environment The environment of the file (\&quot;draft\&quot; or \&quot;published\&quot;).
169169
* @param path The file system location of the file.
170170
*/
171-
public downloadWithHttpInfo(environment: string, path: string, _options?: PromiseConfigurationOptions): Promise<HttpInfo<void>> {
171+
public downloadWithHttpInfo(environment: string, path: string, _options?: PromiseConfigurationOptions): Promise<HttpInfo<HttpFile>> {
172172
let observableOptions: undefined | ConfigurationOptions
173173
if (_options){
174174
observableOptions = {
@@ -191,7 +191,7 @@ export class PromiseContentApi {
191191
* @param environment The environment of the file (\&quot;draft\&quot; or \&quot;published\&quot;).
192192
* @param path The file system location of the file.
193193
*/
194-
public download(environment: string, path: string, _options?: PromiseConfigurationOptions): Promise<void> {
194+
public download(environment: string, path: string, _options?: PromiseConfigurationOptions): Promise<HttpFile> {
195195
let observableOptions: undefined | ConfigurationOptions
196196
if (_options){
197197
observableOptions = {

0 commit comments

Comments
 (0)