mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Fixed prefix value for enums to align with other generators
This commit is contained in:
parent
a16dacaa95
commit
de7b32c391
@ -10,7 +10,7 @@ export function getEnum(values?: (string | number)[]): Enum[] {
|
||||
.map(value => {
|
||||
if (typeof value === 'number') {
|
||||
return {
|
||||
name: `$${value}`,
|
||||
name: `_${value}`,
|
||||
value: String(value),
|
||||
type: PrimaryType.NUMBER,
|
||||
description: null,
|
||||
@ -19,7 +19,7 @@ export function getEnum(values?: (string | number)[]): Enum[] {
|
||||
return {
|
||||
name: value
|
||||
.replace(/\W+/g, '_')
|
||||
.replace(/^(\d+)/g, s => `$${s}`)
|
||||
.replace(/^(\d+)/g, '_$1')
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
.toUpperCase(),
|
||||
value: `'${value}'`,
|
||||
|
||||
@ -16,7 +16,7 @@ export function getEnumFromDescription(description: string): Enum[] {
|
||||
symbols.push({
|
||||
name: name
|
||||
.replace(/\W+/g, '_')
|
||||
.replace(/^(\d+)/g, s => `$${s}`)
|
||||
.replace(/^(\d+)/g, '_$1')
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
.toUpperCase(),
|
||||
value: String(value),
|
||||
|
||||
@ -10,7 +10,7 @@ export function getEnum(values?: (string | number)[]): Enum[] {
|
||||
.map(value => {
|
||||
if (typeof value === 'number') {
|
||||
return {
|
||||
name: `$${value}`,
|
||||
name: `_${value}`,
|
||||
value: String(value),
|
||||
type: PrimaryType.NUMBER,
|
||||
description: null,
|
||||
@ -19,7 +19,7 @@ export function getEnum(values?: (string | number)[]): Enum[] {
|
||||
return {
|
||||
name: value
|
||||
.replace(/\W+/g, '_')
|
||||
.replace(/^(\d+)/g, s => `$${s}`)
|
||||
.replace(/^(\d+)/g, '_$1')
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
.toUpperCase(),
|
||||
value: `'${value}'`,
|
||||
|
||||
@ -16,7 +16,7 @@ export function getEnumFromDescription(description: string): Enum[] {
|
||||
symbols.push({
|
||||
name: name
|
||||
.replace(/\W+/g, '_')
|
||||
.replace(/^(\d+)/g, s => `$${s}`)
|
||||
.replace(/^(\d+)/g, '_$1')
|
||||
.replace(/([a-z])([A-Z]+)/g, '$1_$2')
|
||||
.toUpperCase(),
|
||||
value: String(value),
|
||||
|
||||
@ -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 {
|
||||
$1 = 1,
|
||||
$2 = 2,
|
||||
$3 = 3,
|
||||
_1 = 1,
|
||||
_2 = 2,
|
||||
_3 = 3,
|
||||
}"
|
||||
`;
|
||||
|
||||
@ -1017,12 +1017,12 @@ export namespace ModelWithEnum {
|
||||
* 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',
|
||||
_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',
|
||||
}
|
||||
|
||||
|
||||
@ -3432,9 +3432,9 @@ exports[`generation v3 file(./test/result/v3/models/EnumWithNumbers.ts): ./test/
|
||||
* This is a simple enum with numbers
|
||||
*/
|
||||
export enum EnumWithNumbers {
|
||||
$1 = 1,
|
||||
$2 = 2,
|
||||
$3 = 3,
|
||||
_1 = 1,
|
||||
_2 = 2,
|
||||
_3 = 3,
|
||||
}"
|
||||
`;
|
||||
|
||||
@ -3680,12 +3680,12 @@ export namespace ModelWithEnum {
|
||||
* 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',
|
||||
_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',
|
||||
}
|
||||
|
||||
|
||||
|
||||
11
test/mock/README.md
Normal file
11
test/mock/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
If you want to generate and compare the output of the
|
||||
`openapi-typescript-codegen` vs the official `swagger-codegen`.
|
||||
Then the easiest way to do this is to install the swagger codegen
|
||||
using Homebrew:
|
||||
|
||||
```shell script
|
||||
brew cask install homebrew/cask-versions/adoptopenjdk8
|
||||
brew install swagger-codegen
|
||||
./codegen.sh
|
||||
```
|
||||
|
||||
9
test/mock/codegen.sh
Executable file
9
test/mock/codegen.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
swagger-codegen generate --input-spec v2/spec.json --lang java --output examples/v2/java/
|
||||
swagger-codegen generate --input-spec v2/spec.json --lang typescript-angular --output examples/v2/typescript-angular/
|
||||
swagger-codegen generate --input-spec v2/spec.json --lang javascript --output examples/v2/javascript/
|
||||
|
||||
swagger-codegen generate --input-spec v3/spec.json --lang java --output examples/v3/java/
|
||||
swagger-codegen generate --input-spec v3/spec.json --lang typescript-angular --output examples/v3/typescript-angular/
|
||||
swagger-codegen generate --input-spec v3/spec.json --lang javascript --output examples/v3/javascript/
|
||||
Loading…
x
Reference in New Issue
Block a user