- Added test cases for CLI

- Upgraded dependencies
This commit is contained in:
Ferdi Koomen 2022-02-02 20:45:40 +01:00
parent 1d2d10c39c
commit 4c21c5107d
7 changed files with 707 additions and 949 deletions

View File

@ -1,6 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.
## [0.19.0] - 2022-02-02
### Fixed
- Updated dependencies
### Added
- Added test cases for CLI commands
## [0.18.1] - 2022-01-31
### Fixed
- Escaping error description

70
bin/index.spec.js Executable file
View File

@ -0,0 +1,70 @@
const crossSpawn = require('cross-spawn');
describe('bin', () => {
it('it should support minimal params', async () => {
const result = crossSpawn.sync('node', [
'./bin/index.js',
'--input',
'./test/spec/v3.json',
'--output',
'./test/generated/bin',
]);
expect(result.stdout.toString()).toBe('');
expect(result.stderr.toString()).toBe('');
});
it('it should support all params', async () => {
const result = crossSpawn.sync('node', [
'./bin/index.js',
'--input',
'./test/spec/v3.json',
'--output',
'./test/generated/bin',
'--client',
'fetch',
'--useOptions',
'--useUnionTypes',
'--exportCore',
'true',
'--exportServices',
'true',
'--exportModels',
'true',
'--exportSchemas',
'true',
'--indent',
'4',
'--postfix',
'Service',
]);
expect(result.stdout.toString()).toBe('');
expect(result.stderr.toString()).toBe('');
});
it('it should throw error without params', async () => {
const result = crossSpawn.sync('node', ['./bin/index.js']);
expect(result.stdout.toString()).toBe('');
expect(result.stderr.toString()).toContain(`error: required option '-i, --input <value>' not specified`);
});
it('it should throw error with wrong params', async () => {
const result = crossSpawn.sync('node', [
'./bin/index.js',
'--input',
'./test/spec/v3.json',
'--output',
'./test/generated/bin',
'--unknown',
]);
expect(result.stdout.toString()).toBe('');
expect(result.stderr.toString()).toContain(`error: unknown option '--unknown'`);
});
it('it should display help', async () => {
const result = crossSpawn.sync('node', ['./bin/index.js', '--help']);
expect(result.stdout.toString()).toContain(`Usage: openapi [options]`);
expect(result.stdout.toString()).toContain(`-i, --input <value>`);
expect(result.stdout.toString()).toContain(`-o, --output <value>`);
expect(result.stderr.toString()).toBe('');
});
});

View File

