mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Merge branch 'master' into parameter-components
This commit is contained in:
commit
80880e69c5
41
.github/workflows/codeql.yml
vendored
Normal file
41
.github/workflows/codeql.yml
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
schedule:
|
||||
- cron: "44 20 * * 3"
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ javascript ]
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
queries: +security-and-quality
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: "/language:${{ matrix.language }}"
|
||||
@ -1,6 +1,14 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.24.0] - 2023-04-10
|
||||
### Fixed
|
||||
- Upgraded dependencies
|
||||
- Fixed issue with Cancelable promise
|
||||
- Fixed issue with escaping reserved keywords in schema names
|
||||
### Added
|
||||
- Added `--postfixModels` option
|
||||
|
||||
## [0.23.0] - 2022-06-02
|
||||
### Fixed
|
||||
- Upgraded dependencies
|
||||
|
||||
@ -3,8 +3,6 @@
|
||||
[![NPM][npm-image]][npm-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Coverage][coverage-image]][coverage-url]
|
||||
[![Quality][quality-image]][quality-url]
|
||||
[![Code Climate][climate-image]][climate-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
[![Build][build-image]][build-url]
|
||||
|
||||
@ -14,7 +12,7 @@
|
||||
- Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
|
||||
- Quick, lightweight, robust and framework-agnostic 🚀
|
||||
- Supports generation of TypeScript clients
|
||||
- Supports generations of Fetch, [Node-Fetch](#node-fetch-support), [Axios](#axios-support), [Angular](#angular-support) and XHR http clients
|
||||
- Supports generations of Fetch, Node-Fetch, Axios, Angular and XHR http clients
|
||||
- Supports OpenAPI specification v2.0 and v3.0
|
||||
- Supports JSON and YAML files for input
|
||||
- Supports generation through CLI, Node.js and NPX
|
||||
@ -86,10 +84,6 @@ Support
|
||||
[license-image]: http://img.shields.io/npm/l/openapi-typescript-codegen.svg
|
||||
[coverage-url]: https://codecov.io/gh/ferdikoomen/openapi-typescript-codegen
|
||||
[coverage-image]: https://img.shields.io/codecov/c/github/ferdikoomen/openapi-typescript-codegen.svg
|
||||
[quality-url]: https://lgtm.com/projects/g/ferdikoomen/openapi-typescript-codegen
|
||||
[quality-image]: https://img.shields.io/lgtm/grade/javascript/g/ferdikoomen/openapi-typescript-codegen.svg
|
||||
[climate-url]: https://codeclimate.com/github/ferdikoomen/openapi-typescript-codegen
|
||||
[climate-image]: https://img.shields.io/codeclimate/maintainability/ferdikoomen/openapi-typescript-codegen.svg
|
||||
[downloads-url]: http://npm-stat.com/charts.html?package=openapi-typescript-codegen
|
||||
[downloads-image]: http://img.shields.io/npm/dm/openapi-typescript-codegen.svg
|
||||
[build-url]: https://circleci.com/gh/ferdikoomen/openapi-typescript-codegen/tree/master
|
||||
|
||||
@ -21,7 +21,6 @@ const params = program
|
||||
.option('--exportModels <value>', 'Write models to disk', true)
|
||||
.option('--exportSchemas <value>', 'Write schemas to disk', false)
|
||||
.option('--indent <value>', 'Indentation options [4, 2, tabs]', '4')
|
||||
.option('--postfix <value>', 'Deprecated: Use --postfixServices instead. Service name postfix', 'Service')
|
||||
.option('--postfixServices <value>', 'Service name postfix', 'Service')
|
||||
.option('--postfixModels <value>', 'Model name postfix')
|
||||
.option('--request <value>', 'Path to custom request file')
|
||||
@ -43,7 +42,7 @@ if (OpenAPI) {
|
||||
exportModels: JSON.parse(params.exportModels) === true,
|
||||
exportSchemas: JSON.parse(params.exportSchemas) === true,
|
||||
indent: params.indent,
|
||||
postfixServices: params.postfixServices ?? params.postfix,
|
||||
postfixServices: params.postfixServices,
|
||||
postfixModels: params.postfixModels,
|
||||
request: params.request,
|
||||
})
|
||||
|
||||
@ -69,18 +69,4 @@ describe('bin', () => {
|
||||
expect(result.stdout.toString()).toContain(`-o, --output <value>`);
|
||||
expect(result.stderr.toString()).toBe('');
|
||||
});
|
||||
|
||||
it('should still support the deprecated --postfix parameter', () => {
|
||||
const result = crossSpawn.sync('node', [
|
||||
'./bin/index.js',
|
||||
'--input',
|
||||
'./test/spec/v3.json',
|
||||
'--output',
|
||||
'./test/generated/bin',
|
||||
'--postfix',
|
||||
'Service',
|
||||
]);
|
||||
expect(result.stdout.toString()).toBe('');
|
||||
expect(result.stderr.toString()).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,8 +9,8 @@ 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": "14.0.x",
|
||||
"@angular/core": "14.0.x",
|
||||
"@angular/common": "15.0.x",
|
||||
"@angular/core": "15.0.x",
|
||||
"rxjs": "7.5.x",
|
||||
```
|
||||
|
||||
|
||||
19126
package-lock.json
generated
19126
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
94
package.json
94
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openapi-typescript-codegen",
|
||||
"version": "0.23.0",
|
||||
"version": "0.24.0",
|
||||
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
|
||||
"author": "Ferdi Koomen",
|
||||
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",
|
||||
@ -60,67 +60,69 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"camelcase": "^6.3.0",
|
||||
"commander": "^9.4.1",
|
||||
"fs-extra": "^10.1.0",
|
||||
"commander": "^10.0.0",
|
||||
"fs-extra": "^11.1.1",
|
||||
"handlebars": "^4.7.7",
|
||||
"json-schema-ref-parser": "^9.0.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "14.2.7",
|
||||
"@angular/animations": "14.2.8",
|
||||
"@angular/cli": "14.2.7",
|
||||
"@angular/common": "14.2.8",
|
||||
"@angular/compiler": "14.2.8",
|
||||
"@angular/compiler-cli": "14.2.8",
|
||||
"@angular/core": "14.2.8",
|
||||
"@angular/forms": "14.2.8",
|
||||
"@angular/platform-browser": "14.2.8",
|
||||
"@angular/platform-browser-dynamic": "14.2.8",
|
||||
"@angular/router": "14.2.8",
|
||||
"@babel/cli": "7.20.7",
|
||||
"@babel/core": "7.20.12",
|
||||
"@babel/preset-env": "7.20.2",
|
||||
"@babel/preset-typescript": "7.18.6",
|
||||
"@rollup/plugin-commonjs": "23.0.5",
|
||||
"@rollup/plugin-node-resolve": "15.0.1",
|
||||
"@rollup/plugin-typescript": "9.0.2",
|
||||
"@angular-devkit/build-angular": "15.2.5",
|
||||
"@angular/animations": "15.2.6",
|
||||
"@angular/cli": "15.2.5",
|
||||
"@angular/common": "15.2.6",
|
||||
"@angular/compiler": "15.2.6",
|
||||
"@angular/compiler-cli": "15.2.6",
|
||||
"@angular/core": "15.2.6",
|
||||
"@angular/forms": "15.2.6",
|
||||
"@angular/platform-browser": "15.2.6",
|
||||
"@angular/platform-browser-dynamic": "15.2.6",
|
||||
"@angular/router": "15.2.6",
|
||||
"@babel/cli": "7.21.0",
|
||||
"@babel/core": "7.21.4",
|
||||
"@babel/preset-env": "7.21.4",
|
||||
"@babel/preset-typescript": "7.21.4",
|
||||
"@rollup/plugin-commonjs": "24.0.1",
|
||||
"@rollup/plugin-node-resolve": "15.0.2",
|
||||
"@rollup/plugin-typescript": "11.1.0",
|
||||
"@types/cross-spawn": "6.0.2",
|
||||
"@types/express": "4.17.15",
|
||||
"@types/fs-extra": "^9.0.13",
|
||||
"@types/glob": "8.0.1",
|
||||
"@types/jest": "29.2.5",
|
||||
"@types/node": "18.11.18",
|
||||
"@types/node-fetch": "2.6.2",
|
||||
"@types/express": "4.17.17",
|
||||
"@types/fs-extra": "^11.0.1",
|
||||
"@types/glob": "8.1.0",
|
||||
"@types/jest": "29.5.0",
|
||||
"@types/node": "18.15.11",
|
||||
"@types/node-fetch": "2.6.3",
|
||||
"@types/qs": "6.9.7",
|
||||
"@typescript-eslint/eslint-plugin": "5.49.0",
|
||||
"@typescript-eslint/parser": "5.48.2",
|
||||
"@typescript-eslint/eslint-plugin": "5.57.1",
|
||||
"@typescript-eslint/parser": "5.58.0",
|
||||
"abort-controller": "3.0.0",
|
||||
"axios": "1.2.3",
|
||||
"axios": "1.3.5",
|
||||
"codecov": "3.8.3",
|
||||
"cross-spawn": "7.0.3",
|
||||
"eslint": "8.32.0",
|
||||
"eslint-config-prettier": "8.6.0",
|
||||
"eslint": "8.38.0",
|
||||
"eslint-config-prettier": "8.8.0",
|
||||
"eslint-plugin-prettier": "4.2.1",
|
||||
"eslint-plugin-simple-import-sort": "8.0.0",
|
||||
"eslint-plugin-simple-import-sort": "10.0.0",
|
||||
"express": "4.18.2",
|
||||
"form-data": "4.0.0",
|
||||
"glob": "8.1.0",
|
||||
"jest": "29.3.1",
|
||||
"jest-cli": "29.3.1",
|
||||
"node-fetch": "2.6.7",
|
||||
"prettier": "2.8.3",
|
||||
"puppeteer": "19.5.2",
|
||||
"qs": "6.11.0",
|
||||
"rimraf": "3.0.2",
|
||||
"rollup": "3.2.3",
|
||||
"glob": "10.0.0",
|
||||
"jest": "29.5.0",
|
||||
"jest-cli": "29.5.0",
|
||||
"node-fetch": "2.6.9",
|
||||
"prettier": "2.8.7",
|
||||
"puppeteer": "19.8.5",
|
||||
"qs": "6.11.1",
|
||||
"rimraf": "5.0.0",
|
||||
"rollup": "3.20.2",
|
||||
"rollup-plugin-terser": "7.0.2",
|
||||
"rxjs": "7.8.0",
|
||||
"ts-node": "10.9.1",
|
||||
"tslib": "2.4.1",
|
||||
"typescript": "4.8.4",
|
||||
"zone.js": "0.11.8"
|
||||
"tslib": "2.5.0",
|
||||
"typescript": "4.9.5",
|
||||
"zone.js": "0.13.0"
|
||||
},
|
||||
"overrides" : {
|
||||
"rollup": "3.2.3"
|
||||
"node-fetch": "2.6.9",
|
||||
"rollup": "3.20.2",
|
||||
"typescript": "4.9.5"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import type { Model } from '../../../client/interfaces/Model';
|
||||
import { reservedWords } from '../../v3/parser/getOperationParameterName';
|
||||
import { reservedWords } from '../../../utils/reservedWords';
|
||||
import type { OpenApi } from '../interfaces/OpenApi';
|
||||
import { getModel } from './getModel';
|
||||
import { getType } from './getType';
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import camelCase from 'camelcase';
|
||||
|
||||
const reservedWords =
|
||||
/^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
|
||||
import { reservedWords } from '../../../utils/reservedWords';
|
||||
|
||||
/**
|
||||
* Replaces any invalid characters from a parameter name.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import type { Model } from '../../../client/interfaces/Model';
|
||||
import { reservedWords } from '../../../utils/reservedWords';
|
||||
import type { OpenApi } from '../interfaces/OpenApi';
|
||||
import { getModel } from './getModel';
|
||||
import { reservedWords } from './getOperationParameterName';
|
||||
import { getType } from './getType';
|
||||
|
||||
export const getModels = (openApi: OpenApi): Model[] => {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import camelCase from 'camelcase';
|
||||
|
||||
export const reservedWords =
|
||||
/^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
|
||||
import { reservedWords } from '../../../utils/reservedWords';
|
||||
|
||||
/**
|
||||
* Replaces any invalid characters from a parameter name.
|
||||
|
||||
@ -21,15 +21,13 @@ export interface OnCancel {
|
||||
}
|
||||
|
||||
export class CancelablePromise<T> implements Promise<T> {
|
||||
readonly [Symbol.toStringTag]!: string;
|
||||
|
||||
private _isResolved: boolean;
|
||||
private _isRejected: boolean;
|
||||
private _isCancelled: boolean;
|
||||
private readonly _cancelHandlers: (() => void)[];
|
||||
private readonly _promise: Promise<T>;
|
||||
private _resolve?: (value: T | PromiseLike<T>) => void;
|
||||
private _reject?: (reason?: any) => void;
|
||||
#isResolved: boolean;
|
||||
#isRejected: boolean;
|
||||
#isCancelled: boolean;
|
||||
readonly #cancelHandlers: (() => void)[];
|
||||
readonly #promise: Promise<T>;
|
||||
#resolve?: (value: T | PromiseLike<T>) => void;
|
||||
#reject?: (reason?: any) => void;
|
||||
|
||||
constructor(
|
||||
executor: (
|
||||
@ -38,78 +36,82 @@ export class CancelablePromise<T> implements Promise<T> {
|
||||
onCancel: OnCancel
|
||||
) => void
|
||||
) {
|
||||
this._isResolved = false;
|
||||
this._isRejected = false;
|
||||
this._isCancelled = false;
|
||||
this._cancelHandlers = [];
|
||||
this._promise = new Promise<T>((resolve, reject) => {
|
||||
this._resolve = resolve;
|
||||
this._reject = reject;
|
||||
this.#isResolved = false;
|
||||
this.#isRejected = false;
|
||||
this.#isCancelled = false;
|
||||
this.#cancelHandlers = [];
|
||||
this.#promise = new Promise<T>((resolve, reject) => {
|
||||
this.#resolve = resolve;
|
||||
this.#reject = reject;
|
||||
|
||||
const onResolve = (value: T | PromiseLike<T>): void => {
|
||||
if (this._isResolved || this._isRejected || this._isCancelled) {
|
||||
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
|
||||
return;
|
||||
}
|
||||
this._isResolved = true;
|
||||
this._resolve?.(value);
|
||||
this.#isResolved = true;
|
||||
this.#resolve?.(value);
|
||||
};
|
||||
|
||||
const onReject = (reason?: any): void => {
|
||||
if (this._isResolved || this._isRejected || this._isCancelled) {
|
||||
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
|
||||
return;
|
||||
}
|
||||
this._isRejected = true;
|
||||
this._reject?.(reason);
|
||||
this.#isRejected = true;
|
||||
this.#reject?.(reason);
|
||||
};
|
||||
|
||||
const onCancel = (cancelHandler: () => void): void => {
|
||||
if (this._isResolved || this._isRejected || this._isCancelled) {
|
||||
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
|
||||
return;
|
||||
}
|
||||
this._cancelHandlers.push(cancelHandler);
|
||||
this.#cancelHandlers.push(cancelHandler);
|
||||
};
|
||||
|
||||
Object.defineProperty(onCancel, 'isResolved', {
|
||||
get: (): boolean => this._isResolved,
|
||||
get: (): boolean => this.#isResolved,
|
||||
});
|
||||
|
||||
Object.defineProperty(onCancel, 'isRejected', {
|
||||
get: (): boolean => this._isRejected,
|
||||
get: (): boolean => this.#isRejected,
|
||||
});
|
||||
|
||||
Object.defineProperty(onCancel, 'isCancelled', {
|
||||
get: (): boolean => this._isCancelled,
|
||||
get: (): boolean => this.#isCancelled,
|
||||
});
|
||||
|
||||
return executor(onResolve, onReject, onCancel as OnCancel);
|
||||
});
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
return "Cancellable Promise";
|
||||
}
|
||||
|
||||
public then<TResult1 = T, TResult2 = never>(
|
||||
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
|
||||
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
||||
): Promise<TResult1 | TResult2> {
|
||||
return this._promise.then(onFulfilled, onRejected);
|
||||
return this.#promise.then(onFulfilled, onRejected);
|
||||
}
|
||||
|
||||
public catch<TResult = never>(
|
||||
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
|
||||
): Promise<T | TResult> {
|
||||
return this._promise.catch(onRejected);
|
||||
return this.#promise.catch(onRejected);
|
||||
}
|
||||
|
||||
public finally(onFinally?: (() => void) | null): Promise<T> {
|
||||
return this._promise.finally(onFinally);
|
||||
return this.#promise.finally(onFinally);
|
||||
}
|
||||
|
||||
public cancel(): void {
|
||||
if (this._isResolved || this._isRejected || this._isCancelled) {
|
||||
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
|
||||
return;
|
||||
}
|
||||
this._isCancelled = true;
|
||||
if (this._cancelHandlers.length) {
|
||||
this.#isCancelled = true;
|
||||
if (this.#cancelHandlers.length) {
|
||||
try {
|
||||
for (const cancelHandler of this._cancelHandlers) {
|
||||
for (const cancelHandler of this.#cancelHandlers) {
|
||||
cancelHandler();
|
||||
}
|
||||
} catch (error) {
|
||||
@ -117,11 +119,11 @@ export class CancelablePromise<T> implements Promise<T> {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._cancelHandlers.length = 0;
|
||||
this._reject?.(new CancelError('Request aborted'));
|
||||
this.#cancelHandlers.length = 0;
|
||||
this.#reject?.(new CancelError('Request aborted'));
|
||||
}
|
||||
|
||||
public get isCancelled(): boolean {
|
||||
return this._isCancelled;
|
||||
return this.#isCancelled;
|
||||
}
|
||||
}
|
||||
|
||||
2
src/utils/reservedWords.ts
Normal file
2
src/utils/reservedWords.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export const reservedWords =
|
||||
/^(arguments|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|eval|export|extends|false|finally|for|function|if|implements|import|in|instanceof|interface|let|new|null|package|private|protected|public|return|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)$/g;
|
||||
File diff suppressed because it is too large
Load Diff
@ -15,7 +15,6 @@ describe('v2', () => {
|
||||
exportSchemas: true,
|
||||
exportModels: true,
|
||||
exportServices: true,
|
||||
postfixModels: 'Dto',
|
||||
});
|
||||
|
||||
sync('./test/generated/v2/**/*.ts').forEach(file => {
|
||||
@ -37,7 +36,6 @@ describe('v3', () => {
|
||||
exportSchemas: true,
|
||||
exportModels: true,
|
||||
exportServices: true,
|
||||
postfixModels: 'Dto',
|
||||
});
|
||||
|
||||
sync('./test/generated/v3/**/*.ts').forEach(file => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user