Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2247 maps Enum constants to value of name() rather than toString() #2860

Merged
merged 2 commits into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}