Skip to content

Commit

Permalink
Merge pull request #2860 from DavidSeptimus/bugfix/2247-enum-name
Browse files Browse the repository at this point in the history
Maps Enum constants to value of name() rather than toString()

fixes #2247
  • Loading branch information
dilipkrish committed Aug 3, 2019
2 parents 71553ac + 54857a4 commit 173d44e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static List<String> getEnumValues(final Class<?> subject) {
if (jsonValue.isPresent() && !isEmpty(jsonValue.get())) {
return jsonValue.get();
}
return input.toString();
return ((Enum) input).name();
});
}
@SuppressWarnings("PMD")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ class EnumsSpec extends Specification {
thrown(UnsupportedOperationException)
}

def "we shouldn't have duplicate enum representations"() {
def "enums should be represented by name() rather than the value of toString()"() {
given:
def expected = Arrays.asList("one", "two")
def expected = Arrays.asList("ONE", "TWO")
expect:
expected.equals(Enums.getEnumValues(DuplicateRepresentationEnum))
expected.equals(Enums.getEnumValues(EnumWithOverridenToString))
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright 2016 the original author or authors.
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,28 +16,21 @@
*
*
*/
package springfox.documentation.schema;

/**
*
* A real life example of this would be org.springframework.http.HttpStatus
*
* @author Alexandru-Constantin Bledea
* @since Sep 12, 2016
*/
public enum DuplicateRepresentationEnum {
package springfox.documentation.schema;

ONE,
TWO,
public enum EnumWithOverridenToString {
ONE("one-string"),
TWO("two-string");

@Deprecated
one,
@Deprecated
two;
private final String customName;

@Override
public String toString() {
return name().toLowerCase();
}
EnumWithOverridenToString(String customName) {
this.customName = customName;
}

@Override
public String toString() {
return customName;
}
}

0 comments on commit 173d44e

Please sign in to comment.