Skip to content

Commit 56f9289

Browse files
committed
- Custom client changes
1 parent 4bd109e commit 56f9289

31 files changed

+186
-79
lines changed

bin/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ program
1212
.version(pkg.version)
1313
.requiredOption('-i, --input <value>', 'OpenAPI specification, can be a path, url or string content (required)')
1414
.requiredOption('-o, --output <value>', 'Output directory (required)')
15-
.option('-c, --client <value>', 'HTTP client to generate [fetch, xhr, node]', 'fetch')
15+
.option('-c, --client <value>', 'HTTP client to generate [fetch, xhr, node] or path to custom request file', 'fetch')
1616
.option('--useOptions', 'Use options instead of arguments')
1717
.option('--useUnionTypes', 'Use union types instead of enums')
1818
.option('--exportCore <value>', 'Write core files to disk', true)

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"@types/js-yaml": "3.12.5",
8181
"@types/node": "14.14.13",
8282
"@types/node-fetch": "2.5.7",
83+
"@types/qs": "6.9.4",
8384
"@typescript-eslint/eslint-plugin": "4.9.1",
8485
"@typescript-eslint/parser": "4.9.1",
8586
"codecov": "3.8.1",
@@ -90,11 +91,13 @@
9091
"express": "4.17.1",
9192
"form-data": "3.0.0",
9293
"glob": "7.1.6",
94+
"httpntlm": "1.7.6",
9395
"jest": "26.6.3",
9496
"jest-cli": "26.6.3",
9597
"node-fetch": "2.6.1",
9698
"prettier": "2.2.1",
9799
"puppeteer": "5.5.0",
100+
"qs": "6.9.4",
98101
"rollup": "2.34.2",
99102
"rollup-plugin-terser": "7.0.2",
100103
"rollup-plugin-typescript2": "0.29.0",

src/HttpClient.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum HttpClient {
2+
FETCH = 'fetch',
3+
XHR = 'xhr',
4+
NODE = 'node',
5+
}

src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { HttpClient } from './HttpClient';
12
import { parse as parseV2 } from './openApi/v2';
23
import { parse as parseV3 } from './openApi/v3';
34
import { getOpenApiSpec } from './utils/getOpenApiSpec';
@@ -7,16 +8,12 @@ import { postProcessClient } from './utils/postProcessClient';
78
import { registerHandlebarTemplates } from './utils/registerHandlebarTemplates';
89
import { writeClient } from './utils/writeClient';
910

10-
export enum HttpClient {
11-
FETCH = 'fetch',
12-
XHR = 'xhr',
13-
NODE = 'node',
14-
}
11+
export { HttpClient } from './HttpClient';
1512

1613
export type Options = {
1714
input: string | Record<string, any>;
1815
output: string;
19-
httpClient?: HttpClient;
16+
httpClient?: string | HttpClient;
2017
useOptions?: boolean;
2118
useUnionTypes?: boolean;
2219
exportCore?: boolean;

src/openApi/v2/parser/getComment.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as os from 'os';
1+
import { EOL } from 'os';
22

33
import { getComment } from './getComment';
44

55
describe('getComment', () => {
66
it('should parse comments', () => {
7-
const multiline = 'Testing multiline comments.' + os.EOL + ' * This must go to the next line.' + os.EOL + ' * ' + os.EOL + ' * This will contain a break.';
7+
const multiline = 'Testing multiline comments.' + EOL + ' * This must go to the next line.' + EOL + ' * ' + EOL + ' * This will contain a break.';
88
expect(getComment('')).toEqual(null);
99
expect(getComment('Hello')).toEqual('Hello');
1010
expect(getComment('Hello World!')).toEqual('Hello World!');

src/openApi/v2/parser/getComment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as os from 'os';
1+
import { EOL } from 'os';
22

33
/**
44
* Cleanup comment and prefix multiline comments with "*",
@@ -7,7 +7,7 @@ import * as os from 'os';
77
*/
88
export function getComment(comment?: string): string | null {
99
if (comment) {
10-
return comment.replace(/\r?\n(.*)/g, (_, w) => `${os.EOL} * ${w.trim()}`);
10+
return comment.replace(/\r?\n(.*)/g, (_, w) => `${EOL} * ${w.trim()}`);
1111
}
1212
return null;
1313
}

src/openApi/v3/parser/getComment.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as os from 'os';
1+
import { EOL } from 'os';
22

33
import { getComment } from './getComment';
44

55
describe('getComment', () => {
66
it('should parse comments', () => {
7-
const multiline = 'Testing multiline comments.' + os.EOL + ' * This must go to the next line.' + os.EOL + ' * ' + os.EOL + ' * This will contain a break.';
7+
const multiline = 'Testing multiline comments.' + EOL + ' * This must go to the next line.' + EOL + ' * ' + EOL + ' * This will contain a break.';
88
expect(getComment('')).toEqual(null);
99
expect(getComment('Hello')).toEqual('Hello');
1010
expect(getComment('Hello World!')).toEqual('Hello World!');

src/openApi/v3/parser/getComment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as os from 'os';
1+
import { EOL } from 'os';
22

33
/**
44
* Cleanup comment and prefix multiline comments with "*",
@@ -7,7 +7,7 @@ import * as os from 'os';
77
*/
88
export function getComment(comment?: string): string | null {
99
if (comment) {
10-
return comment.replace(/\r?\n(.*)/g, (_, w) => `${os.EOL} * ${w.trim()}`);
10+
return comment.replace(/\r?\n(.*)/g, (_, w) => `${EOL} * ${w.trim()}`);
1111
}
1212
return null;
1313
}

src/templates/core/node/sendRequest.hbs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@ async function sendRequest(options: ApiRequestOptions, url: string): Promise<Res
44
headers: await getHeaders(options),
55
body: getRequestBody(options),
66
};
7-
if (OpenAPI.WITH_CREDENTIALS) {
8-
request.credentials = 'include';
9-
}
107
return await fetch(url, request);
118
}

src/utils/format.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as os from 'os';
1+
import { EOL } from 'os';
22

33
export function format(s: string): string {
44
let indent: number = 0;
5-
let lines = s.split(os.EOL);
5+
let lines = s.split(EOL);
66
lines = lines.map(line => {
77
line = line.trim().replace(/^\*/g, ' *');
88
let i = indent;
@@ -19,5 +19,5 @@ export function format(s: string): string {
1919
}
2020
return result;
2121
});
22-
return lines.join(os.EOL);
22+
return lines.join(EOL);
2323
}

0 commit comments

Comments
 (0)