[openstreetmap/openstreetmap-website] Add JSON output to /api/0.6/capabilities (PR #4159)
Matt Fellenz
notifications at github.com
Sat Aug 12 04:06:34 UTC 2023
@mattfbacon requested changes on this pull request.
> + assert_equal Settings.api_version, js["version"]
+ assert_equal Settings.generator, js["generator"]
+ assert_equal Settings.api_version, js["api"]["version"]["minimum"]
+ assert_equal Settings.api_version, js["api"]["version"]["maximum"]
+ assert_equal Settings.max_request_area, js["api"]["area"]["maximum"]
+ assert_equal Settings.max_note_request_area, js["api"]["note_area"]["maximum"]
+ assert_equal Settings.tracepoints_per_page, js["api"]["tracepoints"]["per_page"]
+ assert_equal Changeset::MAX_ELEMENTS, js["api"]["changesets"]["maximum_elements"]
+ assert_equal Settings.default_changeset_query_limit, js["api"]["changesets"]["default_query_limit"]
+ assert_equal Settings.max_changeset_query_limit, js["api"]["changesets"]["maximum_query_limit"]
+ assert_equal Settings.max_number_of_relation_members, js["api"]["relationmembers"]["maximum"]
+ assert_equal "online", js["api"]["status"]["database"]
+ assert_equal "online", js["api"]["status"]["api"]
+ assert_equal "online", js["api"]["status"]["gpx"]
+ assert_equal Settings.imagery_blacklist.length, js["policy"]["imagery"]["blacklist"].length
+ end
These tests generally look good, but they implicitly allow adding more keys to the JSON without changing the tests, which may not be desirable. If you constructed the object that we expect and then compared it with `js`, that might work better to test against added keys.
> assert_recognizes(
{ :controller => "api/capabilities", :action => "show" },
{ :path => "/api/0.6/capabilities", :method => :get }
Should there be another `assert_recognizes` here for the JSON route?
> + json.seconds Settings.api_timeout
+ end
+ json.status do
+ json.database @database_status
+ json.api @api_status
+ json.gpx @gpx_status
+ end
+end
+
+json.policy do
+ json.imagery do
+ json.blacklist(Settings.imagery_blacklist) do |url_regex|
+ json.regex url_regex.to_s
+ end
+ end
+end
This looks good as a verbatim copy of the XML builder (though I haven't looked at it in depth), but I wonder it it would be possible to consolidate this JSON generation and the XML generation into a single "data generation" step which would create a Ruby data structure, followed by a serialization step which could dynamically choose the format: JSON or XML.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4159#pullrequestreview-1574758485
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/4159/review/1574758485 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20230811/c16bf539/attachment-0001.htm>
More information about the rails-dev
mailing list