1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class DiscoveryDocumentTest < ActionDispatch::IntegrationTest
28 test "canonical discovery document is saved to checkout" do
29 get "/discovery/v1/apis/arvados/v1/rest"
30 assert_response :success
31 canonical = Hash[CANONICAL_FIELDS.map { |key| [key, json_response[key]] }]
32 missing = canonical.select { |key| canonical[key].nil? }
33 assert(missing.empty?, "discovery document missing required fields")
34 actual_json = JSON.pretty_generate(canonical)
36 # Currently the Python SDK is the only component using this copy of the
37 # discovery document, and storing it with the source simplifies the build
38 # process, so it lives there. If another component wants to use it later,
39 # we might consider moving it to a more general subdirectory, but then the
40 # Python build process will need to be extended to accommodate that.
41 src_path = Rails.root.join("../../sdk/python/arvados-v1-discovery.json")
43 expected_json = File.open(src_path) { |f| f.read }
45 expected_json = "(#{src_path} not found)"
48 out_path = Rails.root.join("tmp", "test-arvados-v1-discovery.json")
49 if expected_json != actual_json
50 File.open(out_path, "w") { |f| f.write(actual_json) }
52 assert_equal(expected_json, actual_json,
53 "Live discovery document did not match the expected version (#{src_path}). " +
54 "If the live version is correct, copy it to the git working directory by running:\n" +
55 "cp #{out_path} #{src_path}\n")
58 test "all methods have full descriptions" do
59 get "/discovery/v1/apis/arvados/v1/rest"
60 assert_response :success
62 def missing.check(name, key, spec)
63 self << "#{name} #{key}" if spec[key].blank?
66 Enumerator::Chain.new(
67 *json_response["resources"].map { |_, res| res["methods"].each_value }
69 method_name = method["id"]
70 missing.check(method_name, "description", method)
71 method["parameters"].andand.each_pair do |param_name, param|
72 missing.check("#{method_name} #{param_name} parameter", "description", param)
76 json_response["schemas"].each_pair do |schema_name, schema|
77 missing.check(schema_name, "description", schema)
78 schema["properties"].andand.each_pair do |prop_name, prop|
79 missing.check("#{schema_name} #{prop_name} property", "description", prop)
85 "named methods and schemas are missing documentation",