Skip to content

Commit b771b11

Browse files
Sorting JAX-RS client methods alphabetically by URI path
1 parent e44299f commit b771b11

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

typescript-generator-core/src/main/java/cz/habarta/typescript/generator/compiler/ModelCompiler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,10 @@ private List<TsMethodModel> processJaxrsMethodGroup(JaxrsApplicationModel jaxrsA
511511

512512
private Map<Symbol, List<JaxrsMethodModel>> groupingByMethodContainer(JaxrsApplicationModel jaxrsApplication, SymbolTable symbolTable, String nameSuffix) {
513513
return jaxrsApplication.getMethods().stream()
514-
.collect(Collectors.groupingBy(method -> getContainerSymbol(jaxrsApplication, symbolTable, nameSuffix, method)));
514+
.collect(Collectors.groupingBy(
515+
method -> getContainerSymbol(jaxrsApplication, symbolTable, nameSuffix, method),
516+
Utils.toSortedList(Comparator.comparing(method -> method.getPath()))
517+
));
515518
}
516519

517520
private Symbol getContainerSymbol(JaxrsApplicationModel jaxrsApplication, SymbolTable symbolTable, String nameSuffix, JaxrsMethodModel method) {

typescript-generator-core/src/main/java/cz/habarta/typescript/generator/util/Utils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import java.util.function.Function;
1717
import java.util.regex.Matcher;
1818
import java.util.regex.Pattern;
19+
import java.util.stream.Collector;
20+
import java.util.stream.Collectors;
1921

2022

2123
public class Utils {
@@ -201,6 +203,16 @@ public static <T> List<T> removeAll(List<T> list, List<T> toBeRemoved) {
201203
return result;
202204
}
203205

206+
public static <T> Collector<T, ?, List<T>> toSortedList(Comparator<? super T> comparator) {
207+
return Collectors.collectingAndThen(
208+
Collectors.toCollection(ArrayList::new),
209+
list -> {
210+
list.sort(comparator);
211+
return list;
212+
}
213+
);
214+
}
215+
204216
public static List<String> readLines(InputStream stream) {
205217
return splitMultiline(readString(stream), false);
206218
}

0 commit comments

Comments
 (0)