opengeospatial / ogcapi-features

An open standard for querying geospatial information on the web.
https://ogcapi.ogc.org/features
Other
333 stars 83 forks source link

What to do if a request contains same parameter multiple times? #837

Open jratike80 opened 1 year ago

jratike80 commented 1 year ago

I ask because I saw this MapServer discussion in GitHub https://github.com/MapServer/MapServer/pull/6893#discussion_r1224356484 about what to do if a request happens to contain for example &crs= or &bbox-crs= many times

@rouault commented

I've had a bit of trouble to figure out what we should do in that situation, but I believe the answer comes indirectly from the fact that the OpenApi query parameters defined in the OGC API spec use "style: form" and "explode: false". Looking at https://swagger.io/docs/specification/serialization/, it means that if "foo=bar&foo=baz" was synthetized, then foo should be interpreted as an array [bar, baz] which doesn't make sense for the requests we are interested in.

The question is relevant to core as well. By some tests made against PyGeoAPI demo site this server picks the first key-value pair and discards the next ones.

This returns a feature with gid=15 https://demo.pygeoapi.io/stable/collections/ogr_gpkg_poi/items?gid=15&gid=24 This returns a feature with gid=24 https://demo.pygeoapi.io/stable/collections/ogr_gpkg_poi/items?gid=24&gid=15 This does not find anything because feature with gid=16 does not exist https://demo.pygeoapi.io/stable/collections/ogr_gpkg_poi/items?gid=16&gid=15

cportele commented 1 year ago

As pointed out by Even, the behavior will depend on the style and explode values.

If style is form and explode is true for a custom query parameter, then foo=bar&foo=baz is mapped to an array [ 'bar', 'baz' ] for foo.

If explode is false, which is used for all query parameters in the standards, then AFAIK there are no provisions in OpenAPI or any other standard how to handle this. The server could throw an error or pick a value (which is what pygeoapi seems to do).

If clients are expected to submit foo=bar&foo=baz, then you should set explode to false. Or use explode as false and submit foo=bar,baz. This is what is done, e.g., with the bbox parameter. Note that multiple values for a parameter imply that the type is array.