[openstreetmap/openstreetmap-website] Add support for json traces API (PR #5943)

Tom Hughes notifications at github.com
Wed Apr 23 17:13:28 UTC 2025


@tomhughes requested changes on this pull request.

The changes I've suggested fix the failing tests, but they also reveal a problem as they show that the structure of the JSON returned by the two methods is not consistent - one has a top level hash with a `osm` member pointing at the details and the other has a top level hash with a `gpx_files` member pointing at an array of details.

Looking at other API methods the responses should probably look like:

```json
{
  "version": "0.6",
  "generator": "OpenStreetMap server",
  "copyright": "OpenStreetMap and contributors",
  "attribution": "http://www.openstreetmap.org/copyright",
  "license": "http://opendatacommons.org/licenses/odbl/1-0/",
  "trace": {
    ...
  }
}
```
and:

```json
{
  "version": "0.6",
  "generator": "OpenStreetMap server",
  "copyright": "OpenStreetMap and contributors",
  "attribution": "http://www.openstreetmap.org/copyright",
  "license": "http://opendatacommons.org/licenses/odbl/1-0/",
  "traces": [
    {
      "trace": {
        ...
      }
    },
    ...
  ]
}
```

> @@ -0,0 +1,3 @@
+json.osm do
+  json.partial! "api/traces/trace", trace => @trace

```suggestion
  json.partial! "api/traces/trace", :trace => @trace
```

> @@ -0,0 +1,3 @@
+json.gpx_files @traces do |trace|
+  json.partial! "api/traces/trace", trace => trace

```suggestion
  json.partial! "api/traces/trace", :trace => trace
```

> +      assert_equal public_trace_file.id, js.id
+      assert_equal public_trace_file.user.id, js.uid

```suggestion
      assert_equal public_trace_file.id, js["osm"]["id"]
      assert_equal public_trace_file.user.id, js["osm"]["uid"]
```

> +        assert_equal trace1.id, js[0]["id"]
+        assert_equal trace2.id, js[1]["id"]

```suggestion
        assert_equal trace1.id, js["gpx_files"][0]["id"]
        assert_equal trace2.id, js["gpx_files"][1]["id"]
```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5943#pullrequestreview-2788123048
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/5943/review/2788123048 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250423/0eb6e096/attachment.htm>


More information about the rails-dev mailing list