Skip to content

Commit

Permalink
Merge pull request #43128 from yamada-y0/issue-42827
Browse files Browse the repository at this point in the history
Sort the list of endpoints in the generated dev 404
  • Loading branch information
geoand authored Sep 12, 2024
2 parents e47fe96 + 2d28d32 commit 4636861
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ public String getHTMLContent() {

// Additional Endpoints
if (!this.additionalEndpoints.isEmpty()) {
List<AdditionalRouteDescription> endpoints = getSortedAdditionalRouteDescriptions();
builder.resourcesStart(ADDITIONAL_ENDPOINTS);
for (AdditionalRouteDescription additionalEndpoint : this.additionalEndpoints) {
for (AdditionalRouteDescription additionalEndpoint : endpoints) {
builder.staticResourcePath(additionalEndpoint.getUri(), additionalEndpoint.getDescription());
}
builder.resourcesEnd();
Expand Down Expand Up @@ -189,7 +190,8 @@ public JsonObject getJsonContent() {
// Additional Endpoints
if (!this.additionalEndpoints.isEmpty()) {
JsonArray ae = new JsonArray();
for (AdditionalRouteDescription additionalEndpoint : this.additionalEndpoints) {
List<AdditionalRouteDescription> endpoints = getSortedAdditionalRouteDescriptions();
for (AdditionalRouteDescription additionalEndpoint : endpoints) {
ae.add(JsonObject.of(URI, additionalEndpoint.getUri(), DESCRIPTION, additionalEndpoint.getDescription()));
}
infoMap.put(ADDITIONAL_ENDPOINTS, ae);
Expand Down Expand Up @@ -250,7 +252,8 @@ public String getTextContent() {
// Additional Endpoints
if (!this.additionalEndpoints.isEmpty()) {
sw.write(ADDITIONAL_ENDPOINTS + NL);
for (AdditionalRouteDescription additionalEndpoint : this.additionalEndpoints) {
List<AdditionalRouteDescription> endpoints = getSortedAdditionalRouteDescriptions();
for (AdditionalRouteDescription additionalEndpoint : endpoints) {
sw.write(TAB + "- " + additionalEndpoint.getUri() + NL);
sw.write(TAB + TAB + "- " + additionalEndpoint.getDescription() + NL);
}
Expand Down Expand Up @@ -341,6 +344,13 @@ private boolean isHtmlFileName(String fileName) {
return fileName.endsWith(".html") || fileName.endsWith(".htm") || fileName.endsWith(".xhtml");
}

private List<AdditionalRouteDescription> getSortedAdditionalRouteDescriptions() {
return this.additionalEndpoints.stream().sorted(
Comparator.comparingInt((AdditionalRouteDescription desc) -> desc.getUri().split("/").length)
.thenComparing(AdditionalRouteDescription::getUri))
.toList();
}

private static final String HEADING = "404 - Resource Not Found";
private static final String RESOURCE_ENDPOINTS = "Resource Endpoints";
private static final String SERVLET_MAPPINGS = "Servlet mappings";
Expand Down

0 comments on commit 4636861

Please sign in to comment.