Skip to content

Commit 8b15c1e

Browse files
committed
- Testing new templates
1 parent d833777 commit 8b15c1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+485
-459
lines changed

jest.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ module.exports = {
1515
displayName: 'E2E',
1616
testEnvironment: 'node',
1717
testMatch: [
18-
'<rootDir>/test/e2e/v2.fetch.spec.js',
19-
'<rootDir>/test/e2e/v2.xhr.spec.js',
20-
// '<rootDir>/test/e2e/v2.node.spec.js',
21-
'<rootDir>/test/e2e/v3.fetch.spec.js',
22-
'<rootDir>/test/e2e/v3.xhr.spec.js',
18+
// '<rootDir>/test/e2e/v2.fetch.spec.js',
19+
// '<rootDir>/test/e2e/v2.xhr.spec.js',
20+
'<rootDir>/test/e2e/v2.node.spec.js',
21+
// '<rootDir>/test/e2e/v3.fetch.spec.js',
22+
// '<rootDir>/test/e2e/v3.xhr.spec.js',
2323
// '<rootDir>/test/e2e/v3.node.spec.js',
2424
],
2525
},

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@
6363
"aap": "node test/e2e/index.js"
6464
},
6565
"dependencies": {
66+
"@types/node-fetch": "2.5.7",
6667
"camelcase": "6.0.0",
6768
"commander": "6.1.0",
69+
"form-data": "3.0.0",
6870
"handlebars": "4.7.6",
6971
"js-yaml": "3.14.0",
7072
"mkdirp": "1.0.4",
73+
"node-fetch": "2.6.1",
7174
"path": "0.12.7",
7275
"rimraf": "3.0.2"
7376
},

src/openApi/v2/parser/getOperation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function getOperation(openApi: OpenApi, url: string, method: string, op:
2626
summary: getComment(op.summary),
2727
description: getComment(op.description),
2828
deprecated: op.deprecated === true,
29-
method: method,
29+
method: method.toUpperCase(),
3030
path: operationPath,
3131
parameters: [...pathParams.parameters],
3232
parametersPath: [...pathParams.parametersPath],

src/openApi/v3/parser/getOperation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function getOperation(openApi: OpenApi, url: string, method: string, op:
3030
summary: getComment(op.summary),
3131
description: getComment(op.description),
3232
deprecated: op.deprecated === true,
33-
method: method,
33+
method: method.toUpperCase(),
3434
path: operationPath,
3535
parameters: [...pathParams.parameters],
3636
parametersPath: [...pathParams.parametersPath],

src/templates/core/ApiError.hbs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,19 @@
1-
/* istanbul ignore file */
2-
/* tslint:disable */
3-
/* eslint-disable */
1+
{{>header}}
42

5-
import { isSuccess } from './isSuccess';
6-
import { Result } from './Result';
3+
import { ApiResponse } from './ApiResponse';
74

85
export class ApiError extends Error {
9-
106
public readonly url: string;
117
public readonly status: number;
128
public readonly statusText: string;
139
public readonly body: any;
1410

15-
constructor(result: Readonly<Result>, message: string) {
11+
constructor(response: ApiResponse, message: string) {
1612
super(message);
1713

18-
this.url = result.url;
19-
this.status = result.status;
20-
this.statusText = result.statusText;
21-
this.body = result.body;
22-
}
23-
}
24-
25-
/**
26-
* Catch common errors (based on status code).
27-
* @param result
28-
*/
29-
export function catchGenericError(result: Result): void {
30-
switch (result.status) {
31-
case 400: throw new ApiError(result, 'Bad Request');
32-
case 401: throw new ApiError(result, 'Unauthorized');
33-
case 403: throw new ApiError(result, 'Forbidden');
34-
case 404: throw new ApiError(result, 'Not Found');
35-
case 500: throw new ApiError(result, 'Internal Server Error');
36-
case 502: throw new ApiError(result, 'Bad Gateway');
37-
case 503: throw new ApiError(result, 'Service Unavailable');
38-
}
39-
40-
if (!isSuccess(result.status)) {
41-
throw new ApiError(result, 'Generic Error');
14+
this.url = response.url;
15+
this.status = response.status;
16+
this.statusText = response.statusText;
17+
this.body = response.body;
4218
}
4319
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{>header}}
2+
3+
export interface RequestOptions {
4+
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
5+
readonly path: string;
6+
readonly cookies?: Record<string, any>;
7+
readonly headers?: Record<string, any>;
8+
readonly query?: Record<string, any>;
9+
readonly formData?: Record<string, any>;
10+
readonly body?: any;
11+
readonly responseHeader?: string;
12+
readonly errors?: Record<number, string>;
13+
}

src/templates/core/ApiResponse.hbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{>header}}
2+
3+
export interface Response {
4+
readonly url: string;
5+
readonly ok: boolean;
6+
readonly status: number;
7+
readonly statusText: string;
8+
readonly body: any;
9+
}

src/templates/core/OpenAPI.hbs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* istanbul ignore file */
2-
/* tslint:disable */
3-
/* eslint-disable */
1+
{{>header}}
42

53
interface Config {
64
BASE: string;

src/templates/core/RequestOptions.hbs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/templates/core/Result.hbs

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)