Skip to content

Commit 0b6fd22

Browse files
committed
- Fixed build and prep for e2e test
1 parent c450461 commit 0b6fd22

32 files changed

+175
-116
lines changed

.babelrc.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
module.exports = {
44
presets: [
5-
[
6-
'@babel/preset-env',
7-
{
8-
targets: {
9-
esmodules: true,
10-
},
11-
},
12-
],
5+
['@babel/preset-env', {
6+
targets: {
7+
node: 'current'
8+
}
9+
}],
1310
'@babel/preset-typescript',
1411
],
1512
};

jest.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
module.exports = {
2-
testRegex: '\\.spec\\.(ts|js)$',
2+
testRegex: '.*\\.spec\\.(ts|js)$',
3+
testPathIgnorePatterns: [
4+
'/node_modules/',
5+
'<rootDir>/dist/',
6+
'<rootDir>/samples/',
7+
],
38
testEnvironment: 'node',
49
moduleNameMapper: {
510
'\\.hbs$': '<rootDir>/src/templates/__mocks__/index.js',
611
},
712
collectCoverageFrom: [
813
'src/**/*.ts',
914
'!src/**/*.d.ts',
10-
'!src/templates/**',
1115
'!**/node_modules/**',
1216
],
1317
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"jest-cli": "26.4.2",
103103
"prettier": "2.1.2",
104104
"reflect-metadata": "0.1.13",
105-
"rollup": "2.28.1",
105+
"rollup": "2.28.2",
106106
"rollup-plugin-terser": "7.0.2",
107107
"rollup-plugin-typescript2": "0.27.2",
108108
"swagger-ui-express": "4.1.4",

rollup.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

33
const commonjs = require('@rollup/plugin-commonjs');
4-
const {nodeResolve} = require('@rollup/plugin-node-resolve');
5-
const {terser} = require('rollup-plugin-terser');
4+
const { nodeResolve } = require('@rollup/plugin-node-resolve');
5+
const { terser } = require('rollup-plugin-terser');
66
const typescript = require('rollup-plugin-typescript2');
77
const handlebars = require('handlebars');
88
const path = require('path');

samples/codegen.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ rm -rf dist
44
rm swagger-codegen-cli-v2.jar
55
rm swagger-codegen-cli-v3.jar
66

7-
curl https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.15/swagger-codegen-cli-2.4.15.jar -o swagger-codegen-cli-v2.jar
8-
curl https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.21/swagger-codegen-cli-3.0.21.jar -o swagger-codegen-cli-v3.jar
7+
#curl https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.15/swagger-codegen-cli-2.4.15.jar -o swagger-codegen-cli-v2.jar
8+
#curl https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.21/swagger-codegen-cli-3.0.21.jar -o swagger-codegen-cli-v3.jar
99

10-
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-aurelia -o dist/v2/typescript-aurelia/
11-
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-angular -o dist/v2/typescript-angular/
12-
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-inversify -o dist/v2/typescript-inversify/
13-
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-fetch -o dist/v2/typescript-fetch/
14-
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-jquery -o dist/v2/typescript-jquery/
15-
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-node -o dist/v2/typescript-node/
10+
#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-aurelia -o dist/v2/typescript-aurelia/
11+
#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-angular -o dist/v2/typescript-angular/
12+
#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-inversify -o dist/v2/typescript-inversify/
13+
#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-fetch -o dist/v2/typescript-fetch/
14+
#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-jquery -o dist/v2/typescript-jquery/
15+
#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-node -o dist/v2/typescript-node/
1616

17-
java -jar ./swagger-codegen-cli-v3.jar generate -i spec/v3.json -l typescript-angular -o dist/v3/typescript-angular/
18-
java -jar ./swagger-codegen-cli-v3.jar generate -i spec/v3.json -l typescript-fetch -o dist/v3/typescript-fetch/
17+
#java -jar ./swagger-codegen-cli-v3.jar generate -i spec/v3.json -l typescript-angular -o dist/v3/typescript-angular/
18+
#java -jar ./swagger-codegen-cli-v3.jar generate -i spec/v3.json -l typescript-fetch -o dist/v3/typescript-fetch/
1919

2020
node ../bin/index.js --input spec/v2.json --output dist/v2/openapi-typescript-codegen/
2121
node ../bin/index.js --input spec/v3.json --output dist/v3/openapi-typescript-codegen/

src/index.spec.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1+
import * as OpenAPI from './index';
2+
13
describe('index', () => {
24
it('parses v2 without issues', async () => {
3-
// await OpenAPI.generate({
4-
// input: './test/mock/v2/spec.json',
5-
// output: './test/result/v2/',
6-
// useOptions: true
7-
// });
5+
await OpenAPI.generate({
6+
input: './test/spec/v3.json',
7+
output: './temp/v3/',
8+
write: false,
9+
});
810
});
911

1012
it('parses v3 without issues', async () => {
11-
// await OpenAPI.generate({
12-
// input: './test/mock/v3/spec.json',
13-
// output: './test/result/v3/',
14-
// useOptions: true
15-
// });
13+
await OpenAPI.generate({
14+
input: './test/spec/v3.json',
15+
output: './temp/v3/',
16+
write: false,
17+
});
1618
});
1719

1820
it('downloads and parses v2 without issues', async () => {
19-
// await OpenAPI.generate({
20-
// input: 'https://raw.githubusercontent.com/ferdikoomen/openapi-typescript-codegen/master/test/mock/v2/spec.json',
21-
// output: './test/result/v2-downloaded/'
22-
// });
21+
await OpenAPI.generate({
22+
input: 'https://raw.githubusercontent.com/ferdikoomen/openapi-typescript-codegen/master/test/spec/v2.json',
23+
output: './temp/v2-downloaded/',
24+
write: false,
25+
});
2326
});
2427

2528
it('downloads and parses v3 without issues', async () => {
26-
// await OpenAPI.generate({
27-
// input: 'https://raw.githubusercontent.com/ferdikoomen/openapi-typescript-codegen/master/test/mock/v3/spec.json',
28-
// output: './test/result/v3-downloaded/'
29-
// });
29+
await OpenAPI.generate({
30+
input: 'https://raw.githubusercontent.com/ferdikoomen/openapi-typescript-codegen/master/test/spec/v3.json',
31+
output: './temp/v3-downloaded/',
32+
write: false,
33+
});
3034
});
3135
});

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface Options {
2323
exportServices?: boolean;
2424
exportModels?: boolean;
2525
exportSchemas?: boolean;
26+
write?: boolean;
2627
}
2728

2829
/**
@@ -50,6 +51,7 @@ export async function generate({
5051
exportServices = true,
5152
exportModels = true,
5253
exportSchemas = false,
54+
write = true,
5355
}: Options): Promise<void> {
5456
// Load the specification, read the OpenAPI version and load the
5557
// handlebar templates for the given language
@@ -61,13 +63,15 @@ export async function generate({
6163
case OpenApiVersion.V2: {
6264
const client = parseV2(openApi);
6365
const clientFinal = postProcessClient(client);
66+
if (!write) break;
6467
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas);
6568
break;
6669
}
6770

6871
case OpenApiVersion.V3: {
6972
const client = parseV3(openApi);
7073
const clientFinal = postProcessClient(client);
74+
if (!write) break;
7175
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas);
7276
break;
7377
}

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 { EOL } from 'os';
1+
import * as os from 'os';
22

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

55
describe('getComment', () => {
66
it('should parse comments', () => {
7-
const multiline = 'Testing multiline comments.' + EOL + ' * This must go to the next line.' + EOL + ' * ' + EOL + ' * This will contain a break.';
7+
const multiline = 'Testing multiline comments.' + os.EOL + ' * This must go to the next line.' + os.EOL + ' * ' + os.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 { EOL } from 'os';
1+
import * as os from 'os';
22

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

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

55
describe('getComment', () => {
66
it('should parse comments', () => {
7-
const multiline = 'Testing multiline comments.' + EOL + ' * This must go to the next line.' + EOL + ' * ' + EOL + ' * This will contain a break.';
7+
const multiline = 'Testing multiline comments.' + os.EOL + ' * This must go to the next line.' + os.EOL + ' * ' + os.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!');

0 commit comments

Comments
 (0)