Skip to content

Commit 4c21c51

Browse files
committed
- Added test cases for CLI
- Upgraded dependencies
1 parent 1d2d10c commit 4c21c51

File tree

7 files changed

+724
-966
lines changed

7 files changed

+724
-966
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.19.0] - 2022-02-02
5+
### Fixed
6+
- Updated dependencies
7+
### Added
8+
- Added test cases for CLI commands
9+
410
## [0.18.1] - 2022-01-31
511
### Fixed
612
- Escaping error description

bin/index.spec.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const crossSpawn = require('cross-spawn');
2+
3+
describe('bin', () => {
4+
it('it should support minimal params', async () => {
5+
const result = crossSpawn.sync('node', [
6+
'./bin/index.js',
7+
'--input',
8+
'./test/spec/v3.json',
9+
'--output',
10+
'./test/generated/bin',
11+
]);
12+
expect(result.stdout.toString()).toBe('');
13+
expect(result.stderr.toString()).toBe('');
14+
});
15+
16+
it('it should support all params', async () => {
17+
const result = crossSpawn.sync('node', [
18+
'./bin/index.js',
19+
'--input',
20+
'./test/spec/v3.json',
21+
'--output',
22+
'./test/generated/bin',
23+
'--client',
24+
'fetch',
25+
'--useOptions',
26+
'--useUnionTypes',
27+
'--exportCore',
28+
'true',
29+
'--exportServices',
30+
'true',
31+
'--exportModels',
32+
'true',
33+
'--exportSchemas',
34+
'true',
35+
'--indent',
36+
'4',
37+
'--postfix',
38+
'Service',
39+
]);
40+
expect(result.stdout.toString()).toBe('');
41+
expect(result.stderr.toString()).toBe('');
42+
});
43+
44+
it('it should throw error without params', async () => {
45+
const result = crossSpawn.sync('node', ['./bin/index.js']);
46+
expect(result.stdout.toString()).toBe('');
47+
expect(result.stderr.toString()).toContain(`error: required option '-i, --input <value>' not specified`);
48+
});
49+
50+
it('it should throw error with wrong params', async () => {
51+
const result = crossSpawn.sync('node', [
52+
'./bin/index.js',
53+
'--input',
54+
'./test/spec/v3.json',
55+
'--output',
56+
'./test/generated/bin',
57+
'--unknown',
58+
]);
59+
expect(result.stdout.toString()).toBe('');
60+
expect(result.stderr.toString()).toContain(`error: unknown option '--unknown'`);
61+
});
62+
63+
it('it should display help', async () => {
64+
const result = crossSpawn.sync('node', ['./bin/index.js', '--help']);
65+
expect(result.stdout.toString()).toContain(`Usage: openapi [options]`);
66+
expect(result.stdout.toString()).toContain(`-i, --input <value>`);
67+
expect(result.stdout.toString()).toContain(`-o, --output <value>`);
68+
expect(result.stderr.toString()).toBe('');
69+
});
70+
});

