mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Updated test cases after EOL change
- Added request options object to ApiError
This commit is contained in:
parent
f69da7fe2c
commit
4428f85f2c
892
package-lock.json
generated
892
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -116,7 +116,10 @@
|
||||
"rxjs": "7.5.5",
|
||||
"ts-node": "10.8.0",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.7.2",
|
||||
"typescript": "4.6.4",
|
||||
"zone.js": "0.11.5"
|
||||
},
|
||||
"resolutions": {
|
||||
"node-fetch": "2.6.7"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{{>header}}
|
||||
|
||||
import type { ApiRequestOptions } from './ApiRequestOptions';
|
||||
import type { ApiResult } from './ApiResult';
|
||||
|
||||
export class ApiError extends Error {
|
||||
@ -7,8 +8,9 @@ export class ApiError extends Error {
|
||||
public readonly status: number;
|
||||
public readonly statusText: string;
|
||||
public readonly body: any;
|
||||
public readonly request: ApiRequestOptions;
|
||||
|
||||
constructor(response: ApiResult, message: string) {
|
||||
constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
|
||||
super(message);
|
||||
|
||||
this.name = 'ApiError';
|
||||
@ -16,5 +18,6 @@ export class ApiError extends Error {
|
||||
this.status = response.status;
|
||||
this.statusText = response.statusText;
|
||||
this.body = response.body;
|
||||
this.request = request;
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,10 +12,10 @@ const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void =>
|
||||
|
||||
const error = errors[result.status];
|
||||
if (error) {
|
||||
throw new ApiError(result, error);
|
||||
throw new ApiError(options, result, error);
|
||||
}
|
||||
|
||||
if (!result.ok) {
|
||||
throw new ApiError(result, 'Generic Error');
|
||||
throw new ApiError(options, result, 'Generic Error');
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { EOL } from 'os';
|
||||
|
||||
import type { Client } from '../client/interfaces/Client';
|
||||
import { HttpClient } from '../HttpClient';
|
||||
import { Indent } from '../Indent';
|
||||
@ -38,11 +40,11 @@ describe('writeClientCore', () => {
|
||||
|
||||
await writeClientCore(client, templates, '/', HttpClient.FETCH, Indent.SPACE_4);
|
||||
|
||||
expect(writeFile).toBeCalledWith('/OpenAPI.ts', 'settings');
|
||||
expect(writeFile).toBeCalledWith('/ApiError.ts', 'apiError');
|
||||
expect(writeFile).toBeCalledWith('/ApiRequestOptions.ts', 'apiRequestOptions');
|
||||
expect(writeFile).toBeCalledWith('/ApiResult.ts', 'apiResult');
|
||||
expect(writeFile).toBeCalledWith('/CancelablePromise.ts', 'cancelablePromise');
|
||||
expect(writeFile).toBeCalledWith('/request.ts', 'request');
|
||||
expect(writeFile).toBeCalledWith('/OpenAPI.ts', `settings${EOL}`);
|
||||
expect(writeFile).toBeCalledWith('/ApiError.ts', `apiError${EOL}`);
|
||||
expect(writeFile).toBeCalledWith('/ApiRequestOptions.ts', `apiRequestOptions${EOL}`);
|
||||
expect(writeFile).toBeCalledWith('/ApiResult.ts', `apiResult${EOL}`);
|
||||
expect(writeFile).toBeCalledWith('/CancelablePromise.ts', `cancelablePromise${EOL}`);
|
||||
expect(writeFile).toBeCalledWith('/request.ts', `request${EOL}`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { EOL } from 'os';
|
||||
|
||||
import type { Model } from '../client/interfaces/Model';
|
||||
import { HttpClient } from '../HttpClient';
|
||||
import { Indent } from '../Indent';
|
||||
@ -51,6 +53,6 @@ describe('writeClientModels', () => {
|
||||
|
||||
await writeClientModels(models, templates, '/', HttpClient.FETCH, false, Indent.SPACE_4);
|
||||
|
||||
expect(writeFile).toBeCalledWith('/User.ts', 'model');
|
||||
expect(writeFile).toBeCalledWith('/User.ts', `model${EOL}`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { EOL } from 'os';
|
||||
|
||||
import type { Model } from '../client/interfaces/Model';
|
||||
import { HttpClient } from '../HttpClient';
|
||||
import { Indent } from '../Indent';
|
||||
@ -51,6 +53,6 @@ describe('writeClientSchemas', () => {
|
||||
|
||||
await writeClientSchemas(models, templates, '/', HttpClient.FETCH, false, Indent.SPACE_4);
|
||||
|
||||
expect(writeFile).toBeCalledWith('/$User.ts', 'schema');
|
||||
expect(writeFile).toBeCalledWith('/$User.ts', `schema${EOL}`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { EOL } from 'os';
|
||||
|
||||
import type { Service } from '../client/interfaces/Service';
|
||||
import { HttpClient } from '../HttpClient';
|
||||
import { Indent } from '../Indent';
|
||||
@ -39,6 +41,6 @@ describe('writeClientServices', () => {
|
||||
|
||||
await writeClientServices(services, templates, '/', HttpClient.FETCH, false, false, Indent.SPACE_4, 'Service');
|
||||
|
||||
expect(writeFile).toBeCalledWith('/UserService.ts', 'service');
|
||||
expect(writeFile).toBeCalledWith('/UserService.ts', `service${EOL}`);
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user