Skip to content

Commit

Permalink
Specifying the right rel for landing page links
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Aug 6, 2018
1 parent 100ed56 commit 38cb61f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,31 @@ public LandingPageDocument(LandingPageRequest request, WFSInfo wfs, Catalog cata
link.setRel(Link.REL_SELF);
link.setTitle("This document");
}
});
}, Link.REL_ALTERNATE);
// api
addLinksFor(
baseUrl,
"wfs3/api",
OpenAPI.class,
"API definition for this endpoint as ",
"api",
null);
null, Link.REL_SERVICE);
// conformance
addLinksFor(
baseUrl,
"wfs3/conformance",
ConformanceDocument.class,
"Conformance declaration as ",
"conformance",
null);
null, "conformance");
// collections
addLinksFor(
baseUrl,
"wfs3/collections",
CollectionsDocument.class,
"Collections Metadata as ",
"collections",
null);
null, "data");
}

/** Builds service links for the given response types */
Expand All @@ -83,13 +83,12 @@ private void addLinksFor(
Class<?> responseType,
String titlePrefix,
String classification,
BiConsumer<String, Link> linkUpdater) {
BiConsumer<String, Link> linkUpdater, String rel) {
for (String format : DefaultWebFeatureService30.getAvailableFormats(responseType)) {
Map<String, String> params = Collections.singletonMap("f", format);
String url = buildURL(baseUrl, path, params, URLMangler.URLType.SERVICE);
String linkType = Link.REL_SERVICE;
String linkTitle = titlePrefix + format;
Link link = new Link(url, linkType, format, linkTitle);
Link link = new Link(url, rel, format, linkTitle);
link.setClassification(classification);
if (linkUpdater != null) {
linkUpdater.accept(format, link);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</p>

<h2>API definition</h2>
<p>The <a id="jsonApiLink" href="${model.getLinkUrl('api', 'text/html')!}"> API document</a> provides a machine processable description of this service API conformant to OpenAPI 3.
<p>The <a id="htmlApiLink" href="${model.getLinkUrl('api', 'text/html')!}"> API document</a> provides a machine processable description of this service API conformant to OpenAPI 3.
<br/>
This API document is also available as
<#list model.getLinksExcept("api", "application/json") as link><a href="${link.href}">${link.type}</a><#if link_has_next>, </#if></#list>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import static org.junit.Assert.assertThat;

import com.jayway.jsonpath.DocumentContext;
import java.util.List;

import org.hamcrest.Matchers;
import org.junit.Test;
import org.w3c.dom.Document;

import java.util.List;

public class LandingPageTest extends WFS3TestSupport {

@Test
Expand Down Expand Up @@ -43,9 +45,9 @@ private void checkJSONLandingPage(DocumentContext json) {
assertJSONList(
json,
"links[?(@.type != 'application/json' && @.href =~ /.*wfs3\\/\\?.*/)].rel",
"service",
"service",
"service");
"alternate",
"alternate",
"alternate");
// check API links
assertJSONList(
json,
Expand All @@ -58,17 +60,17 @@ private void checkJSONLandingPage(DocumentContext json) {
assertJSONList(
json,
"links[?(@.href =~ /.*wfs3\\/conformance.*/)].rel",
"service",
"service",
"service");
"conformance",
"conformance",
"conformance");
// check collection links
assertJSONList(
json,
"links[?(@.href =~ /.*wfs3\\/collections.*/)].rel",
"service",
"service",
"service",
"service");
"data",
"data",
"data",
"data");
}

private <T> void assertJSONList(DocumentContext json, String path, T... expected) {
Expand Down Expand Up @@ -104,7 +106,7 @@ public void testLandingPageHTML() throws Exception {
"http://localhost:8080/geoserver/wfs3/collections?f=text%2Fhtml",
document.select("#htmlCollectionsLink").attr("href"));
assertEquals(
"http://localhost:8080/geoserver/wfs3/api?f=application%2Fjson",
document.select("#jsonApiLink").attr("href"));
"http://localhost:8080/geoserver/wfs3/api?f=text%2Fhtml",
document.select("#htmlApiLink").attr("href"));
}
}

0 comments on commit 38cb61f

Please sign in to comment.