mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2026-01-25 16:02:59 +00:00
commit
d290592d0e
@ -1,5 +0,0 @@
|
||||
dist
|
||||
samples
|
||||
test/generated
|
||||
test/e2e/generated
|
||||
node_modules
|
||||
@ -1,25 +0,0 @@
|
||||
{
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"extends": ["plugin:@typescript-eslint/recommended", "plugin:prettier/recommended", "prettier"],
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true,
|
||||
"jest": true
|
||||
},
|
||||
"plugins": ["simple-import-sort"],
|
||||
"rules": {
|
||||
"@typescript-eslint/no-explicit-any": 0,
|
||||
"@typescript-eslint/no-inferrable-types": 0,
|
||||
"@typescript-eslint/no-non-null-assertion": 0,
|
||||
"@typescript-eslint/no-var-requires": 0,
|
||||
"@typescript-eslint/ban-ts-ignore": 0,
|
||||
"@typescript-eslint/ban-ts-comment": 0,
|
||||
"@typescript-eslint/explicit-function-return-type": 0,
|
||||
"@typescript-eslint/explicit-module-boundary-types": 0,
|
||||
"sort-imports": "off",
|
||||
"import/order": "off",
|
||||
"simple-import-sort/imports": "error",
|
||||
"simple-import-sort/exports": "error",
|
||||
"prettier/prettier": ["error"]
|
||||
}
|
||||
}
|
||||
13
.github/dependabot.yml
vendored
13
.github/dependabot.yml
vendored
@ -5,18 +5,7 @@ updates:
|
||||
schedule:
|
||||
interval: "daily"
|
||||
ignore:
|
||||
- dependency-name: "@apidevtools/json-schema-ref-parser"
|
||||
- dependency-name: "@types/node-fetch"
|
||||
- dependency-name: "node-fetch"
|
||||
- dependency-name: "camelcase"
|
||||
- dependency-name: "@angular-devkit/build-angular"
|
||||
- dependency-name: "@angular/animations"
|
||||
- dependency-name: "@angular/cli"
|
||||
- dependency-name: "@angular/common"
|
||||
- dependency-name: "@angular/compiler"
|
||||
- dependency-name: "@angular/compiler-cli"
|
||||
- dependency-name: "@angular/core"
|
||||
- dependency-name: "@angular/forms"
|
||||
- dependency-name: "@angular/platform-browser"
|
||||
- dependency-name: "@angular/platform-browser-dynamic"
|
||||
- dependency-name: "@angular/router"
|
||||
- dependency-name: "typescript"
|
||||
43
eslint.config.mjs
Normal file
43
eslint.config.mjs
Normal file
@ -0,0 +1,43 @@
|
||||
import javascript from '@eslint/js';
|
||||
import prettierConfig from 'eslint-plugin-prettier/recommended';
|
||||
import simpleImportSort from 'eslint-plugin-simple-import-sort';
|
||||
import globals from 'globals';
|
||||
import typescript from 'typescript-eslint';
|
||||
|
||||
export default [
|
||||
{
|
||||
ignores: ['dist', 'samples', 'test/generated', 'test/e2e/generated', 'node_modules'],
|
||||
},
|
||||
javascript.configs.recommended,
|
||||
...typescript.configs.recommended,
|
||||
prettierConfig,
|
||||
{
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.browser,
|
||||
...globals.jest,
|
||||
...globals.es2019,
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
'simple-import-sort': simpleImportSort,
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/no-explicit-any': 0,
|
||||
'@typescript-eslint/no-inferrable-types': 0,
|
||||
'@typescript-eslint/no-non-null-assertion': 0,
|
||||
'@typescript-eslint/no-var-requires': 0,
|
||||
'@typescript-eslint/no-require-imports': 0,
|
||||
'@typescript-eslint/ban-ts-ignore': 0,
|
||||
'@typescript-eslint/ban-ts-comment': 0,
|
||||
'@typescript-eslint/explicit-function-return-type': 0,
|
||||
'@typescript-eslint/explicit-module-boundary-types': 0,
|
||||
'sort-imports': 'off',
|
||||
'import/order': 'off',
|
||||
'simple-import-sort/imports': 'error',
|
||||
'simple-import-sort/exports': 'error',
|
||||
'prettier/prettier': ['error'],
|
||||
},
|
||||
},
|
||||
];
|
||||
13591
package-lock.json
generated
13591
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
108
package.json
108
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openapi-typescript-codegen",
|
||||
"version": "0.29.0",
|
||||
"version": "0.30.0",
|
||||
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
|
||||
"author": "Ferdi Koomen",
|
||||
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",
|
||||
@ -60,69 +60,67 @@
|
||||
"docker": "docker build -t eeelenbaas/openapi-typescript-codegen ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@apidevtools/json-schema-ref-parser": "^11.5.4",
|
||||
"@apidevtools/json-schema-ref-parser": "^14.2.1",
|
||||
"camelcase": "^6.3.0",
|
||||
"commander": "^12.0.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"commander": "^14.0.2",
|
||||
"fs-extra": "^11.3.3",
|
||||
"handlebars": "^4.7.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "20.3.10",
|
||||
"@angular/animations": "17.3.3",
|
||||
"@angular/cli": "20.2.2",
|
||||
"@angular/common": "17.3.3",
|
||||
"@angular/compiler": "17.3.3",
|
||||
"@angular/compiler-cli": "17.3.3",
|
||||
"@angular/core": "17.3.3",
|
||||
"@angular/forms": "17.3.3",
|
||||
"@angular/platform-browser": "17.3.3",
|
||||
"@angular/platform-browser-dynamic": "17.3.3",
|
||||
"@angular/router": "17.3.3",
|
||||
"@babel/cli": "7.24.8",
|
||||
"@babel/core": "7.26.7",
|
||||
"@babel/preset-env": "7.26.0",
|
||||
"@babel/preset-typescript": "7.24.7",
|
||||
"@rollup/plugin-commonjs": "25.0.8",
|
||||
"@rollup/plugin-node-resolve": "15.2.3",
|
||||
"@rollup/plugin-terser": "^0.4.4",
|
||||
"@rollup/plugin-typescript": "11.1.6",
|
||||
"@angular-devkit/build-angular": "21.0.4",
|
||||
"@angular/animations": "21.0.6",
|
||||
"@angular/cli": "21.0.4",
|
||||
"@angular/common": "21.0.6",
|
||||
"@angular/compiler": "21.0.6",
|
||||
"@angular/compiler-cli": "21.0.6",
|
||||
"@angular/core": "21.0.6",
|
||||
"@angular/forms": "21.0.6",
|
||||
"@angular/platform-browser": "21.0.6",
|
||||
"@angular/platform-browser-dynamic": "21.0.6",
|
||||
"@angular/router": "21.0.6",
|
||||
"@babel/cli": "7.28.3",
|
||||
"@babel/core": "7.28.5",
|
||||
"@babel/preset-env": "7.28.5",
|
||||
"@babel/preset-typescript": "7.28.5",
|
||||
"@eslint/js": "9.39.2",
|
||||
"@rollup/plugin-commonjs": "29.0.0",
|
||||
"@rollup/plugin-node-resolve": "16.0.3",
|
||||
"@rollup/plugin-terser": "0.4.4",
|
||||
"@rollup/plugin-typescript": "12.3.0",
|
||||
"@types/cross-spawn": "6.0.6",
|
||||
"@types/express": "4.17.21",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/glob": "8.1.0",
|
||||
"@types/jest": "29.5.12",
|
||||
"@types/node": "20.14.10",
|
||||
"@types/node-fetch": "2.6.11",
|
||||
"@types/qs": "6.9.15",
|
||||
"@typescript-eslint/eslint-plugin": "7.16.0",
|
||||
"@typescript-eslint/parser": "7.18.0",
|
||||
"@types/express": "5.0.6",
|
||||
"@types/fs-extra": "11.0.4",
|
||||
"@types/jest": "30.0.0",
|
||||
"@types/node": "25.0.3",
|
||||
"@types/node-fetch": "2.6.13",
|
||||
"@types/qs": "6.14.0",
|
||||
"@typescript-eslint/eslint-plugin": "8.50.1",
|
||||
"@typescript-eslint/parser": "8.50.1",
|
||||
"abort-controller": "3.0.0",
|
||||
"axios": "1.8.2",
|
||||
"axios": "1.13.2",
|
||||
"codecov": "3.8.3",
|
||||
"cross-spawn": "7.0.3",
|
||||
"eslint": "8.57.0",
|
||||
"eslint-config-prettier": "9.1.0",
|
||||
"eslint-plugin-prettier": "5.1.3",
|
||||
"cross-spawn": "7.0.6",
|
||||
"eslint": "9.39.2",
|
||||
"eslint-config-prettier": "10.1.8",
|
||||
"eslint-plugin-prettier": "5.5.4",
|
||||
"eslint-plugin-simple-import-sort": "12.1.1",
|
||||
"express": "4.22.0",
|
||||
"form-data": "4.0.4",
|
||||
"glob": "12.0.0",
|
||||
"jest": "29.7.0",
|
||||
"jest-cli": "29.7.0",
|
||||
"express": "5.2.1",
|
||||
"form-data": "4.0.5",
|
||||
"globals": "16.5.0",
|
||||
"glob": "13.0.0",
|
||||
"jest": "30.2.0",
|
||||
"jest-cli": "30.2.0",
|
||||
"node-fetch": "2.7.0",
|
||||
"prettier": "3.4.1",
|
||||
"puppeteer": "22.14.0",
|
||||
"qs": "6.12.3",
|
||||
"rimraf": "6.1.0",
|
||||
"rollup": "4.14.0",
|
||||
"rxjs": "7.8.1",
|
||||
"prettier": "3.7.4",
|
||||
"puppeteer": "24.34.0",
|
||||
"qs": "6.14.0",
|
||||
"rimraf": "6.1.2",
|
||||
"rollup": "4.54.0",
|
||||
"rxjs": "7.8.2",
|
||||
"ts-node": "10.9.2",
|
||||
"tslib": "2.6.3",
|
||||
"typescript": "5.4.4",
|
||||
"zone.js": "0.15.0"
|
||||
},
|
||||
"overrides": {
|
||||
"node-fetch": "2.7.0",
|
||||
"rollup": "4.14.0"
|
||||
"tslib": "2.8.1",
|
||||
"typescript": "5.9.3",
|
||||
"typescript-eslint": "8.50.1",
|
||||
"zone.js": "0.16.0"
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ export type GetModelFn = typeof getModel;
|
||||
export const getModelProperties = (openApi: OpenApi, definition: OpenApiSchema, getModel: GetModelFn): Model[] => {
|
||||
const models: Model[] = [];
|
||||
for (const propertyName in definition.properties) {
|
||||
if (definition.properties.hasOwnProperty(propertyName)) {
|
||||
if (Object.prototype.hasOwnProperty.call(definition.properties, propertyName)) {
|
||||
const property = definition.properties[propertyName];
|
||||
const propertyRequired = !!definition.required?.includes(propertyName);
|
||||
if (property.$ref) {
|
||||
|
||||
@ -7,7 +7,7 @@ import { getType } from './getType';
|
||||
export const getModels = (openApi: OpenApi): Model[] => {
|
||||
const models: Model[] = [];
|
||||
for (const definitionName in openApi.definitions) {
|
||||
if (openApi.definitions.hasOwnProperty(definitionName)) {
|
||||
if (Object.prototype.hasOwnProperty.call(openApi.definitions, definitionName)) {
|
||||
const definition = openApi.definitions[definitionName];
|
||||
const definitionType = getType(definitionName);
|
||||
const model = getModel(openApi, definition, true, definitionType.base.replace(reservedWords, '_$1'));
|
||||
|
||||
@ -10,7 +10,7 @@ export const getOperationName = (url: string, method: string, operationId?: stri
|
||||
return camelCase(
|
||||
operationId
|
||||
.replace(/^[^a-zA-Z]+/g, '')
|
||||
.replace(/[^\w\-]+/g, '-')
|
||||
.replace(/[^\w-]+/g, '-')
|
||||
.trim()
|
||||
);
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ export const getOperationParameterDefault = (
|
||||
case 'object':
|
||||
try {
|
||||
return JSON.stringify(parameter.default, null, 4);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import { reservedWords } from '../../../utils/reservedWords';
|
||||
export const getOperationParameterName = (value: string): string => {
|
||||
const clean = value
|
||||
.replace(/^[^a-zA-Z]+/g, '')
|
||||
.replace(/[^\w\-]+/g, '-')
|
||||
.replace(/[^\w-]+/g, '-')
|
||||
.trim();
|
||||
return camelCase(clean).replace(reservedWords, '_$1');
|
||||
};
|
||||
|
||||
@ -85,7 +85,7 @@ export const getOperationResponse = (
|
||||
// fetch and XHR client just support string types.
|
||||
if (response.headers) {
|
||||
for (const name in response.headers) {
|
||||
if (response.headers.hasOwnProperty(name)) {
|
||||
if (Object.prototype.hasOwnProperty.call(response.headers, name)) {
|
||||
operationResponse.in = 'header';
|
||||
operationResponse.name = name;
|
||||
operationResponse.type = 'string';
|
||||
|
||||
@ -12,7 +12,7 @@ export const getOperationResponses = (openApi: OpenApi, responses: OpenApiRespon
|
||||
// Iterate over each response code and get the
|
||||
// status code and response message (if any).
|
||||
for (const code in responses) {
|
||||
if (responses.hasOwnProperty(code)) {
|
||||
if (Object.prototype.hasOwnProperty.call(responses, code)) {
|
||||
const responseOrReference = responses[code];
|
||||
const response = getRef<OpenApiResponse>(openApi, responseOrReference);
|
||||
const responseCode = getOperationResponseCode(code);
|
||||
|
||||
@ -20,7 +20,7 @@ export const getRef = <T>(openApi: OpenApi, item: T & OpenApiReference): T => {
|
||||
const decodedPath = decodeURIComponent(
|
||||
path.replace(ESCAPED_REF_SLASH, '/').replace(ESCAPED_REF_TILDE, '~')
|
||||
);
|
||||
if (result.hasOwnProperty(decodedPath)) {
|
||||
if (Object.prototype.hasOwnProperty.call(result, decodedPath)) {
|
||||
result = result[decodedPath];
|
||||
} else {
|
||||
throw new Error(`Could not find reference: "${item.$ref}"`);
|
||||
|
||||
@ -7,7 +7,7 @@ import camelCase from 'camelcase';
|
||||
export const getServiceName = (value: string): string => {
|
||||
const clean = value
|
||||
.replace(/^[^a-zA-Z]+/g, '')
|
||||
.replace(/[^\w\-]+/g, '-')
|
||||
.replace(/[^\w-]+/g, '-')
|
||||
.trim();
|
||||
return camelCase(clean, { pascalCase: true });
|
||||
};
|
||||
|
||||
@ -10,14 +10,14 @@ import { getOperationParameters } from './getOperationParameters';
|
||||
export const getServices = (openApi: OpenApi): Service[] => {
|
||||
const services = new Map<string, Service>();
|
||||
for (const url in openApi.paths) {
|
||||
if (openApi.paths.hasOwnProperty(url)) {
|
||||
if (Object.prototype.hasOwnProperty.call(openApi.paths, url)) {
|
||||
// Grab path and parse any global path parameters
|
||||
const path = openApi.paths[url];
|
||||
const pathParams = getOperationParameters(openApi, path.parameters || []);
|
||||
|
||||
// Parse all the methods for this path
|
||||
for (const method in path) {
|
||||
if (path.hasOwnProperty(method)) {
|
||||
if (Object.prototype.hasOwnProperty.call(path, method)) {
|
||||
switch (method) {
|
||||
case 'get':
|
||||
case 'put':
|
||||
@ -25,7 +25,7 @@ export const getServices = (openApi: OpenApi): Service[] => {
|
||||
case 'delete':
|
||||
case 'options':
|
||||
case 'head':
|
||||
case 'patch':
|
||||
case 'patch': {
|
||||
// Each method contains an OpenAPI operation, we parse the operation
|
||||
const op = path[method]!;
|
||||
const tags = op.tags?.length ? op.tags.filter(unique) : ['Default'];
|
||||
@ -46,6 +46,7 @@ export const getServices = (openApi: OpenApi): Service[] => {
|
||||
services.set(operation.service, service);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ export const getModelDefault = (definition: OpenApiSchema, model?: Model): strin
|
||||
case 'object':
|
||||
try {
|
||||
return JSON.stringify(definition.default, null, 4);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ export const getModelProperties = (
|
||||
const models: Model[] = [];
|
||||
const discriminator = findOneOfParentDiscriminator(openApi, parent);
|
||||
for (const propertyName in definition.properties) {
|
||||
if (definition.properties.hasOwnProperty(propertyName)) {
|
||||
if (Object.prototype.hasOwnProperty.call(definition.properties, propertyName)) {
|
||||
const property = definition.properties[propertyName];
|
||||
const propertyRequired = !!definition.required?.includes(propertyName);
|
||||
const propertyValues: Omit<
|
||||
|
||||
@ -8,7 +8,7 @@ export const getModels = (openApi: OpenApi): Model[] => {
|
||||
const models: Model[] = [];
|
||||
if (openApi.components) {
|
||||
for (const definitionName in openApi.components.schemas) {
|
||||
if (openApi.components.schemas.hasOwnProperty(definitionName)) {
|
||||
if (Object.prototype.hasOwnProperty.call(openApi.components.schemas, definitionName)) {
|
||||
const definition = openApi.components.schemas[definitionName];
|
||||
const definitionType = getType(definitionName);
|
||||
const model = getModel(openApi, definition, true, definitionType.base.replace(reservedWords, '_$1'));
|
||||
@ -16,7 +16,7 @@ export const getModels = (openApi: OpenApi): Model[] => {
|
||||
}
|
||||
}
|
||||
for (const definitionName in openApi.components.parameters) {
|
||||
if (openApi.components.parameters.hasOwnProperty(definitionName)) {
|
||||
if (Object.prototype.hasOwnProperty.call(openApi.components.parameters, definitionName)) {
|
||||
const definition = openApi.components.parameters[definitionName];
|
||||
const definitionType = getType(definitionName);
|
||||
const schema = definition.schema;
|
||||
|
||||
@ -10,7 +10,7 @@ export const getOperationName = (url: string, method: string, operationId?: stri
|
||||
return camelCase(
|
||||
operationId
|
||||
.replace(/^[^a-zA-Z]+/g, '')
|
||||
.replace(/[^\w\-]+/g, '-')
|
||||
.replace(/[^\w-]+/g, '-')
|
||||
.trim()
|
||||
);
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ export const getOperationParameterName = (value: string): string => {
|
||||
const clean = value
|
||||
.replace(/^[^a-zA-Z]+/g, '')
|
||||
.replace('[]', 'Array')
|
||||
.replace(/[^\w\-]+/g, '-')
|
||||
.replace(/[^\w-]+/g, '-')
|
||||
.trim();
|
||||
return camelCase(clean).replace(reservedWords, '_$1');
|
||||
};
|
||||
|
||||
@ -84,7 +84,7 @@ export const getOperationResponse = (
|
||||
// fetch and XHR client just support string types.
|
||||
if (response.headers) {
|
||||
for (const name in response.headers) {
|
||||
if (response.headers.hasOwnProperty(name)) {
|
||||
if (Object.prototype.hasOwnProperty.call(response.headers, name)) {
|
||||
operationResponse.in = 'header';
|
||||
operationResponse.name = name;
|
||||
operationResponse.type = 'string';
|
||||
|
||||
@ -12,7 +12,7 @@ export const getOperationResponses = (openApi: OpenApi, responses: OpenApiRespon
|
||||
// Iterate over each response code and get the
|
||||
// status code and response message (if any).
|
||||
for (const code in responses) {
|
||||
if (responses.hasOwnProperty(code)) {
|
||||
if (Object.prototype.hasOwnProperty.call(responses, code)) {
|
||||
const responseOrReference = responses[code];
|
||||
const response = getRef<OpenApiResponse>(openApi, responseOrReference);
|
||||
const responseCode = getOperationResponseCode(code);
|
||||
|
||||
@ -20,7 +20,7 @@ export const getRef = <T>(openApi: OpenApi, item: T & OpenApiReference): T => {
|
||||
const decodedPath = decodeURIComponent(
|
||||
path.replace(ESCAPED_REF_SLASH, '/').replace(ESCAPED_REF_TILDE, '~')
|
||||
);
|
||||
if (result.hasOwnProperty(decodedPath)) {
|
||||
if (Object.prototype.hasOwnProperty.call(result, decodedPath)) {
|
||||
result = result[decodedPath];
|
||||
} else {
|
||||
throw new Error(`Could not find reference: "${item.$ref}"`);
|
||||
|
||||
@ -5,7 +5,7 @@ export const getServer = (openApi: OpenApi): string => {
|
||||
const variables = server?.variables || {};
|
||||
let url = server?.url || '';
|
||||
for (const variable in variables) {
|
||||
if (variables.hasOwnProperty(variable)) {
|
||||
if (Object.prototype.hasOwnProperty.call(variables, variable)) {
|
||||
url = url.replace(`{${variable}}`, variables[variable].default);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import camelCase from 'camelcase';
|
||||
export const getServiceName = (value: string): string => {
|
||||
const clean = value
|
||||
.replace(/^[^a-zA-Z]+/g, '')
|
||||
.replace(/[^\w\-]+/g, '-')
|
||||
.replace(/[^\w-]+/g, '-')
|
||||
.trim();
|
||||
return camelCase(clean, { pascalCase: true });
|
||||
};
|
||||
|
||||
@ -10,14 +10,14 @@ import { getOperationParameters } from './getOperationParameters';
|
||||
export const getServices = (openApi: OpenApi): Service[] => {
|
||||
const services = new Map<string, Service>();
|
||||
for (const url in openApi.paths) {
|
||||
if (openApi.paths.hasOwnProperty(url)) {
|
||||
if (Object.prototype.hasOwnProperty.call(openApi.paths, url)) {
|
||||
// Grab path and parse any global path parameters
|
||||
const path = openApi.paths[url];
|
||||
const pathParams = getOperationParameters(openApi, path.parameters || []);
|
||||
|
||||
// Parse all the methods for this path
|
||||
for (const method in path) {
|
||||
if (path.hasOwnProperty(method)) {
|
||||
if (Object.prototype.hasOwnProperty.call(path, method)) {
|
||||
switch (method) {
|
||||
case 'get':
|
||||
case 'put':
|
||||
@ -25,7 +25,7 @@ export const getServices = (openApi: OpenApi): Service[] => {
|
||||
case 'delete':
|
||||
case 'options':
|
||||
case 'head':
|
||||
case 'patch':
|
||||
case 'patch': {
|
||||
// Each method contains an OpenAPI operation, we parse the operation
|
||||
const op = path[method]!;
|
||||
const tags = op.tags?.length ? op.tags.filter(unique) : ['Default'];
|
||||
@ -46,6 +46,7 @@ export const getServices = (openApi: OpenApi): Service[] => {
|
||||
services.set(operation.service, service);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ const inverseDictionary = (map: Dictionary<string>): Dictionary<string> => {
|
||||
export const findOneOfParentDiscriminator = (openApi: OpenApi, parent?: Model): OpenApiDiscriminator | undefined => {
|
||||
if (openApi.components && parent) {
|
||||
for (const definitionName in openApi.components.schemas) {
|
||||
if (openApi.components.schemas.hasOwnProperty(definitionName)) {
|
||||
if (Object.prototype.hasOwnProperty.call(openApi.components.schemas, definitionName)) {
|
||||
const schema = openApi.components.schemas[definitionName];
|
||||
if (
|
||||
schema.discriminator &&
|
||||
|
||||
@ -10,7 +10,6 @@ describe('getPattern', () => {
|
||||
expect(getPattern('\\')).toEqual('\\\\');
|
||||
expect(getPattern('\\/')).toEqual('\\\\/');
|
||||
expect(getPattern('\\/\\/')).toEqual('\\\\/\\\\/');
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
expect(getPattern("'")).toEqual("\\'");
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,6 +9,5 @@
|
||||
* @param pattern
|
||||
*/
|
||||
export const getPattern = (pattern?: string): string | undefined => {
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
return pattern?.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
||||
};
|
||||
|
||||
@ -13,7 +13,7 @@ export const readSpecFromDisk = async (input: string): Promise<string> => {
|
||||
try {
|
||||
const content = await readFile(filePath, 'utf8');
|
||||
return content.toString();
|
||||
} catch (e) {
|
||||
} catch {
|
||||
throw new Error(`Could not read OpenApi spec: "${filePath}"`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,8 +52,8 @@ describe('writeClient', () => {
|
||||
'AppClient'
|
||||
);
|
||||
|
||||
expect(rmdir).toBeCalled();
|
||||
expect(mkdir).toBeCalled();
|
||||
expect(writeFile).toBeCalled();
|
||||
expect(rmdir).toHaveBeenCalled();
|
||||
expect(mkdir).toHaveBeenCalled();
|
||||
expect(writeFile).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@ -38,6 +38,6 @@ describe('writeClientClass', () => {
|
||||
|
||||
await writeClientClass(client, templates, './dist', HttpClient.FETCH, 'AppClient', Indent.SPACE_4, '');
|
||||
|
||||
expect(writeFile).toBeCalled();
|
||||
expect(writeFile).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@ -41,11 +41,11 @@ describe('writeClientCore', () => {
|
||||
|
||||
await writeClientCore(client, templates, '/', HttpClient.FETCH, Indent.SPACE_4);
|
||||
|
||||
expect(writeFile).toBeCalledWith(resolve('/', '/OpenAPI.ts'), `settings${EOL}`);
|
||||
expect(writeFile).toBeCalledWith(resolve('/', '/ApiError.ts'), `apiError${EOL}`);
|
||||
expect(writeFile).toBeCalledWith(resolve('/', '/ApiRequestOptions.ts'), `apiRequestOptions${EOL}`);
|
||||
expect(writeFile).toBeCalledWith(resolve('/', '/ApiResult.ts'), `apiResult${EOL}`);
|
||||
expect(writeFile).toBeCalledWith(resolve('/', '/CancelablePromise.ts'), `cancelablePromise${EOL}`);
|
||||
expect(writeFile).toBeCalledWith(resolve('/', '/request.ts'), `request${EOL}`);
|
||||
expect(writeFile).toHaveBeenCalledWith(resolve('/', '/OpenAPI.ts'), `settings${EOL}`);
|
||||
expect(writeFile).toHaveBeenCalledWith(resolve('/', '/ApiError.ts'), `apiError${EOL}`);
|
||||
expect(writeFile).toHaveBeenCalledWith(resolve('/', '/ApiRequestOptions.ts'), `apiRequestOptions${EOL}`);
|
||||
expect(writeFile).toHaveBeenCalledWith(resolve('/', '/ApiResult.ts'), `apiResult${EOL}`);
|
||||
expect(writeFile).toHaveBeenCalledWith(resolve('/', '/CancelablePromise.ts'), `cancelablePromise${EOL}`);
|
||||
expect(writeFile).toHaveBeenCalledWith(resolve('/', '/request.ts'), `request${EOL}`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -38,6 +38,6 @@ describe('writeClientIndex', () => {
|
||||
|
||||
await writeClientIndex(client, templates, '/', true, true, true, true, true, 'Service', '');
|
||||
|
||||
expect(writeFile).toBeCalledWith(resolve('/', '/index.ts'), 'index');
|
||||
expect(writeFile).toHaveBeenCalledWith(resolve('/', '/index.ts'), 'index');
|
||||
});
|
||||
});
|
||||
|
||||
@ -54,6 +54,6 @@ describe('writeClientModels', () => {
|
||||
|
||||
await writeClientModels(models, templates, '/', HttpClient.FETCH, false, Indent.SPACE_4);
|
||||
|
||||
expect(writeFile).toBeCalledWith(resolve('/', '/User.ts'), `model${EOL}`);
|
||||
expect(writeFile).toHaveBeenCalledWith(resolve('/', '/User.ts'), `model${EOL}`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -54,6 +54,6 @@ describe('writeClientSchemas', () => {
|
||||
|
||||
await writeClientSchemas(models, templates, '/', HttpClient.FETCH, false, Indent.SPACE_4);
|
||||
|
||||
expect(writeFile).toBeCalledWith(resolve('/', '/$User.ts'), `schema${EOL}`);
|
||||
expect(writeFile).toHaveBeenCalledWith(resolve('/', '/$User.ts'), `schema${EOL}`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -42,6 +42,6 @@ describe('writeClientServices', () => {
|
||||
|
||||
await writeClientServices(services, templates, '/', HttpClient.FETCH, false, false, Indent.SPACE_4, 'Service');
|
||||
|
||||
expect(writeFile).toBeCalledWith(resolve('/', '/UserService.ts'), `service${EOL}`);
|
||||
expect(writeFile).toHaveBeenCalledWith(resolve('/', '/UserService.ts'), `service${EOL}`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
|
||||
exports[`v2 should generate: test/generated/v2/core/ApiError.ts 1`] = `
|
||||
"/* generated using openapi-typescript-codegen -- do not edit */
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import puppeteer, { Browser, EvaluateFn, Page } from 'puppeteer';
|
||||
import puppeteer, { Browser, EvaluateFunc, Page } from 'puppeteer';
|
||||
|
||||
let _browser: Browser;
|
||||
let _page: Page;
|
||||
@ -8,8 +8,7 @@ const start = async () => {
|
||||
// and load the localhost page, this page will load the
|
||||
// javascript modules (see server.js for more info)
|
||||
_browser = await puppeteer.launch({
|
||||
headless: 'new',
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
||||
headless: true,
|
||||
});
|
||||
_page = await _browser.newPage();
|
||||
// _page.on('console', msg => console.log(msg.text()));
|
||||
@ -19,15 +18,15 @@ const start = async () => {
|
||||
};
|
||||
|
||||
const stop = async () => {
|
||||
await _page.close();
|
||||
await _browser.close();
|
||||
await _page?.close();
|
||||
await _browser?.close();
|
||||
};
|
||||
|
||||
const evaluate = async (fn: EvaluateFn) => {
|
||||
const evaluate = async <T extends unknown[]>(fn: EvaluateFunc<T>) => {
|
||||
return await _page.evaluate(fn);
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||
const exposeFunction = async (name: string, fn: Function) => {
|
||||
return await _page.exposeFunction(name, fn);
|
||||
};
|
||||
|
||||
@ -8,7 +8,7 @@ export const createAngularProject = (dir: string, name: string) => {
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
sync('ng', ['analytics', 'off', '--global'], {
|
||||
sync('ng', ['analytics', 'disable', '--global'], {
|
||||
cwd: resolvePath(cwd),
|
||||
stdio: 'inherit',
|
||||
});
|
||||
@ -18,6 +18,8 @@ export const createAngularProject = (dir: string, name: string) => {
|
||||
[
|
||||
'new',
|
||||
name,
|
||||
'--ai-config',
|
||||
'none',
|
||||
'--minimal',
|
||||
'true',
|
||||
'--style',
|
||||
|
||||
@ -65,7 +65,7 @@ const start = async (dir: string) => {
|
||||
// Register an 'echo' server that just returns all data from the API calls.
|
||||
// Although this might not be a 'correct' response, we can use this to test
|
||||
// the majority of API calls.
|
||||
_app.all('/base/api/v1.0/*', (req, res) => {
|
||||
_app.all('/base/api/v1.0/*path', (req, res) => {
|
||||
setTimeout(() => {
|
||||
res.json({
|
||||
method: req.method,
|
||||
@ -87,7 +87,7 @@ const start = async (dir: string) => {
|
||||
|
||||
const stop = async () => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
_server.close(err => {
|
||||
_server?.close(err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
|
||||
@ -147,6 +147,10 @@ describe('v3.axios', () => {
|
||||
size: 1,
|
||||
sort: ['location'],
|
||||
})) as Promise<any>;
|
||||
expect((result as any).query).toStrictEqual({ parameter: { page: '0', size: '1', sort: 'location' } });
|
||||
expect((result as any).query).toStrictEqual({
|
||||
'parameter[page]': '0',
|
||||
'parameter[size]': '1',
|
||||
'parameter[sort]': 'location',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -177,6 +177,10 @@ describe('v3.babel', () => {
|
||||
},
|
||||
})) as Promise<any>;
|
||||
});
|
||||
expect(result.query).toStrictEqual({ parameter: { page: '0', size: '1', sort: 'location' } });
|
||||
expect(result.query).toStrictEqual({
|
||||
'parameter[page]': '0',
|
||||
'parameter[size]': '1',
|
||||
'parameter[sort]': 'location',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -169,6 +169,10 @@ describe('v3.fetch', () => {
|
||||
sort: ['location'],
|
||||
})) as Promise<any>;
|
||||
});
|
||||
expect(result.query).toStrictEqual({ parameter: { page: '0', size: '1', sort: 'location' } });
|
||||
expect(result.query).toStrictEqual({
|
||||
'parameter[page]': '0',
|
||||
'parameter[size]': '1',
|
||||
'parameter[sort]': 'location',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -147,6 +147,10 @@ describe('v3.node', () => {
|
||||
size: 1,
|
||||
sort: ['location'],
|
||||
})) as Promise<any>;
|
||||
expect((result as any).query).toStrictEqual({ parameter: { page: '0', size: '1', sort: 'location' } });
|
||||
expect((result as any).query).toStrictEqual({
|
||||
'parameter[page]': '0',
|
||||
'parameter[size]': '1',
|
||||
'parameter[sort]': 'location',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -168,6 +168,10 @@ describe('v3.xhr', () => {
|
||||
sort: ['location'],
|
||||
})) as Promise<any>;
|
||||
});
|
||||
expect(result.query).toStrictEqual({ parameter: { page: '0', size: '1', sort: 'location' } });
|
||||
expect(result.query).toStrictEqual({
|
||||
'parameter[page]': '0',
|
||||
'parameter[size]': '1',
|
||||
'parameter[sort]': 'location',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -43,7 +43,7 @@ const generateRealWorldSpecs = async () => {
|
||||
return {
|
||||
name: name
|
||||
.replace(/^[^a-zA-Z]+/g, '')
|
||||
.replace(/[^\w\-]+/g, '-')
|
||||
.replace(/[^\w-]+/g, '-')
|
||||
.trim()
|
||||
.toLowerCase(),
|
||||
url: latestVersion.swaggerYamlUrl || latestVersion.swaggerUrl,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user