mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2026-02-01 16:46:58 +00:00
Return undefined in most cases to support noImplicitReturns rule
Filter out wrong enum values
This commit is contained in:
parent
93d57da3f6
commit
05d5962144
@ -1,6 +1,12 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.20.2] - 2022-02-25
|
||||
### Fixed
|
||||
- Return `undefined` to match `noImplicitReturns` rule
|
||||
- Made `BaseHttpRequest` class abstract
|
||||
- Filter out wrong enum values
|
||||
|
||||
## [0.20.1] - 2022-02-25
|
||||
### Fixed
|
||||
- Support enums with single quotes in names for V2
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import type { Enum } from '../../../client/interfaces/Enum';
|
||||
import { isDefined } from '../../../utils/isDefined';
|
||||
|
||||
export const getEnum = (values?: (string | number)[]): Enum[] => {
|
||||
if (Array.isArray(values)) {
|
||||
@ -7,7 +6,9 @@ export const getEnum = (values?: (string | number)[]): Enum[] => {
|
||||
.filter((value, index, arr) => {
|
||||
return arr.indexOf(value) === index;
|
||||
})
|
||||
.filter(isDefined)
|
||||
.filter((value: any) => {
|
||||
return typeof value === 'number' || typeof value === 'string';
|
||||
})
|
||||
.map(value => {
|
||||
if (typeof value === 'number') {
|
||||
return {
|
||||
@ -23,7 +24,7 @@ export const getEnum = (values?: (string | number)[]): Enum[] => {
|
||||
.replace(/^(\d+)/g, '_$1')
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
.toUpperCase(),
|
||||
value: `'${value.replace(/'/g, "\\'")}'`,
|
||||
value: `'${value.replace(/'/g, '\\\'')}'`,
|
||||
type: 'string',
|
||||
description: null,
|
||||
};
|
||||
|
||||
@ -6,7 +6,7 @@ export const getOperationParameterDefault = (
|
||||
operationParameter: OperationParameter
|
||||
): string | undefined => {
|
||||
if (parameter.default === undefined) {
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (parameter.default === null) {
|
||||
@ -38,5 +38,5 @@ export const getOperationParameterDefault = (
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import type { Enum } from '../../../client/interfaces/Enum';
|
||||
import { isDefined } from '../../../utils/isDefined';
|
||||
|
||||
export const getEnum = (values?: (string | number)[]): Enum[] => {
|
||||
if (Array.isArray(values)) {
|
||||
@ -7,7 +6,9 @@ export const getEnum = (values?: (string | number)[]): Enum[] => {
|
||||
.filter((value, index, arr) => {
|
||||
return arr.indexOf(value) === index;
|
||||
})
|
||||
.filter(isDefined)
|
||||
.filter((value: any) => {
|
||||
return typeof value === 'number' || typeof value === 'string';
|
||||
})
|
||||
.map(value => {
|
||||
if (typeof value === 'number') {
|
||||
return {
|
||||
@ -23,7 +24,7 @@ export const getEnum = (values?: (string | number)[]): Enum[] => {
|
||||
.replace(/^(\d+)/g, '_$1')
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
.toUpperCase(),
|
||||
value: `'${value.replace(/'/g, "\\'")}'`,
|
||||
value: `'${value.replace(/'/g, '\\\'')}'`,
|
||||
type: 'string',
|
||||
description: null,
|
||||
};
|
||||
|
||||
@ -3,7 +3,7 @@ import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
|
||||
|
||||
export const getModelDefault = (definition: OpenApiSchema, model?: Model): string | undefined => {
|
||||
if (definition.default === undefined) {
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (definition.default === null) {
|
||||
@ -35,5 +35,5 @@ export const getModelDefault = (definition: OpenApiSchema, model?: Model): strin
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -8,5 +8,5 @@ const getRequestBody = (options: ApiRequestOptions): any => {
|
||||
return JSON.stringify(options.body);
|
||||
}
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -2,5 +2,5 @@ const getResponseBody = <T>(response: HttpResponse<T>): T | undefined => {
|
||||
if (response.status !== 204 && response.body !== null) {
|
||||
return response.body;
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -2,5 +2,5 @@ const getRequestBody = (options: ApiRequestOptions): any => {
|
||||
if (options.body) {
|
||||
return options.body;
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -2,5 +2,5 @@ const getResponseBody = (response: AxiosResponse<any>): any => {
|
||||
if (response.status !== 204) {
|
||||
return response.data;
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -8,5 +8,5 @@ const getRequestBody = (options: ApiRequestOptions): any => {
|
||||
return JSON.stringify(options.body);
|
||||
}
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -14,5 +14,5 @@ const getResponseBody = async (response: Response): Promise<any> => {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -8,5 +8,5 @@ const getRequestBody = (options: ApiRequestOptions): any => {
|
||||
return JSON.stringify(options.body);
|
||||
}
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -14,5 +14,5 @@ const getResponseBody = async (response: Response): Promise<any> => {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -9,5 +9,5 @@ const getRequestBody = (options: ApiRequestOptions): any => {
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -14,5 +14,5 @@ const getResponseBody = (xhr: XMLHttpRequest): any => {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -27,7 +27,7 @@ export const findOneOfParentDiscriminator = (openApi: OpenApi, parent?: Model):
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const mapPropertyValue = (discriminator: OpenApiDiscriminator, parent: Model): string => {
|
||||
|
||||
@ -410,7 +410,7 @@ const getRequestBody = (options: ApiRequestOptions): any => {
|
||||
return JSON.stringify(options.body);
|
||||
}
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const sendRequest = async (
|
||||
@ -466,7 +466,7 @@ const getResponseBody = async (response: Response): Promise<any> => {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
|
||||
@ -3421,7 +3421,7 @@ const getRequestBody = (options: ApiRequestOptions): any => {
|
||||
return JSON.stringify(options.body);
|
||||
}
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const sendRequest = async (
|
||||
@ -3477,7 +3477,7 @@ const getResponseBody = async (response: Response): Promise<any> => {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
return;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user