Skip to content

Commit

Permalink
Set removeEnumValuePrefix to false by default (#20452)
Browse files Browse the repository at this point in the history
* set removeEnumValuePrefix to false by default

* update tests
  • Loading branch information
wing328 authored Jan 13, 2025
1 parent 479cd52 commit 09530b4
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 49 deletions.
1 change: 1 addition & 0 deletions bin/configs/java-okhttp-gson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ additionalProperties:
useOneOfDiscriminatorLookup: true
disallowAdditionalPropertiesIfNotPresent: false
useReflectionEqualsHashCode:: true
removeEnumValuePrefix: true
enumNameMappings:
s: LOWER_CASE_S
S: UPPER_CASE_S
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ apiTemplateFiles are for API outputs only (controllers/handlers).
// acts strictly upon a spec, potentially modifying it to have consistent behavior across generators.
protected boolean strictSpecBehavior = true;
// flag to indicate whether enum value prefixes are removed
protected boolean removeEnumValuePrefix = true;
protected boolean removeEnumValuePrefix = false;

// Support legacy logic for evaluating discriminators
@Setter protected boolean legacyDiscriminatorBehavior = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ public void updateCodegenPropertyEnumWithExtension() {
@Test
public void updateCodegenPropertyEnumWithPrefixRemoved() {
final DefaultCodegen codegen = new DefaultCodegen();
codegen.setRemoveEnumValuePrefix(true);
CodegenProperty enumProperty = codegenProperty(Arrays.asList("animal_dog", "animal_cat"));

codegen.updateCodegenPropertyEnum(enumProperty);
Expand Down Expand Up @@ -925,6 +926,7 @@ public void updateCodegenPropertyEnumWithoutPrefixRemoved() {
@Test
public void postProcessModelsEnumWithPrefixRemoved() {
final DefaultCodegen codegen = new DefaultCodegen();
codegen.setRemoveEnumValuePrefix(true);
ModelsMap objs = codegenModel(Arrays.asList("animal_dog", "animal_cat"));
CodegenModel cm = objs.getModels().get(0).getModel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
## Enum


* `_1` (value: `"Code 1"`)
* `CODE_1` (value: `"Code 1"`)

* `_2` (value: `"Code 2"`)
* `CODE_2` (value: `"Code 2"`)

* `_3` (value: `"Code 3"`)
* `CODE_3` (value: `"Code 3"`)



Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
@JsonAdapter(CodesEnum.Adapter.class)
public enum CodesEnum {

_1("Code 1"),
CODE_1("Code 1"),

_2("Code 2"),
CODE_2("Code 2"),

_3("Code 3");
CODE_3("Code 3");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ impl UniqueItemArrayTesting {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
UniqueItem1,
#[serde(rename = "unique_item_2")]
Variant2,
UniqueItem2,
#[serde(rename = "unique_item_3")]
Variant3,
UniqueItem3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
Self::UniqueItem1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ impl UniqueItemArrayTesting {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
UniqueItem1,
#[serde(rename = "unique_item_2")]
Variant2,
UniqueItem2,
#[serde(rename = "unique_item_3")]
Variant3,
UniqueItem3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
Self::UniqueItem1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ impl UniqueItemArrayTesting {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
UniqueItem1,
#[serde(rename = "unique_item_2")]
Variant2,
UniqueItem2,
#[serde(rename = "unique_item_3")]
Variant3,
UniqueItem3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
Self::UniqueItem1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ impl UniqueItemArrayTesting {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
UniqueItem1,
#[serde(rename = "unique_item_2")]
Variant2,
UniqueItem2,
#[serde(rename = "unique_item_3")]
Variant3,
UniqueItem3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
Self::UniqueItem1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ impl UniqueItemArrayTesting {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
UniqueItem1,
#[serde(rename = "unique_item_2")]
Variant2,
UniqueItem2,
#[serde(rename = "unique_item_3")]
Variant3,
UniqueItem3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
Self::UniqueItem1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ impl UniqueItemArrayTesting {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
UniqueItem1,
#[serde(rename = "unique_item_2")]
Variant2,
UniqueItem2,
#[serde(rename = "unique_item_3")]
Variant3,
UniqueItem3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
Self::UniqueItem1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ impl UniqueItemArrayTesting {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
UniqueItem1,
#[serde(rename = "unique_item_2")]
Variant2,
UniqueItem2,
#[serde(rename = "unique_item_3")]
Variant3,
UniqueItem3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
Self::UniqueItem1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ impl UniqueItemArrayTesting {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
UniqueItem1,
#[serde(rename = "unique_item_2")]
Variant2,
UniqueItem2,
#[serde(rename = "unique_item_3")]
Variant3,
UniqueItem3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
Self::UniqueItem1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ impl FooUniqueItemArrayTesting {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
UniqueItem1,
#[serde(rename = "unique_item_2")]
Variant2,
UniqueItem2,
#[serde(rename = "unique_item_3")]
Variant3,
UniqueItem3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
Self::UniqueItem1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ impl UniqueItemArrayTesting {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
UniqueItem1,
#[serde(rename = "unique_item_2")]
Variant2,
UniqueItem2,
#[serde(rename = "unique_item_3")]
Variant3,
UniqueItem3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
Self::UniqueItem1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export interface Category {
*/

export const MediaType = {
Json: 'application/json',
Xml: 'application/xml'
ApplicationJson: 'application/json',
ApplicationXml: 'application/xml'
} as const;

export type MediaType = typeof MediaType[keyof typeof MediaType];
Expand Down

0 comments on commit 09530b4

Please sign in to comment.