-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[typescript] Fix incorrect enum literal case (#7378)
* Fix incorrect enum values for typescript clients * Fix incorrect enum values for typescript clients * Fix incorrect enum values for typescript clients
- Loading branch information
Andrey Mochalov
authored
Sep 9, 2020
1 parent
37de486
commit 4d8ac0e
Showing
2 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...c/test/java/org/openapitools/codegen/typescript/TypeScriptAxiosClientCodegenTestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.openapitools.codegen.typescript; | ||
|
||
import org.openapitools.codegen.CodegenConstants; | ||
import org.openapitools.codegen.languages.TypeScriptAxiosClientCodegen; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
public class TypeScriptAxiosClientCodegenTestTest { | ||
|
||
TypeScriptAxiosClientCodegen codegen = new TypeScriptAxiosClientCodegen(); | ||
|
||
@Test | ||
public void testToEnumVarNameOriginalNamingType() { | ||
codegen.additionalProperties().put(CodegenConstants.ENUM_PROPERTY_NAMING, CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.original.name()); | ||
codegen.processOpts(); | ||
assertEquals(codegen.toEnumVarName("SCIENCE", "string"), "SCIENCE"); | ||
assertEquals(codegen.toEnumVarName("SCIENCE_FICTION", "string"), "SCIENCE_FICTION"); | ||
assertEquals(codegen.toEnumVarName("science", "string"), "science"); | ||
assertEquals(codegen.toEnumVarName("science_fiction", "string"), "science_fiction"); | ||
assertEquals(codegen.toEnumVarName("scienceFiction", "string"), "scienceFiction"); | ||
assertEquals(codegen.toEnumVarName("ScienceFiction", "string"), "ScienceFiction"); | ||
assertEquals(codegen.toEnumVarName("A", "string"), "A"); | ||
assertEquals(codegen.toEnumVarName("b", "string"), "b"); | ||
} | ||
|
||
@Test | ||
public void testToEnumVarNameCamelCaseNamingType() { | ||
codegen.additionalProperties().put(CodegenConstants.ENUM_PROPERTY_NAMING, CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.camelCase.name()); | ||
codegen.processOpts(); | ||
assertEquals(codegen.toEnumVarName("SCIENCE", "string"), "science"); | ||
assertEquals(codegen.toEnumVarName("SCIENCE_FICTION", "string"), "scienceFiction"); | ||
assertEquals(codegen.toEnumVarName("science", "string"), "science"); | ||
assertEquals(codegen.toEnumVarName("science_fiction", "string"), "scienceFiction"); | ||
assertEquals(codegen.toEnumVarName("scienceFiction", "string"), "scienceFiction"); | ||
assertEquals(codegen.toEnumVarName("ScienceFiction", "string"), "scienceFiction"); | ||
} | ||
|
||
@Test | ||
public void testToEnumVarNamePascalCaseNamingType() { | ||
codegen.additionalProperties().put(CodegenConstants.ENUM_PROPERTY_NAMING, CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.PascalCase.name()); | ||
codegen.processOpts(); | ||
assertEquals(codegen.toEnumVarName("SCIENCE", "string"), "Science"); | ||
assertEquals(codegen.toEnumVarName("SCIENCE_FICTION", "string"), "ScienceFiction"); | ||
assertEquals(codegen.toEnumVarName("science", "string"), "Science"); | ||
assertEquals(codegen.toEnumVarName("science_fiction", "string"), "ScienceFiction"); | ||
assertEquals(codegen.toEnumVarName("scienceFiction", "string"), "ScienceFiction"); | ||
assertEquals(codegen.toEnumVarName("ScienceFiction", "string"), "ScienceFiction"); | ||
assertEquals(codegen.toEnumVarName("A", "string"), "A"); | ||
assertEquals(codegen.toEnumVarName("b", "string"), "B"); | ||
} | ||
|
||
@Test | ||
public void testToEnumVarNameSnakeCaseNamingType() { | ||
codegen.additionalProperties().put(CodegenConstants.ENUM_PROPERTY_NAMING, CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.snake_case.name()); | ||
codegen.processOpts(); | ||
assertEquals(codegen.toEnumVarName("SCIENCE", "string"), "science"); | ||
assertEquals(codegen.toEnumVarName("SCIENCE_FICTION", "string"), "science_fiction"); | ||
assertEquals(codegen.toEnumVarName("science", "string"), "science"); | ||
assertEquals(codegen.toEnumVarName("science_fiction", "string"), "science_fiction"); | ||
assertEquals(codegen.toEnumVarName("scienceFiction", "string"), "science_fiction"); | ||
assertEquals(codegen.toEnumVarName("ScienceFiction", "string"), "science_fiction"); | ||
assertEquals(codegen.toEnumVarName("A", "string"), "a"); | ||
assertEquals(codegen.toEnumVarName("b", "string"), "b"); | ||
} | ||
|
||
@Test | ||
public void testToEnumVarNameUpperCaseNamingType() { | ||
codegen.additionalProperties().put(CodegenConstants.ENUM_PROPERTY_NAMING, CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.UPPERCASE.name()); | ||
codegen.processOpts(); | ||
assertEquals(codegen.toEnumVarName("SCIENCE", "string"), "SCIENCE"); | ||
assertEquals(codegen.toEnumVarName("SCIENCE_FICTION", "string"), "SCIENCE_FICTION"); | ||
assertEquals(codegen.toEnumVarName("science", "string"), "SCIENCE"); | ||
assertEquals(codegen.toEnumVarName("science_fiction", "string"), "SCIENCE_FICTION"); | ||
assertEquals(codegen.toEnumVarName("scienceFiction", "string"), "SCIENCE_FICTION"); | ||
assertEquals(codegen.toEnumVarName("ScienceFiction", "string"), "SCIENCE_FICTION"); | ||
assertEquals(codegen.toEnumVarName("A", "string"), "A"); | ||
assertEquals(codegen.toEnumVarName("b", "string"), "B"); | ||
} | ||
|
||
} |