mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Fixed issue with non string values in x-enum flags
This commit is contained in:
parent
a45e1b1586
commit
2f8ae47c2a
@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
|
||||
### Fixed
|
||||
- Support enums with single quotes in names
|
||||
- Generating better names when `operationId` is not given (breaking change)
|
||||
- Fixed issue where `x-enum` flags where breaking due to non-string values
|
||||
|
||||
## [0.19.0] - 2022-02-02
|
||||
### Added
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import type { Enum } from '../../../client/interfaces/Enum';
|
||||
import { isString } from '../../../utils/isString';
|
||||
import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtension';
|
||||
|
||||
/**
|
||||
@ -8,12 +9,12 @@ import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtensi
|
||||
* @param definition
|
||||
*/
|
||||
export const extendEnum = (enumerators: Enum[], definition: WithEnumExtension): Enum[] => {
|
||||
const names = definition['x-enum-varnames'];
|
||||
const descriptions = definition['x-enum-descriptions'];
|
||||
const names = definition['x-enum-varnames']?.filter(isString);
|
||||
const descriptions = definition['x-enum-descriptions']?.filter(isString);
|
||||
|
||||
return enumerators.map((enumerator, index) => ({
|
||||
name: names?.[index] || enumerator.name,
|
||||
description: descriptions?.[index] || enumerator.description,
|
||||
description: JSON.stringify(descriptions?.[index] || enumerator.description),
|
||||
value: enumerator.value,
|
||||
type: enumerator.type,
|
||||
}));
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import type { Enum } from '../../../client/interfaces/Enum';
|
||||
import { isString } from '../../../utils/isString';
|
||||
import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtension';
|
||||
|
||||
/**
|
||||
@ -8,8 +9,8 @@ import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtensi
|
||||
* @param definition
|
||||
*/
|
||||
export const extendEnum = (enumerators: Enum[], definition: WithEnumExtension): Enum[] => {
|
||||
const names = definition['x-enum-varnames'];
|
||||
const descriptions = definition['x-enum-descriptions'];
|
||||
const names = definition['x-enum-varnames']?.filter(isString);
|
||||
const descriptions = definition['x-enum-descriptions']?.filter(isString);
|
||||
|
||||
return enumerators.map((enumerator, index) => ({
|
||||
name: names?.[index] || enumerator.name,
|
||||
|
||||
@ -11,7 +11,7 @@ export enum {{{name}}} {
|
||||
*/
|
||||
{{/if}}
|
||||
{{#containsSpaces name}}
|
||||
"{{{name}}}" = {{{value}}},
|
||||
'{{{name}}}' = {{{value}}},
|
||||
{{else}}
|
||||
{{{name}}} = {{{value}}},
|
||||
{{/containsSpaces}}
|
||||
|
||||
@ -890,15 +890,15 @@ exports[`v2 should generate: ./test/generated/v2/models/EnumWithExtensions.ts 1`
|
||||
*/
|
||||
export enum EnumWithExtensions {
|
||||
/**
|
||||
* Used when the status of something is successful
|
||||
* \\"Used when the status of something is successful\\"
|
||||
*/
|
||||
CUSTOM_SUCCESS = 200,
|
||||
/**
|
||||
* Used when the status of something has a warning
|
||||
* \\"Used when the status of something has a warning\\"
|
||||
*/
|
||||
CUSTOM_WARNING = 400,
|
||||
/**
|
||||
* Used when the status of something has an error
|
||||
* \\"Used when the status of something has an error\\"
|
||||
*/
|
||||
CUSTOM_ERROR = 500,
|
||||
}"
|
||||
@ -913,20 +913,65 @@ exports[`v2 should generate: ./test/generated/v2/models/EnumWithNumbers.ts 1`] =
|
||||
* This is a simple enum with numbers
|
||||
*/
|
||||
export enum EnumWithNumbers {
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_1' = 1,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_2' = 2,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_3' = 3,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_1.1' = 1.1,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_1.2' = 1.2,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_1.3' = 1.3,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_100' = 100,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_200' = 200,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_300' = 300,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_-100' = -100,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_-200' = -200,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_-300' = -300,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_-1.1' = -1.1,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_-1.2' = -1.2,
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
'_-1.3' = -1.3,
|
||||
}"
|
||||
`;
|
||||
@ -940,10 +985,25 @@ exports[`v2 should generate: ./test/generated/v2/models/EnumWithStrings.ts 1`] =
|
||||
* This is a simple enum with strings
|
||||
*/
|
||||
export enum EnumWithStrings {
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
SUCCESS = 'Success',
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
WARNING = 'Warning',
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
ERROR = 'Error',
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
_SINGLE_QUOTE_ = ''Single Quote'',
|
||||
/**
|
||||
* null
|
||||
*/
|
||||
_DOUBLE_QUOTES_ = '\\"Double Quotes\\"',
|
||||
}"
|
||||
`;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user