docs/angular-support.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ If you want to generate the Angular based client then you can specify `--client
99
The Angular client has been tested with the following versions:
1010

1111
```
12-
"@angular/common": "13.1.3",
13-
"@angular/core": "13.1.3",
14-
"rxjs": "7.5.2",
12+
"@angular/common": "13.1.x",
13+
"@angular/core": "13.1.x",
14+
"rxjs": "7.5.x",
1515
```
1616

1717
## Example

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const config: Config.InitialOptions = {
55
{
66
displayName: 'UNIT',
77
testEnvironment: 'node',
8-
testMatch: ['<rootDir>/src/**/*.spec.ts', '<rootDir>/test/index.spec.ts'],
8+
testMatch: ['<rootDir>/src/**/*.spec.ts', '<rootDir>/test/index.spec.ts', '<rootDir>/bin/index.spec.js'],
99
moduleFileExtensions: ['js', 'ts', 'd.ts'],
1010
moduleNameMapper: {
1111
'\\.hbs$': '<rootDir>/src/templates/__mocks__/index.ts',

package.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@
6060
},
6161
"dependencies": {
6262
"camelcase": "^6.3.0",
63-
"commander": "^8.3.0",
63+
"commander": "^9.0.0",
6464
"handlebars": "^4.7.6",
6565
"json-schema-ref-parser": "^9.0.7"
6666
},
6767
"devDependencies": {
68-
"@angular-devkit/build-angular": "13.1.4",
69-
"@angular/animations": "13.1.3",
70-
"@angular/cli": "13.1.4",
71-
"@angular/common": "13.1.3",
72-
"@angular/compiler": "13.1.3",
73-
"@angular/compiler-cli": "13.1.3",
74-
"@angular/core": "13.1.3",
75-
"@angular/forms": "13.1.3",
76-
"@angular/platform-browser": "13.1.3",
77-
"@angular/platform-browser-dynamic": "13.1.3",
78-
"@angular/router": "13.1.3",
68+
"@angular-devkit/build-angular": "13.2.1",
69+
"@angular/animations": "13.2.1",
70+
"@angular/cli": "13.2.1",
71+
"@angular/common": "13.2.1",
72+
"@angular/compiler": "13.2.1",
73+
"@angular/compiler-cli": "13.2.1",
74+
"@angular/core": "13.2.1",
75+
"@angular/forms": "13.2.1",
76+
"@angular/platform-browser": "13.2.1",
77+
"@angular/platform-browser-dynamic": "13.2.1",
78+
"@angular/router": "13.2.1",
7979
"@babel/cli": "7.16.8",
8080
"@babel/core": "7.16.12",
8181
"@babel/preset-env": "7.16.11",
@@ -87,30 +87,30 @@
8787
"@types/express": "4.17.13",
8888
"@types/glob": "7.2.0",
8989
"@types/jest": "27.4.0",
90-
"@types/node": "17.0.12",
91-
"@types/node-fetch": "^2.5.12",
90+
"@types/node": "17.0.14",
91+
"@types/node-fetch": "2.5.12",
9292
"@types/qs": "6.9.7",
93-
"@typescript-eslint/eslint-plugin": "5.10.1",
94-
"@typescript-eslint/parser": "5.10.1",
95-
"abort-controller": "^3.0.0",
96-
"axios": "^0.25.0",
93+
"@typescript-eslint/eslint-plugin": "5.10.2",
94+
"@typescript-eslint/parser": "5.10.2",
95+
"abort-controller": "3.0.0",
96+
"axios": "0.25.0",
9797
"codecov": "3.8.3",
9898
"cross-spawn": "7.0.3",
99-
"eslint": "8.7.0",
99+
"eslint": "8.8.0",
100100
"eslint-config-prettier": "8.3.0",
101101
"eslint-plugin-prettier": "4.0.0",
102102
"eslint-plugin-simple-import-sort": "7.0.0",
103103
"express": "4.17.2",
104-
"form-data": "^4.0.0",
104+
"form-data": "4.0.0",
105105
"glob": "7.2.0",
106106
"jest": "27.4.7",
107107
"jest-cli": "27.4.7",
108-
"node-fetch": "^2.6.6",
108+
"node-fetch": "2.6.6",
109109
"prettier": "2.5.1",
110-
"puppeteer": "13.1.2",
110+
"puppeteer": "13.1.3",
111111
"qs": "6.10.3",
112-
"rimraf": "^3.0.2",
113-
"rollup": "2.66.1",
112+
"rimraf": "3.0.2",
113+
"rollup": "2.67.0",
114114
"rollup-plugin-node-externals": "3.1.2",
115115
"rollup-plugin-terser": "7.0.2",
116116
"rxjs": "7.5.2",

test/__snapshots__/index.spec.ts.snap

Lines changed: 0 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`v2 should generate: ./test/generated/v2/client.ts 1`] = `
4-
"/* istanbul ignore file */
5-
/* tslint:disable */
6-
/* eslint-disable */
7-
import type { BaseHttpRequest } from './core/BaseHttpRequest';
8-
import type { OpenAPIConfig } from './core/OpenAPI';
9-
import { FetchHttpRequest } from './core/FetchHttpRequest';
10-
11-
import { CollectionFormatService } from './services/CollectionFormatService';
12-
import { ComplexService } from './services/ComplexService';
13-
import { DefaultService } from './services/DefaultService';
14-
import { DefaultsService } from './services/DefaultsService';
15-
import { DescriptionsService } from './services/DescriptionsService';
16-
import { DuplicateService } from './services/DuplicateService';
17-
import { ErrorService } from './services/ErrorService';
18-
import { HeaderService } from './services/HeaderService';
19-
import { MultipleTags1Service } from './services/MultipleTags1Service';
20-
import { MultipleTags2Service } from './services/MultipleTags2Service';
21-
import { MultipleTags3Service } from './services/MultipleTags3Service';
22-
import { NoContentService } from './services/NoContentService';
23-
import { ParametersService } from './services/ParametersService';
24-
import { ResponseService } from './services/ResponseService';
25-
import { SimpleService } from './services/SimpleService';
26-
import { TypesService } from './services/TypesService';
27-
28-
type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
29-
30-
export class DemoAppClient {
31-
32-
public readonly collectionFormat: CollectionFormatService;
33-
public readonly complex: ComplexService;
34-
public readonly default: DefaultService;
35-
public readonly defaults: DefaultsService;
36-
public readonly descriptions: DescriptionsService;
37-
public readonly duplicate: DuplicateService;
38-
public readonly error: ErrorService;
39-
public readonly header: HeaderService;
40-
public readonly multipleTags1: MultipleTags1Service;
41-
public readonly multipleTags2: MultipleTags2Service;
42-
public readonly multipleTags3: MultipleTags3Service;
43-
public readonly noContent: NoContentService;
44-
public readonly parameters: ParametersService;
45-
public readonly response: ResponseService;
46-
public readonly simple: SimpleService;
47-
public readonly types: TypesService;
48-
49-
public readonly request: BaseHttpRequest;
50-
51-
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = FetchHttpRequest) {
52-
this.request = new HttpRequest({
53-
BASE: config?.BASE ?? 'http://localhost:3000/base',
54-
VERSION: config?.VERSION ?? '1.0',
55-
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
56-
CREDENTIALS: config?.CREDENTIALS ?? 'include',
57-
TOKEN: config?.TOKEN,
58-
USERNAME: config?.USERNAME,
59-
PASSWORD: config?.PASSWORD,
60-
HEADERS: config?.HEADERS,
61-
ENCODE_PATH: config?.ENCODE_PATH,
62-
});
63-
64-
this.collectionFormat = new CollectionFormatService(this.request);
65-
this.complex = new ComplexService(this.request);
66-
this.default = new DefaultService(this.request);
67-
this.defaults = new DefaultsService(this.request);
68-
this.descriptions = new DescriptionsService(this.request);
69-
this.duplicate = new DuplicateService(this.request);
70-
this.error = new ErrorService(this.request);
71-
this.header = new HeaderService(this.request);
72-
this.multipleTags1 = new MultipleTags1Service(this.request);
73-
this.multipleTags2 = new MultipleTags2Service(this.request);
74-
this.multipleTags3 = new MultipleTags3Service(this.request);
75-
this.noContent = new NoContentService(this.request);
76-
this.parameters = new ParametersService(this.request);
77-
this.response = new ResponseService(this.request);
78-
this.simple = new SimpleService(this.request);
79-
this.types = new TypesService(this.request);
80-
}
81-
}"
82-
`;
83-
843
exports[`v2 should generate: ./test/generated/v2/core/ApiError.ts 1`] = `
854
"/* istanbul ignore file */
865
/* tslint:disable */
@@ -3030,99 +2949,6 @@ export class TypesService {
30302949
}"
30312950
`;
30322951

3033-
exports[`v3 should generate: ./test/generated/v3/client.ts 1`] = `
3034-
"/* istanbul ignore file */
3035-
/* tslint:disable */
3036-
/* eslint-disable */
3037-
import type { BaseHttpRequest } from './core/BaseHttpRequest';
3038-
import type { OpenAPIConfig } from './core/OpenAPI';
3039-
import { FetchHttpRequest } from './core/FetchHttpRequest';
3040-
3041-
import { CollectionFormatService } from './services/CollectionFormatService';
3042-
import { ComplexService } from './services/ComplexService';
3043-
import { DefaultService } from './services/DefaultService';
3044-
import { DefaultsService } from './services/DefaultsService';
3045-
import { DescriptionsService } from './services/DescriptionsService';
3046-
import { DuplicateService } from './services/DuplicateService';
3047-
import { ErrorService } from './services/ErrorService';
3048-
import { FormDataService } from './services/FormDataService';
3049-
import { HeaderService } from './services/HeaderService';
3050-
import { MultipartService } from './services/MultipartService';
3051-
import { MultipleTags1Service } from './services/MultipleTags1Service';
3052-
import { MultipleTags2Service } from './services/MultipleTags2Service';
3053-
import { MultipleTags3Service } from './services/MultipleTags3Service';
3054-
import { NoContentService } from './services/NoContentService';
3055-
import { ParametersService } from './services/ParametersService';
3056-
import { RequestBodyService } from './services/RequestBodyService';
3057-
import { ResponseService } from './services/ResponseService';
3058-
import { SimpleService } from './services/SimpleService';
3059-
import { TypesService } from './services/TypesService';
3060-
import { UploadService } from './services/UploadService';
3061-
3062-
type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
3063-
3064-
export class DemoAppClient {
3065-
3066-
public readonly collectionFormat: CollectionFormatService;
3067-
public readonly complex: ComplexService;
3068-
public readonly default: DefaultService;
3069-
public readonly defaults: DefaultsService;
3070-
public readonly descriptions: DescriptionsService;
3071-
public readonly duplicate: DuplicateService;
3072-
public readonly error: ErrorService;
3073-
public readonly formData: FormDataService;
3074-
public readonly header: HeaderService;
3075-
public readonly multipart: MultipartService;
3076-
public readonly multipleTags1: MultipleTags1Service;
3077-
public readonly multipleTags2: MultipleTags2Service;
3078-
public readonly multipleTags3: MultipleTags3Service;
3079-
public readonly noContent: NoContentService;
3080-
public readonly parameters: ParametersService;
3081-
public readonly requestBody: RequestBodyService;
3082-
public readonly response: ResponseService;
3083-
public readonly simple: SimpleService;
3084-
public readonly types: TypesService;
3085-
public readonly upload: UploadService;
3086-
3087-
public readonly request: BaseHttpRequest;
3088-
3089-
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = FetchHttpRequest) {
3090-
this.request = new HttpRequest({
3091-
BASE: config?.BASE ?? 'http://localhost:3000/base',
3092-
VERSION: config?.VERSION ?? '1.0',
3093-
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
3094-
CREDENTIALS: config?.CREDENTIALS ?? 'include',
3095-
TOKEN: config?.TOKEN,
3096-
USERNAME: config?.USERNAME,
3097-
PASSWORD: config?.PASSWORD,
3098-
HEADERS: config?.HEADERS,
3099-
ENCODE_PATH: config?.ENCODE_PATH,
3100-
});
3101-
3102-
this.collectionFormat = new CollectionFormatService(this.request);
3103-
this.complex = new ComplexService(this.request);
3104-
this.default = new DefaultService(this.request);
3105-
this.defaults = new DefaultsService(this.request);
3106-
this.descriptions = new DescriptionsService(this.request);
3107-
this.duplicate = new DuplicateService(this.request);
3108-
this.error = new ErrorService(this.request);
3109-
this.formData = new FormDataService(this.request);
3110-
this.header = new HeaderService(this.request);
3111-
this.multipart = new MultipartService(this.request);
3112-
this.multipleTags1 = new MultipleTags1Service(this.request);
3113-
this.multipleTags2 = new MultipleTags2Service(this.request);
3114-
this.multipleTags3 = new MultipleTags3Service(this.request);
3115-
this.noContent = new NoContentService(this.request);
3116-
this.parameters = new ParametersService(this.request);
3117-
this.requestBody = new RequestBodyService(this.request);
3118-
this.response = new ResponseService(this.request);
3119-
this.simple = new SimpleService(this.request);
3120-
this.types = new TypesService(this.request);
3121-
this.upload = new UploadService(this.request);
3122-
}
3123-
}"
3124-
`;
3125-
31262952
exports[`v3 should generate: ./test/generated/v3/core/ApiError.ts 1`] = `
31272953
"/* istanbul ignore file */
31282954
/* tslint:disable */

0 commit comments

Comments
 (0)