mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Fixed #226
This commit is contained in:
parent
8a3102b0b1
commit
a16dacaa95
@ -10,14 +10,18 @@ export function getEnum(values?: (string | number)[]): Enum[] {
|
||||
.map(value => {
|
||||
if (typeof value === 'number') {
|
||||
return {
|
||||
name: `NUM_${value}`,
|
||||
name: `$${value}`,
|
||||
value: String(value),
|
||||
type: PrimaryType.NUMBER,
|
||||
description: null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: value.replace(/([a-z])([A-Z]+)/g, '$1_$2').toUpperCase(),
|
||||
name: value
|
||||
.replace(/\W+/g, '_')
|
||||
.replace(/^(\d+)/g, s => `$${s}`)
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
.toUpperCase(),
|
||||
value: `'${value}'`,
|
||||
type: PrimaryType.STRING,
|
||||
description: null,
|
||||
|
||||
@ -14,7 +14,11 @@ export function getEnumFromDescription(description: string): Enum[] {
|
||||
const value = parseInt(match.split('=')[1].replace(/[^0-9]/g, ''));
|
||||
if (name && Number.isInteger(value)) {
|
||||
symbols.push({
|
||||
name: name.replace(/([a-z])([A-Z]+)/g, '$1_$2').toUpperCase(),
|
||||
name: name
|
||||
.replace(/\W+/g, '_')
|
||||
.replace(/^(\d+)/g, s => `$${s}`)
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
.toUpperCase(),
|
||||
value: String(value),
|
||||
type: PrimaryType.NUMBER,
|
||||
description: null,
|
||||
|
||||
@ -10,14 +10,18 @@ export function getEnum(values?: (string | number)[]): Enum[] {
|
||||
.map(value => {
|
||||
if (typeof value === 'number') {
|
||||
return {
|
||||
name: `NUM_${value}`,
|
||||
name: `$${value}`,
|
||||
value: String(value),
|
||||
type: PrimaryType.NUMBER,
|
||||
description: null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: value.replace(/([a-z])([A-Z]+)/g, '$1_$2').toUpperCase(),
|
||||
name: value
|
||||
.replace(/\W+/g, '_')
|
||||
.replace(/^(\d+)/g, s => `$${s}`)
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
.toUpperCase(),
|
||||
value: `'${value}'`,
|
||||
type: PrimaryType.STRING,
|
||||
description: null,
|
||||
|
||||
@ -14,7 +14,11 @@ export function getEnumFromDescription(description: string): Enum[] {
|
||||
const value = parseInt(match.split('=')[1].replace(/[^0-9]/g, ''));
|
||||
if (name && Number.isInteger(value)) {
|
||||
symbols.push({
|
||||
name: name.replace(/([a-z])([A-Z]+)/g, '$1_$2').toUpperCase(),
|
||||
name: name
|
||||
.replace(/\W+/g, '_')
|
||||
.replace(/^(\d+)/g, s => `$${s}`)
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
.toUpperCase(),
|
||||
value: String(value),
|
||||
type: PrimaryType.NUMBER,
|
||||
description: null,
|
||||
|
||||
@ -55,7 +55,6 @@ export function writeClient(
|
||||
copySupportFile('core/getFormData.ts', outputPath);
|
||||
copySupportFile('core/getQueryString.ts', outputPath);
|
||||
copySupportFile('core/isSuccess.ts', outputPath);
|
||||
copySupportFile('core/OpenAPI.hbs', outputPath);
|
||||
copySupportFile('core/request.ts', outputPath);
|
||||
copySupportFile('core/RequestOptions.ts', outputPath);
|
||||
copySupportFile('core/requestUsingFetch.ts', outputPath);
|
||||
|
||||
@ -791,9 +791,9 @@ exports[`generation v2 file(./test/result/v2/models/EnumWithNumbers.ts): ./test/
|
||||
* This is a simple enum with numbers
|
||||
*/
|
||||
export enum EnumWithNumbers {
|
||||
NUM_1 = 1,
|
||||
NUM_2 = 2,
|
||||
NUM_3 = 3,
|
||||
$1 = 1,
|
||||
$2 = 2,
|
||||
$3 = 3,
|
||||
}"
|
||||
`;
|
||||
|
||||
@ -996,6 +996,10 @@ export interface ModelWithEnum {
|
||||
* This is a simple enum with strings
|
||||
*/
|
||||
test?: ModelWithEnum.test;
|
||||
/**
|
||||
* These are the HTTP error code enums
|
||||
*/
|
||||
statusCode?: ModelWithEnum.statusCode;
|
||||
}
|
||||
|
||||
export namespace ModelWithEnum {
|
||||
@ -1009,6 +1013,18 @@ export namespace ModelWithEnum {
|
||||
ERROR = 'Error',
|
||||
}
|
||||
|
||||
/**
|
||||
* These are the HTTP error code enums
|
||||
*/
|
||||
export enum statusCode {
|
||||
$100 = '100',
|
||||
$200_FOO = '200 FOO',
|
||||
$300_FOO_BAR = '300 FOO_BAR',
|
||||
$400_FOO_BAR = '400 foo-bar',
|
||||
$500_FOO_BAR = '500 foo.bar',
|
||||
$600_FOO_BAR = '600 foo&bar',
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
"
|
||||
@ -1640,6 +1656,9 @@ export const $ModelWithEnum = {
|
||||
test: {
|
||||
type: 'Enum',
|
||||
},
|
||||
statusCode: {
|
||||
type: 'Enum',
|
||||
},
|
||||
},
|
||||
};"
|
||||
`;
|
||||
@ -3413,9 +3432,9 @@ exports[`generation v3 file(./test/result/v3/models/EnumWithNumbers.ts): ./test/
|
||||
* This is a simple enum with numbers
|
||||
*/
|
||||
export enum EnumWithNumbers {
|
||||
NUM_1 = 1,
|
||||
NUM_2 = 2,
|
||||
NUM_3 = 3,
|
||||
$1 = 1,
|
||||
$2 = 2,
|
||||
$3 = 3,
|
||||
}"
|
||||
`;
|
||||
|
||||
@ -3639,7 +3658,11 @@ export interface ModelWithEnum {
|
||||
/**
|
||||
* This is a simple enum with strings
|
||||
*/
|
||||
Test?: ModelWithEnum.Test;
|
||||
test?: ModelWithEnum.test;
|
||||
/**
|
||||
* These are the HTTP error code enums
|
||||
*/
|
||||
statusCode?: ModelWithEnum.statusCode;
|
||||
}
|
||||
|
||||
export namespace ModelWithEnum {
|
||||
@ -3647,12 +3670,24 @@ export namespace ModelWithEnum {
|
||||
/**
|
||||
* This is a simple enum with strings
|
||||
*/
|
||||
export enum Test {
|
||||
export enum test {
|
||||
SUCCESS = 'Success',
|
||||
WARNING = 'Warning',
|
||||
ERROR = 'Error',
|
||||
}
|
||||
|
||||
/**
|
||||
* These are the HTTP error code enums
|
||||
*/
|
||||
export enum statusCode {
|
||||
$100 = '100',
|
||||
$200_FOO = '200 FOO',
|
||||
$300_FOO_BAR = '300 FOO_BAR',
|
||||
$400_FOO_BAR = '400 foo-bar',
|
||||
$500_FOO_BAR = '500 foo.bar',
|
||||
$600_FOO_BAR = '600 foo&bar',
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
"
|
||||
@ -3672,7 +3707,7 @@ export interface ModelWithEnumFromDescription {
|
||||
/**
|
||||
* Success=1,Warning=2,Error=3
|
||||
*/
|
||||
Test?: ModelWithEnumFromDescription.Test;
|
||||
test?: ModelWithEnumFromDescription.test;
|
||||
}
|
||||
|
||||
export namespace ModelWithEnumFromDescription {
|
||||
@ -3680,7 +3715,7 @@ export namespace ModelWithEnumFromDescription {
|
||||
/**
|
||||
* Success=1,Warning=2,Error=3
|
||||
*/
|
||||
export enum Test {
|
||||
export enum test {
|
||||
SUCCESS = 1,
|
||||
WARNING = 2,
|
||||
ERROR = 3,
|
||||
@ -4319,7 +4354,10 @@ exports[`generation v3 file(./test/result/v3/schemas/$ModelWithEnum.ts): ./test/
|
||||
|
||||
export const $ModelWithEnum = {
|
||||
properties: {
|
||||
Test: {
|
||||
test: {
|
||||
type: 'Enum',
|
||||
},
|
||||
statusCode: {
|
||||
type: 'Enum',
|
||||
},
|
||||
},
|
||||
@ -4334,7 +4372,7 @@ exports[`generation v3 file(./test/result/v3/schemas/$ModelWithEnumFromDescripti
|
||||
|
||||
export const $ModelWithEnumFromDescription = {
|
||||
properties: {
|
||||
Test: {
|
||||
test: {
|
||||
type: 'Enum',
|
||||
},
|
||||
},
|
||||
|
||||
@ -862,6 +862,17 @@
|
||||
"Warning",
|
||||
"Error"
|
||||
]
|
||||
},
|
||||
"statusCode": {
|
||||
"description": "These are the HTTP error code enums",
|
||||
"enum": [
|
||||
"100",
|
||||
"200 FOO",
|
||||
"300 FOO_BAR",
|
||||
"400 foo-bar",
|
||||
"500 foo.bar",
|
||||
"600 foo&bar"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -1304,13 +1304,24 @@
|
||||
"description": "This is a model with one enum",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Test": {
|
||||
"test": {
|
||||
"description": "This is a simple enum with strings",
|
||||
"enum": [
|
||||
"Success",
|
||||
"Warning",
|
||||
"Error"
|
||||
]
|
||||
},
|
||||
"statusCode": {
|
||||
"description": "These are the HTTP error code enums",
|
||||
"enum": [
|
||||
"100",
|
||||
"200 FOO",
|
||||
"300 FOO_BAR",
|
||||
"400 foo-bar",
|
||||
"500 foo.bar",
|
||||
"600 foo&bar"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -1318,7 +1329,7 @@
|
||||
"description": "This is a model with one enum",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Test": {
|
||||
"test": {
|
||||
"type": "integer",
|
||||
"description": "Success=1,Warning=2,Error=3"
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user