@ -9,9 +9,9 @@ If you want to generate the Angular based client then you can specify `--client
The Angular client has been tested with the following versions:
```
"@angular/common": "13.1.3",
"@angular/core": "13.1.3",
"rxjs": "7.5.2",
"@angular/common": "13.1.x",
"@angular/core": "13.1.x",
"rxjs": "7.5.x",
```
## Example

View File

@ -5,7 +5,7 @@ const config: Config.InitialOptions = {
{
displayName: 'UNIT',
testEnvironment: 'node',
testMatch: ['<rootDir>/src/**/*.spec.ts', '<rootDir>/test/index.spec.ts'],
testMatch: ['<rootDir>/src/**/*.spec.ts', '<rootDir>/test/index.spec.ts', '<rootDir>/bin/index.spec.js'],
moduleFileExtensions: ['js', 'ts', 'd.ts'],
moduleNameMapper: {
'\\.hbs$': '<rootDir>/src/templates/__mocks__/index.ts',

View File

@ -60,22 +60,22 @@
},
"dependencies": {
"camelcase": "^6.3.0",
"commander": "^8.3.0",
"commander": "^9.0.0",
"handlebars": "^4.7.6",
"json-schema-ref-parser": "^9.0.7"
},
"devDependencies": {
"@angular-devkit/build-angular": "13.1.4",
"@angular/animations": "13.1.3",
"@angular/cli": "13.1.4",
"@angular/common": "13.1.3",
"@angular/compiler": "13.1.3",
"@angular/compiler-cli": "13.1.3",
"@angular/core": "13.1.3",
"@angular/forms": "13.1.3",
"@angular/platform-browser": "13.1.3",
"@angular/platform-browser-dynamic": "13.1.3",
"@angular/router": "13.1.3",
"@angular-devkit/build-angular": "13.2.1",
"@angular/animations": "13.2.1",
"@angular/cli": "13.2.1",
"@angular/common": "13.2.1",
"@angular/compiler": "13.2.1",
"@angular/compiler-cli": "13.2.1",
"@angular/core": "13.2.1",
"@angular/forms": "13.2.1",
"@angular/platform-browser": "13.2.1",
"@angular/platform-browser-dynamic": "13.2.1",
"@angular/router": "13.2.1",
"@babel/cli": "7.16.8",
"@babel/core": "7.16.12",
"@babel/preset-env": "7.16.11",
@ -87,30 +87,30 @@
"@types/express": "4.17.13",
"@types/glob": "7.2.0",
"@types/jest": "27.4.0",
"@types/node": "17.0.12",
"@types/node-fetch": "^2.5.12",
"@types/node": "17.0.14",
"@types/node-fetch": "2.5.12",
"@types/qs": "6.9.7",
"@typescript-eslint/eslint-plugin": "5.10.1",
"@typescript-eslint/parser": "5.10.1",
"abort-controller": "^3.0.0",
"axios": "^0.25.0",
"@typescript-eslint/eslint-plugin": "5.10.2",
"@typescript-eslint/parser": "5.10.2",
"abort-controller": "3.0.0",
"axios": "0.25.0",
"codecov": "3.8.3",
"cross-spawn": "7.0.3",
"eslint": "8.7.0",
"eslint": "8.8.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"express": "4.17.2",
"form-data": "^4.0.0",
"form-data": "4.0.0",
"glob": "7.2.0",
"jest": "27.4.7",
"jest-cli": "27.4.7",
"node-fetch": "^2.6.6",
"node-fetch": "2.6.6",
"prettier": "2.5.1",
"puppeteer": "13.1.2",
"puppeteer": "13.1.3",
"qs": "6.10.3",
"rimraf": "^3.0.2",
"rollup": "2.66.1",
"rimraf": "3.0.2",
"rollup": "2.67.0",
"rollup-plugin-node-externals": "3.1.2",
"rollup-plugin-terser": "7.0.2",
"rxjs": "7.5.2",

View File

@ -1,86 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`v2 should generate: ./test/generated/v2/client.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { BaseHttpRequest } from './core/BaseHttpRequest';
import type { OpenAPIConfig } from './core/OpenAPI';
import { FetchHttpRequest } from './core/FetchHttpRequest';
import { CollectionFormatService } from './services/CollectionFormatService';
import { ComplexService } from './services/ComplexService';
import { DefaultService } from './services/DefaultService';
import { DefaultsService } from './services/DefaultsService';
import { DescriptionsService } from './services/DescriptionsService';
import { DuplicateService } from './services/DuplicateService';
import { ErrorService } from './services/ErrorService';
import { HeaderService } from './services/HeaderService';
import { MultipleTags1Service } from './services/MultipleTags1Service';
import { MultipleTags2Service } from './services/MultipleTags2Service';
import { MultipleTags3Service } from './services/MultipleTags3Service';
import { NoContentService } from './services/NoContentService';
import { ParametersService } from './services/ParametersService';
import { ResponseService } from './services/ResponseService';
import { SimpleService } from './services/SimpleService';
import { TypesService } from './services/TypesService';
type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
export class DemoAppClient {
public readonly collectionFormat: CollectionFormatService;
public readonly complex: ComplexService;
public readonly default: DefaultService;
public readonly defaults: DefaultsService;
public readonly descriptions: DescriptionsService;
public readonly duplicate: DuplicateService;
public readonly error: ErrorService;
public readonly header: HeaderService;
public readonly multipleTags1: MultipleTags1Service;
public readonly multipleTags2: MultipleTags2Service;
public readonly multipleTags3: MultipleTags3Service;
public readonly noContent: NoContentService;
public readonly parameters: ParametersService;
public readonly response: ResponseService;
public readonly simple: SimpleService;
public readonly types: TypesService;
public readonly request: BaseHttpRequest;
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = FetchHttpRequest) {
this.request = new HttpRequest({
BASE: config?.BASE ?? 'http://localhost:3000/base',
VERSION: config?.VERSION ?? '1.0',
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
CREDENTIALS: config?.CREDENTIALS ?? 'include',
TOKEN: config?.TOKEN,
USERNAME: config?.USERNAME,
PASSWORD: config?.PASSWORD,
HEADERS: config?.HEADERS,
ENCODE_PATH: config?.ENCODE_PATH,
});
this.collectionFormat = new CollectionFormatService(this.request);
this.complex = new ComplexService(this.request);
this.default = new DefaultService(this.request);
this.defaults = new DefaultsService(this.request);
this.descriptions = new DescriptionsService(this.request);
this.duplicate = new DuplicateService(this.request);
this.error = new ErrorService(this.request);
this.header = new HeaderService(this.request);
this.multipleTags1 = new MultipleTags1Service(this.request);
this.multipleTags2 = new MultipleTags2Service(this.request);
this.multipleTags3 = new MultipleTags3Service(this.request);
this.noContent = new NoContentService(this.request);
this.parameters = new ParametersService(this.request);
this.response = new ResponseService(this.request);
this.simple = new SimpleService(this.request);
this.types = new TypesService(this.request);
}
}"
`;
exports[`v2 should generate: ./test/generated/v2/core/ApiError.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
@ -3030,99 +2949,6 @@ export class TypesService {
}"
`;
exports[`v3 should generate: ./test/generated/v3/client.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { BaseHttpRequest } from './core/BaseHttpRequest';
import type { OpenAPIConfig } from './core/OpenAPI';
import { FetchHttpRequest } from './core/FetchHttpRequest';
import { CollectionFormatService } from './services/CollectionFormatService';
import { ComplexService } from './services/ComplexService';
import { DefaultService } from './services/DefaultService';
import { DefaultsService } from './services/DefaultsService';
import { DescriptionsService } from './services/DescriptionsService';
import { DuplicateService } from './services/DuplicateService';
import { ErrorService } from './services/ErrorService';
import { FormDataService } from './services/FormDataService';
import { HeaderService } from './services/HeaderService';
import { MultipartService } from './services/MultipartService';
import { MultipleTags1Service } from './services/MultipleTags1Service';
import { MultipleTags2Service } from './services/MultipleTags2Service';
import { MultipleTags3Service } from './services/MultipleTags3Service';
import { NoContentService } from './services/NoContentService';
import { ParametersService } from './services/ParametersService';
import { RequestBodyService } from './services/RequestBodyService';
import { ResponseService } from './services/ResponseService';
import { SimpleService } from './services/SimpleService';
import { TypesService } from './services/TypesService';
import { UploadService } from './services/UploadService';
type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
export class DemoAppClient {
public readonly collectionFormat: CollectionFormatService;
public readonly complex: ComplexService;
public readonly default: DefaultService;
public readonly defaults: DefaultsService;
public readonly descriptions: DescriptionsService;
public readonly duplicate: DuplicateService;
public readonly error: ErrorService;
public readonly formData: FormDataService;
public readonly header: HeaderService;
public readonly multipart: MultipartService;
public readonly multipleTags1: MultipleTags1Service;
public readonly multipleTags2: MultipleTags2Service;
public readonly multipleTags3: MultipleTags3Service;
public readonly noContent: NoContentService;
public readonly parameters: ParametersService;
public readonly requestBody: RequestBodyService;
public readonly response: ResponseService;
public readonly simple: SimpleService;
public readonly types: TypesService;
public readonly upload: UploadService;
public readonly request: BaseHttpRequest;
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = FetchHttpRequest) {
this.request = new HttpRequest({
BASE: config?.BASE ?? 'http://localhost:3000/base',
VERSION: config?.VERSION ?? '1.0',
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
CREDENTIALS: config?.CREDENTIALS ?? 'include',
TOKEN: config?.TOKEN,
USERNAME: config?.USERNAME,
PASSWORD: config?.PASSWORD,
HEADERS: config?.HEADERS,
ENCODE_PATH: config?.ENCODE_PATH,
});
this.collectionFormat = new CollectionFormatService(this.request);
this.complex = new ComplexService(this.request);
this.default = new DefaultService(this.request);
this.defaults = new DefaultsService(this.request);
this.descriptions = new DescriptionsService(this.request);
this.duplicate = new DuplicateService(this.request);
this.error = new ErrorService(this.request);
this.formData = new FormDataService(this.request);
this.header = new HeaderService(this.request);
this.multipart = new MultipartService(this.request);
this.multipleTags1 = new MultipleTags1Service(this.request);
this.multipleTags2 = new MultipleTags2Service(this.request);
this.multipleTags3 = new MultipleTags3Service(this.request);
this.noContent = new NoContentService(this.request);
this.parameters = new ParametersService(this.request);
this.requestBody = new RequestBodyService(this.request);
this.response = new ResponseService(this.request);
this.simple = new SimpleService(this.request);
this.types = new TypesService(this.request);
this.upload = new UploadService(this.request);
}
}"
`;
exports[`v3 should generate: ./test/generated/v3/core/ApiError.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */

1350
yarn.lock

File diff suppressed because it is too large Load Diff