Skip to content

Commit

Permalink
Expose configured limit values
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Jun 26, 2018
1 parent 397bed0 commit ff5b8c1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.servers.Server;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -95,7 +97,8 @@ public OpenAPI build(BaseRequest request, WFSInfo wfs) {
FeatureCollectionResponse.class);

// provide a list of valid values for collectionId
Parameter collectionId = api.getComponents().getParameters().get("collectionId");
Map<String, Parameter> parameters = api.getComponents().getParameters();
Parameter collectionId = parameters.get("collectionId");
Catalog catalog = wfs.getGeoServer().getCatalog();
List<String> validCollectionIds =
catalog.getFeatureTypes()
Expand All @@ -104,6 +107,18 @@ public OpenAPI build(BaseRequest request, WFSInfo wfs) {
.collect(Collectors.toList());
collectionId.getSchema().setEnum(validCollectionIds);

// provide actual values for limit
Parameter limit = parameters.get("limit");
BigDecimal limitMax;
if (wfs.getMaxFeatures() > 0) {
limitMax = BigDecimal.valueOf(wfs.getMaxFeatures());
} else {
limitMax = BigDecimal.valueOf(Integer.MAX_VALUE);
}
limit.getSchema().setMaximum(limitMax);
// for the moment we don't have a setting for the default, keep it same as max
limit.getSchema().setDefault(limitMax);

return api;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.geoserver.wfs3.response;

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlAnnotationIntrospector;
Expand Down Expand Up @@ -95,6 +96,7 @@ public String findNamespace(Annotated ann) {

} else {
mapper = Json.mapper();
mapper.writer(new DefaultPrettyPrinter());
}

mapper.writeValue(output, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ components:
Only items are counted that are on the first level of the collection in
the response document. Nested objects contained within the explicitly
requested items shall not be counted.
* Minimum = 1
* Maximum = 10000
* Default = 10
required: false
schema:
type: integer
Expand Down
15 changes: 14 additions & 1 deletion src/community/wfs3/src/test/java/org/geoserver/wfs3/ApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.Paths;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.servers.Server;
import java.io.ByteArrayInputStream;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.geoserver.wfs.WFSInfo;
import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.web.MockHttpServletRequest;
Expand Down Expand Up @@ -118,7 +122,8 @@ private void validateApi(OpenAPI api) {
assertThat(item.getGet().getOperationId(), equalTo("getFeature"));

// check collectionId parameter
Parameter collectionId = api.getComponents().getParameters().get("collectionId");
Map<String, Parameter> params = api.getComponents().getParameters();
Parameter collectionId = params.get("collectionId");
List<String> collectionIdValues = collectionId.getSchema().getEnum();
List<String> expectedCollectionIds =
getCatalog()
Expand All @@ -127,5 +132,13 @@ private void validateApi(OpenAPI api) {
.map(ft -> NCNameResourceCodec.encode(ft))
.collect(Collectors.toList());
assertThat(collectionIdValues, equalTo(expectedCollectionIds));

// check the limit parameter
Parameter limit = params.get("limit");
Schema limitSchema = limit.getSchema();
assertEquals(BigDecimal.valueOf(1), limitSchema.getMinimum());
WFSInfo wfs = getGeoServer().getService(WFSInfo.class);
assertEquals(wfs.getMaxFeatures(), limitSchema.getMaximum().intValue());
assertEquals(wfs.getMaxFeatures(), ((Number) limitSchema.getDefault()).intValue());
}
}

0 comments on commit ff5b8c1

Please sign in to comment.