I am migrating my project from the old Elasticsearch REST High Client to the new Java Api Client. I use Openapi generator and Mapstruct.
In openapi.yml
SortOrder:
enum:
- ASC
- DESC
type: string
default: DESC
in my mapper interface I have
SortOrder toModel(com....model.SortOrder sortOrder);
If I switch the SortOrder to the new Java Api Client I get this error:
error: The following constants from the source enum have no corresponding constant in the target enum and must be be mapped via adding additional mappings: ASC, DESC. SortOrder toModel(com....model.SortOrder sortOrder);
When I check the class co.elastic.clients.elasticsearch._types.SortOrder it says:
Asc("asc"),
Desc("desc");
but the old one was: org.elasticsearch.search.sort.SortOrder
ASC {
public String toString() {
return "asc";
}
public int reverseMul() {
return 1;
}
public <T> Comparator<T> wrap(Comparator<T> delegate) {
return delegate;
}
},
DESC {
public String toString() {
return "desc";
}
public int reverseMul() {
return -1;
}
public <T> Comparator<T> wrap(Comparator<T> delegate) {
return delegate.reversed();
}
};
I think the problem is that new library uses Asc/Desc instead of ASC/DESC. How can I solve it?
I found the solution.
in my mapper interface:
@ValueMapping(source="ASC", target = "Asc" )
@ValueMapping(source="DESC", target = "Desc" )
SortOrder toModel(com.....model.SortOrder sortOrder);
Since it was in openapi.yml ASC/DESC and library uses Asc/Desc