haveapi 0.31.1 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/benchmarks/documentation.rb +29 -6
  4. data/benchmarks/endpoints.rb +153 -24
  5. data/benchmarks/spec/client_examples_spec.rb +109 -37
  6. data/doc/client-examples.md +218 -45
  7. data/doc/documentation-oauth.md +157 -0
  8. data/doc/documentation-ui.md +192 -0
  9. data/doc/index.md +3 -6
  10. data/doc/performance.md +39 -12
  11. data/haveapi.gemspec +1 -1
  12. data/lib/haveapi/authentication/chain.rb +19 -0
  13. data/lib/haveapi/authentication/oauth2/provider.rb +7 -1
  14. data/lib/haveapi/client_example.rb +143 -15
  15. data/lib/haveapi/client_examples/curl.rb +30 -20
  16. data/lib/haveapi/client_examples/dynamic_helpers.rb +1 -1
  17. data/lib/haveapi/client_examples/go_client.rb +9 -2
  18. data/lib/haveapi/client_examples/http.rb +9 -4
  19. data/lib/haveapi/client_examples/js_async_client.rb +7 -0
  20. data/lib/haveapi/client_examples/js_client.rb +47 -36
  21. data/lib/haveapi/client_examples/php_client.rb +161 -75
  22. data/lib/haveapi/client_examples/python_async_client.rb +3 -0
  23. data/lib/haveapi/client_examples/python_client.rb +61 -47
  24. data/lib/haveapi/client_examples/ruby_cli.rb +27 -18
  25. data/lib/haveapi/client_examples/ruby_client.rb +80 -31
  26. data/lib/haveapi/client_examples/rust_client.rb +20 -9
  27. data/lib/haveapi/client_examples/ts_async_client.rb +7 -0
  28. data/lib/haveapi/client_examples/ts_client.rb +3 -0
  29. data/lib/haveapi/client_examples/ts_generated_client.rb +10 -2
  30. data/lib/haveapi/documentation_context.rb +7 -2
  31. data/lib/haveapi/documentation_helpers.rb +223 -0
  32. data/lib/haveapi/documentation_oauth.rb +399 -0
  33. data/lib/haveapi/documentation_search.rb +225 -0
  34. data/lib/haveapi/documentation_search_index.rb +79 -0
  35. data/lib/haveapi/documentation_validators.rb +179 -0
  36. data/lib/haveapi/public/css/documentation.css +343 -0
  37. data/lib/haveapi/public/js/documentation.js +992 -0
  38. data/lib/haveapi/server.rb +144 -86
  39. data/lib/haveapi/shared_documentation_helpers.rb +54 -0
  40. data/lib/haveapi/version.rb +1 -1
  41. data/lib/haveapi/views/doc_layout.erb +16 -0
  42. data/lib/haveapi/views/doc_sidebars/create-client.erb +3 -3
  43. data/lib/haveapi/views/doc_sidebars/json-schema.erb +1 -1
  44. data/lib/haveapi/views/doc_sidebars/protocol.erb +5 -5
  45. data/lib/haveapi/views/documentation/search_form.erb +10 -0
  46. data/lib/haveapi/views/documentation/search_index.erb +1 -0
  47. data/lib/haveapi/views/documentation/search_results.erb +20 -0
  48. data/lib/haveapi/views/index.erb +2 -4
  49. data/lib/haveapi/views/main_layout.erb +12 -6
  50. data/lib/haveapi/views/shared_documentation.erb +12 -0
  51. data/lib/haveapi/views/shared_sidebar.erb +25 -0
  52. data/lib/haveapi/views/version_page/auth_body.erb +12 -33
  53. data/lib/haveapi/views/version_page/client_overview.erb +40 -0
  54. data/lib/haveapi/views/version_page/example_panels.erb +18 -0
  55. data/lib/haveapi/views/version_page/resource_body.erb +91 -132
  56. data/lib/haveapi/views/version_page/resource_directory.erb +14 -0
  57. data/lib/haveapi/views/version_page/usage.erb +7 -0
  58. data/lib/haveapi/views/version_page.erb +36 -117
  59. data/lib/haveapi/views/version_sidebar/auth_nav.erb +12 -16
  60. data/lib/haveapi/views/version_sidebar/auth_resource_nav.erb +19 -0
  61. data/lib/haveapi/views/version_sidebar/authentication_control.erb +26 -0
  62. data/lib/haveapi/views/version_sidebar/authentication_status.erb +3 -0
  63. data/lib/haveapi/views/version_sidebar/brand.erb +31 -0
  64. data/lib/haveapi/views/version_sidebar/resource_nav.erb +11 -20
  65. data/lib/haveapi/views/version_sidebar.erb +59 -48
  66. data/spec/authentication/basic_spec.rb +10 -10
  67. data/spec/authentication/oauth2_chain_spec.rb +72 -0
  68. data/spec/authentication/oauth2_token_validation_spec.rb +38 -0
  69. data/spec/client_examples/assets/documentation_test.cjs +817 -0
  70. data/spec/client_examples/context_performance_spec.rb +5 -4
  71. data/spec/client_examples/context_spec.rb +23 -2
  72. data/spec/client_examples/detail_spec.rb +175 -0
  73. data/spec/client_examples/dynamic_acceptance.md +59 -26
  74. data/spec/client_examples/dynamic_acceptance.rb +164 -44
  75. data/spec/client_examples/dynamic_acceptance_spec.rb +140 -23
  76. data/spec/client_examples/dynamic_fixture.rb +4 -3
  77. data/spec/client_examples/dynamic_js_spec.rb +20 -11
  78. data/spec/client_examples/dynamic_metadata_spec.rb +69 -0
  79. data/spec/client_examples/dynamic_mounted_paths_spec.rb +9 -7
  80. data/spec/client_examples/dynamic_python_spec.rb +62 -11
  81. data/spec/client_examples/go_spec.rb +14 -1
  82. data/spec/client_examples/presentation_spec.rb +247 -0
  83. data/spec/client_examples/profile_mount_spec.rb +40 -13
  84. data/spec/client_examples/rust_client_spec.rb +35 -1
  85. data/spec/client_examples/shell_spec.rb +268 -0
  86. data/spec/client_examples/syntax_spec.rb +192 -0
  87. data/spec/client_examples/ts_generated_client_spec.rb +15 -2
  88. data/spec/client_examples/typescript_profiles_spec.rb +1 -1
  89. data/spec/documentation/auth_filtering_spec.rb +9 -4
  90. data/spec/documentation/canonical_routes_spec.rb +89 -0
  91. data/spec/documentation/client_examples_spec.rb +39 -5
  92. data/spec/documentation/client_overview_spec.rb +145 -0
  93. data/spec/documentation/current_user_html_escaping_spec.rb +7 -2
  94. data/spec/documentation/example_variants_spec.rb +93 -0
  95. data/spec/documentation/fixtures/search_index.json +476 -0
  96. data/spec/documentation/identity_and_guides_spec.rb +130 -0
  97. data/spec/documentation/identity_context_spec.rb +180 -0
  98. data/spec/documentation/navigation_spec.rb +296 -0
  99. data/spec/documentation/oauth_fixture_spec.rb +39 -0
  100. data/spec/documentation/oauth_spec.rb +912 -0
  101. data/spec/documentation/oauth_transport_spec.rb +45 -0
  102. data/spec/documentation/performance_spec.rb +47 -6
  103. data/spec/documentation/reference_headings_spec.rb +190 -0
  104. data/spec/documentation/search_index_routes_spec.rb +202 -0
  105. data/spec/documentation/search_index_spec.rb +85 -0
  106. data/spec/documentation/search_routes_spec.rb +199 -0
  107. data/spec/documentation/search_spec.rb +134 -0
  108. data/spec/documentation/shared_pages_spec.rb +240 -0
  109. data/spec/documentation/validators_spec.rb +123 -0
  110. data/spec/documentation_spec.rb +3 -3
  111. data/spec/packaging_spec.rb +21 -2
  112. data/spec/performance/documentation_identity_fixture_spec.rb +47 -0
  113. data/spec/performance/documentation_shapes_spec.rb +97 -0
  114. data/spec/performance/json_activation_spec.rb +78 -1
  115. data/spec/performance/release_lineage_spec.rb +4 -3
  116. data/spec/performance/runner_spec.rb +1 -0
  117. data/test_support/all_client_performance_fixture.rb +6 -10
  118. data/test_support/documentation_oauth_fixture.rb +54 -0
  119. data/test_support/documentation_performance_fixture.rb +19 -1
  120. data/test_support/dynamic_documentation_api.rb +35 -10
  121. data/test_support/dynamic_python_login_spec.rb +3 -11
  122. metadata +52 -3
@@ -1,17 +1,18 @@
1
- <h2 id="auth-<%= name %>"><%= name.to_s.humanize %></h2>
1
+ <section data-doc-section id="auth-<%= escape_html(name) %>">
2
+ <h2><%= escape_html(name.to_s.humanize) %><%= documentation_permalink("auth-#{name}", name.to_s.humanize) %></h2>
2
3
  <hr>
3
4
 
4
5
  <p><%= info[:description] %></p>
5
6
 
6
7
  <% if name == :token %>
7
- <dl>
8
+ <dl class="docs-metadata">
8
9
  <dt>HTTP header:</dt>
9
10
  <dd><%= info[:http_header] %></dd>
10
11
  <dt>Query parameter:</dt>
11
12
  <dd><%= info[:query_parameter] %></dd>
12
13
  </dl>
13
14
  <% elsif name == :oauth2 %>
14
- <dl>
15
+ <dl class="docs-metadata">
15
16
  <dt>Authorize URL:</dt>
16
17
  <dd><%= info[:authorize_url] %></dd>
17
18
  <dt>Token URL:</dt>
@@ -21,37 +22,15 @@
21
22
  </dl>
22
23
  <% end %>
23
24
 
24
- <% if info[:resources] %>
25
- <h2>Resources</h2>
25
+ <% unless (info[:resources] || {}).empty? %>
26
+ <% resources_target = documentation_reference_anchor(authentication: name, section: :resources) %>
27
+ <h2 id="<%= escape_html(resources_target) %>">Resources<%= documentation_permalink(resources_target, 'Resources') %></h2>
26
28
  <% sort_hash(info[:resources]).each do |resource, desc| %>
27
- <%= erb :"version_page/resource_body", locals: {resource: resource.to_s, info: desc, path: [], prefix: 'root', name: nil} %>
29
+ <%= erb :"version_page/resource_body", locals: {resource: resource.to_s, info: desc, path: [], prefix: 'root', name: nil, authentication_resource: true, authentication_provider: name} %>
28
30
  <% end %>
29
31
  <% end %>
30
32
 
31
- <% baseid = "auth-#{name}" %>
32
- <div id="<%= baseid %>-tabbar"></div>
33
-
34
- <div id="<%= baseid %>-examples">
35
- <% documentation_panels(:auth, auth_method: name, auth_description: info).each do |client, result| %>
36
- <div id="<%= escape_html("#{baseid}-#{client.id}") %>">
37
- <%= erb :"version_page/client_auth", locals: {client: client, result: result} %>
38
- </div>
39
- <% end %>
40
- </div>
41
-
42
- <script type="text/javascript">
43
- nojsTabs({
44
- tabs: document.getElementById('<%= "#{baseid}-examples" %>'),
45
- titleSelector: 'h4',
46
- tabBar: document.getElementById('<%= "#{baseid}-tabbar" %>'),
47
- hiddenClass: 'tab-hidden',
48
- activeClass: 'active',
49
- createElement: function (el) {
50
- if (el.tagName == 'UL')
51
- el.classList.add('nav', 'nav-tabs');
52
-
53
- else if (el.tagName == 'LI')
54
- el.setAttribute('role', 'presentation');
55
- }
56
- });
57
- </script>
33
+ <% examples_target = documentation_reference_anchor(authentication: name, section: :examples) %>
34
+ <h3 id="<%= escape_html(examples_target) %>">Examples<%= documentation_permalink(examples_target, 'Examples') %></h3>
35
+ <%= erb :'version_page/example_panels', locals: {baseid: "auth-#{name}", kind: :auth, changes: {auth_method: name, auth_description: info}} %>
36
+ </section>
@@ -0,0 +1,40 @@
1
+ <% library_paths = {
2
+ '0' => 'clients/ruby#client-library',
3
+ '3' => 'clients/ruby#cli',
4
+ 'javascript-callback' => 'clients/js#javascript-with-callbacks',
5
+ 'javascript-async' => 'clients/js#javascript-with-async-await',
6
+ 'typescript-callback' => 'clients/js#typescript-with-callbacks',
7
+ 'typescript-async' => 'clients/js#typescript-with-async-await',
8
+ 'python-sync' => 'clients/python#synchronous-client',
9
+ 'python-async' => 'clients/python#asynchronous-client',
10
+ '2' => 'clients/php'
11
+ } %>
12
+ <% generator_paths = {
13
+ 'go' => 'clients/go',
14
+ 'rust-async' => 'clients/rust',
15
+ 'rust-blocking' => 'clients/rust',
16
+ 'typescript-generated' => 'clients/typescript'
17
+ } %>
18
+ <% clients = documentation_clients %>
19
+ <% library_clients = clients.select { |client| library_paths.has_key?(client.id) || generator_paths.has_key?(client.id) } %>
20
+ <% groups = library_clients.group_by { |client| client.language == 'cli' && library_clients.any? { |candidate| candidate.language == 'ruby' } ? 'ruby' : client.language } %>
21
+ <section id="client-libraries">
22
+ <h2>Client libraries<%= documentation_permalink('client-libraries', 'Client libraries') %></h2>
23
+ <ul>
24
+ <% groups.each_value do |group| %>
25
+ <% variants = group.length > 1 || group.first.variant %>
26
+ <% profiles = group.filter_map { |client| documentation_context(client).profile if generator_paths.has_key?(client.id) }.uniq %>
27
+ <li>
28
+ <% if variants %><%= escape_html(group.first.language_label) %> (<% end %><% group.each_with_index do |client, index|
29
+ path = library_paths[client.id] || generator_paths.fetch(client.id)
30
+ label = variants ? (client.variant&.downcase&.sub(/\Aapi\b/, 'API') || (client.language == 'ruby' ? 'library' : client.language_label)) : client.language_label
31
+ separator = index.zero? ? '' : (index == group.length - 1 ? ' and ' : ', ')
32
+ %><%= separator %><a href="<%= escape_html("https://github.com/vpsfreecz/haveapi/tree/master/#{path}") %>"><%= escape_html(label) %></a><% end %><% if variants %>)<% end %><% profiles.each do |profile| %>: <code><%= escape_html(profile.package_name) %></code><% unless profile.package_version.nil? %> <%= escape_html(profile.package_version) %><% end %><% end %>
33
+ </li>
34
+ <% end %>
35
+ </ul>
36
+ <% request_formats = clients.select { |client| %w[curl http].include?(client.language) } %>
37
+ <% unless request_formats.empty? %>
38
+ <p><% request_formats.each_with_index do |client, index| %><%= index.zero? ? '' : ' and ' %><a href="<%= escape_html(documentation_url(page: 'resources')) %>"><%= escape_html(client.label) %></a><% end %> request examples are available on resource pages.</p>
39
+ <% end %>
40
+ </section>
@@ -0,0 +1,18 @@
1
+ <% legacy_baseid ||= nil %>
2
+ <% variants = documentation_example_variants(kind, **changes) %>
3
+ <% details_by_client = variants.group_by { |client, _detail, _result| client.id }.transform_values { |items| items.map { |_client, detail, _result| detail.to_s } } %>
4
+ <% if legacy_baseid %><%= documentation_reference_alias("#{legacy_baseid}-examples") %><% end %>
5
+ <div class="docs-example" data-example data-example-details="<%= escape_html(JSON.generate(details_by_client)) %>" id="<%= escape_html("#{baseid}-examples") %>">
6
+ <% variants.each do |client, detail, result| %>
7
+ <% suffix = detail == :thorough ? '-thorough' : '' %>
8
+ <% if legacy_baseid %><%= documentation_reference_alias("#{legacy_baseid}-#{client.id}#{suffix}") %><% end %>
9
+ <% if detail == :simple && details_by_client[client.id] == ['simple'] %>
10
+ <%= documentation_reference_alias("#{legacy_baseid || baseid}-#{client.id}-thorough") %>
11
+ <% if legacy_baseid %><%= documentation_reference_alias("#{baseid}-#{client.id}-thorough") %><% end %>
12
+ <% end %>
13
+ <details data-example-panel data-client="<%= escape_html(client.id) %>" data-language="<%= escape_html(client.language) %>" data-variant="<%= escape_html(client.variant) %>" data-detail="<%= detail %>" id="<%= escape_html("#{baseid}-#{client.id}#{suffix}") %>"<% if detail == :simple %> open<% end %>>
14
+ <summary><%= escape_html(client.label) %> · <%= detail == :simple ? 'Simple' : 'With error handling' %></summary>
15
+ <%= erb :'version_page/client_result', locals: {client: client, result: result} %>
16
+ </details>
17
+ <% end %>
18
+ </div>
@@ -1,156 +1,115 @@
1
1
  <% name ||= resource.humanize %>
2
+ <% authentication_resource ||= false %>
3
+ <% authentication_provider ||= nil %>
2
4
  <% resource_path = path.clone << resource %>
3
5
  <% resource_info = info %>
4
- <h2 class="resource" id="<%= "#{prefix}-#{resource}" %>"><%= resource.humanize %></h2>
5
- <hr>
6
+ <% resource_target = documentation_resource_target(resource_path: resource_path, authentication: authentication_provider) %>
7
+ <% heading = authentication_resource ? 'h3' : 'h1' %>
8
+ <% action_heading = authentication_resource ? 'h4' : 'h2' %>
9
+ <% parameter_heading = authentication_resource ? 'h5' : 'h3' %>
10
+ <% if authentication_resource %><%= documentation_reference_alias("#{prefix}-#{resource}") %><% end %>
11
+ <<%= heading %> class="resource" id="<%= escape_html(resource_target) %>"><%= escape_html(name) %><%= documentation_permalink(resource_target, name) %></<%= heading %>>
6
12
  <div class="resource-body">
7
13
  <p><%= info[:description] %></p>
8
-
9
14
  <div class="actions">
10
15
  <% sort_hash(info[:actions]).each do |action, info| %>
11
- <h3 id="<%= "#{prefix}-#{resource}-#{action}" %>"><%= name %> # <%= action.capitalize %></h3>
12
- <div class="action">
13
- <dl>
14
- <dt>Path:</dt>
15
- <dd><%= info[:method] %> <%= info[:path] %></dd>
16
- <dt>Description:</dt>
17
- <dd><%= info[:description] %></dd>
18
- <dt>Authentication required:</dt>
19
- <dd><%= info[:auth] ? 'yes' : 'no' %></dd>
20
- <dt>Scope:</dt>
21
- <dd><%= info[:scope] %></dd>
22
- <dt>Aliases:</dt>
23
- <dd><%= info[:aliases].join(', ') %></dd>
24
- <dt>Blocking:</dt>
25
- <dd><%= info[:blocking] ? 'yes' : 'no' %></dd>
26
- </dl>
27
-
28
- <h4>Input parameters</h4>
29
- <div class="parameters">
16
+ <% action_target = documentation_resource_target(resource_path: resource_path, action_name: action, authentication: authentication_provider) %>
17
+ <% sections = documentation_action_sections(info, resource_path: resource_path, action_name: action, authentication: authentication_provider) %>
18
+ <% if authentication_resource %><%= documentation_reference_alias("#{prefix}-#{resource}-#{action}") %><% end %>
19
+ <section data-doc-section id="<%= escape_html(action_target) %>">
20
+ <<%= action_heading %>><%= escape_html(action.capitalize) %><%= documentation_permalink(action_target, action.to_s.capitalize) %></<%= action_heading %>>
21
+ <div class="action">
22
+ <dl class="docs-metadata">
23
+ <dt>Path</dt><dd><%= info[:method] %> <%= info[:path] %></dd>
24
+ <dt>Description</dt><dd><%= info[:description] %></dd>
25
+ <dt>Authentication required</dt><dd><%= info[:auth] ? 'yes' : 'no' %></dd>
26
+ <dt>Scope</dt><dd><%= info[:scope] %></dd>
27
+ <dt>Aliases</dt><dd><%= info[:aliases].join(', ') %></dd>
28
+ <dt>Blocking</dt><dd><%= info[:blocking] ? 'yes' : 'no' %></dd>
29
+ </dl>
30
+ <<%= parameter_heading %> id="<%= escape_html(sections[0][:id]) %>">Input parameters<%= documentation_permalink(sections[0][:id], 'Input parameters') %></<%= parameter_heading %>>
30
31
  <% if info[:input][:parameters].empty? %>
31
32
  <p>No parameters.</p>
32
33
  <% else %>
33
- <dl>
34
- <dt>Layout:</dt>
35
- <dd><%= info[:input][:layout] %></dd>
36
- <dt>Namespace:</dt>
37
- <dd><%= info[:input][:namespace] %></dd>
34
+ <dl class="docs-metadata">
35
+ <dt>Layout</dt><dd><%= info[:input][:layout] %></dd>
36
+ <dt>Namespace</dt><dd><%= info[:input][:namespace] %></dd>
38
37
  </dl>
39
-
40
- <table class="table table-striped table-hover table-bordered">
41
- <tr>
42
- <th>Label</th>
43
- <th>Name</th>
44
- <th>Required</th>
45
- <th>Type</th>
46
- <th>Validators</th>
47
- <th>Default</th>
48
- <th>Description</th>
49
- </tr>
50
- <% info[:input][:parameters].each do |param, info| %>
51
- <tr>
52
- <td><%= info[:label] %></td>
53
- <td><%= param %></td>
54
- <td><%= info[:required] ? 'yes' : 'no' %></td>
55
- <td><%= format_param_type(info) %></td>
56
- <td><%= format_validators(info[:validators]) %></td>
57
- <td><%= info[:default] == :_nil ? '' : escape_html(info[:default]) %></td>
58
- <td><%= escape_html(info[:description]) %></td>
59
- </tr>
60
- <% end %>
61
- </table>
38
+ <div class="docs-table-scroll" tabindex="0" role="region" aria-label="Input parameters">
39
+ <table class="docs-input-parameters">
40
+ <thead><tr><th>Parameter</th><th>Type</th><th>Required</th><th>Details</th></tr></thead>
41
+ <tbody>
42
+ <% info[:input][:parameters].each do |param, parameter| %>
43
+ <tr id="<%= escape_html(documentation_parameter_anchor(resource_path: resource_path, action_name: action, direction: :input, parameter_name: param, authentication: authentication_provider)) %>">
44
+ <td class="docs-param-name"><code><%= escape_html(param) %></code><% if parameter[:label].to_s != param.to_s %><div><%= parameter[:label] %></div><% end %></td>
45
+ <td><%= format_param_type(parameter) %></td>
46
+ <td><%= parameter[:required] ? 'yes' : 'no' %></td>
47
+ <td class="docs-param-details">
48
+ <% if parameter[:description] %><p><%= escape_html(parameter[:description]) %></p><% end %>
49
+ <% if parameter.has_key?(:default) && parameter[:default] != :_nil %>
50
+ <p><strong>Default:</strong> <code><%= escape_html(parameter[:default].nil? ? 'null' : parameter[:default] == '' ? '""' : parameter[:default]) %></code></p>
51
+ <% end %>
52
+ <%= format_validators(parameter[:validators], type: parameter[:type]) %>
53
+ </td>
54
+ </tr>
55
+ <% end %>
56
+ </tbody>
57
+ </table>
58
+ </div>
62
59
  <% end %>
63
- </div>
64
-
65
- <h4>Output parameters</h4>
66
- <div class="parameters">
60
+ <<%= parameter_heading %> id="<%= escape_html(sections[1][:id]) %>">Output parameters<%= documentation_permalink(sections[1][:id], 'Output parameters') %></<%= parameter_heading %>>
67
61
  <% if info[:output][:parameters].empty? && info[:output][:format].nil? %>
68
62
  <p>No parameters.</p>
69
63
  <% else %>
70
- <dl>
71
- <dt>Layout:</dt>
72
- <dd><%= info[:output][:layout] %></dd>
73
- <dt>Namespace:</dt>
74
- <dd><%= info[:output][:namespace] %></dd>
64
+ <dl class="docs-metadata">
65
+ <dt>Layout</dt><dd><%= info[:output][:layout] %></dd>
66
+ <dt>Namespace</dt><dd><%= info[:output][:namespace] %></dd>
75
67
  </dl>
76
-
77
- <table class="table table-striped table-hover table-bordered">
78
- <tr>
79
- <th>Label</th>
80
- <th>Name</th>
81
- <th>Type</th>
82
- <th>Description</th>
83
- </tr>
84
- <% info[:output][:parameters].each do |param, info| %>
85
- <tr>
86
- <td><%= info[:label] %></td>
87
- <td><%= param %></td>
88
- <td><%= format_param_type(info) %></td>
89
- <td><%= escape_html(info[:description]) %></td>
90
- </tr>
91
- <% end %>
92
- </table>
68
+ <div class="docs-table-scroll" tabindex="0" role="region" aria-label="Output parameters">
69
+ <table class="docs-output-parameters">
70
+ <thead><tr><th>Parameter</th><th>Type</th><th>Description</th></tr></thead>
71
+ <tbody>
72
+ <% info[:output][:parameters].each do |param, parameter| %>
73
+ <tr id="<%= escape_html(documentation_parameter_anchor(resource_path: resource_path, action_name: action, direction: :output, parameter_name: param, authentication: authentication_provider)) %>">
74
+ <td class="docs-param-name"><code><%= escape_html(param) %></code><% if parameter[:label].to_s != param.to_s %><div><%= parameter[:label] %></div><% end %></td>
75
+ <td><%= format_param_type(parameter) %></td>
76
+ <td class="docs-param-details"><%= escape_html(parameter[:description]) %></td>
77
+ </tr>
78
+ <% end %>
79
+ </tbody>
80
+ </table>
81
+ </div>
93
82
  <% end %>
94
- </div>
95
-
96
- <% unless info[:examples].empty? %>
97
- <h4>Examples</h4>
98
- <% info[:examples].each_with_index do |example, i| %>
99
- <h5><%= example[:title].empty? ? "Example ##{i}" : example[:title] %></h5>
83
+ <% unless info[:examples].empty? %>
84
+ <<%= parameter_heading %> id="<%= escape_html(sections[2][:id]) %>">Examples<%= documentation_permalink(sections[2][:id], 'Examples') %></<%= parameter_heading %>>
85
+ <p>Examples use an initialized <code>api</code> client, authenticated when required. See <a href="<%= escape_html(documentation_url(anchor: 'initialization')) %>">initialization</a> and <a href="<%= escape_html(documentation_url(page: 'authentication')) %>">authentication</a>.</p>
86
+ <% info[:examples].each_with_index do |example, index| %>
87
+ <% example_title = example[:title].empty? ? "Example ##{index}" : example[:title] %>
88
+ <% example_target = documentation_reference_anchor(resource_path: resource_path, action_name: action, authentication: authentication_provider, section: :example_title, example_index: index) %>
89
+ <h4 id="<%= escape_html(example_target) %>"><%= escape_html(example_title) %><%= documentation_permalink(example_target, example_title) %></h4>
100
90
  <p><%= example[:comment] %></p>
101
-
102
- <% baseid = "example-#{resource_path.join('.')}-#{action}-#{i}" %>
103
- <%# placeholder for tabs %>
104
- <div id="<%= "#{baseid}-tabbar" %>"></div>
105
-
106
- <div id="<%= "#{baseid}-examples" %>">
107
- <% documentation_panels(:example, resource_path: resource_path, resource: resource_info, action_name: action, action: info, sample: example).each do |client, result| %>
108
- <div id="<%= escape_html("#{baseid}-#{client.id}") %>">
109
- <%=
110
- erb :"version_page/client_example", locals: {
111
- client: client,
112
- result: result,
113
- }
114
- %>
115
- </div>
116
- <% end %>
117
- </div>
118
-
119
- <script type="text/javascript">
120
- nojsTabs({
121
- tabs: document.getElementById('<%= "#{baseid}-examples" %>'),
122
- titleSelector: 'h6',
123
- tabBar: document.getElementById('<%= "#{baseid}-tabbar" %>'),
124
- hiddenClass: 'tab-hidden',
125
- activeClass: 'active',
126
- createElement: function (el) {
127
- if (el.tagName == 'UL')
128
- el.classList.add('nav', 'nav-tabs');
129
-
130
- else if (el.tagName == 'LI')
131
- el.setAttribute('role', 'presentation');
132
- }
133
- });
134
- </script>
91
+ <% old_baseid = "example-#{resource_path.join('.')}-#{action}-#{index}" %>
92
+ <% panel_baseid = authentication_resource ? documentation_reference_anchor(resource_path: resource_path, action_name: action, authentication: authentication_provider, section: :example, example_index: index) : old_baseid %>
93
+ <%= erb :'version_page/example_panels', locals: {baseid: panel_baseid, legacy_baseid: authentication_resource ? old_baseid : nil, kind: :example, changes: {resource_path: resource_path, resource: resource_info, action_name: action, action: info, sample: example}} %>
94
+ <% end %>
135
95
  <% end %>
136
- <% end %>
137
-
138
- </div>
96
+ </div>
97
+ </section>
139
98
  <% end %>
140
99
  </div>
141
-
142
100
  <% unless info[:resources].empty? %>
143
- <% sort_hash(info[:resources]).each do |r, i| %>
144
- <%=
145
- erb :"version_page/resource_body", locals: {
146
- resource: r,
147
- info: i,
148
- path: resource_path,
149
- prefix: "#{prefix}-#{resource}",
150
- name: "#{name}.#{r.humanize}",
151
- }
152
- %>
101
+ <% children_target = documentation_reference_anchor(resource_path: resource_path, authentication: authentication_provider, section: :children) %>
102
+ <h2 id="<%= escape_html(children_target) %>">Subresources<%= documentation_permalink(children_target, 'Subresources') %></h2>
103
+ <% if authentication_resource %>
104
+ <% sort_hash(info[:resources]).each do |child, child_info| %>
105
+ <%= erb :'version_page/resource_body', locals: {resource: child, info: child_info, path: resource_path, prefix: "#{prefix}-#{resource}", name: "#{name} / #{child.humanize}", authentication_resource: true, authentication_provider: authentication_provider} %>
106
+ <% end %>
107
+ <% else %>
108
+ <ul>
109
+ <% sort_hash(info[:resources]).each do |child, child_info| %>
110
+ <li><a href="<%= escape_html(documentation_url(resource: resource_path + [child.to_s])) %>"><%= escape_html((resource_path + [child.to_s]).join('.')) %></a></li>
111
+ <% end %>
112
+ </ul>
153
113
  <% end %>
154
114
  <% end %>
155
-
156
- </div> <!-- resource -->
115
+ </div>
@@ -0,0 +1,14 @@
1
+ <section id="resources">
2
+ <h1>Resources<%= documentation_permalink('resources', 'Resources') %></h1>
3
+ <% if documentation_search_query.empty? %>
4
+ <nav aria-label="Resources" data-resource-nav>
5
+ <ul class="docs-resource-list docs-resource-directory">
6
+ <% sort_hash(@help[:resources]).each do |resource, info| %>
7
+ <%= erb :'version_sidebar/resource_nav', locals: {resource: resource, info: info, path: []} %>
8
+ <% end %>
9
+ </ul>
10
+ </nav>
11
+ <% else %>
12
+ <%= erb :'documentation/search_results', locals: {search: documentation_search_results} %>
13
+ <% end %>
14
+ </section>
@@ -0,0 +1,7 @@
1
+ <section aria-labelledby="reference-usage">
2
+ <h2 id="reference-usage">Using this reference<%= documentation_permalink('reference-usage', 'Using this reference') %></h2>
3
+ <p>Choose a <strong>Language</strong> and <strong>Client</strong> variant for the examples. <strong>Examples</strong> offers the selected client's supported formats. Your choices apply to every example and stay selected as you browse.</p>
4
+ <p>Start with <a href="#initialization">Initialization</a> below and <a href="<%= escape_html(documentation_url(page: 'authentication')) %>">Authentication</a> for credentials. Open <a href="<%= escape_html(documentation_url(page: 'resources')) %>">Resources</a> to browse the API, then choose a resource to see its actions, parameters and examples.</p>
5
+ <p>Search finds resources, actions and input or output parameters. Follow a result to its reference entry.</p>
6
+ <p>While signed out, the reference shows all declared resources, actions and parameters.<% if documentation_account_context&.dig(:controls) %> Sign in to show only those available to your account.<% end %> Each API request still checks permissions for the requested operation.</p>
7
+ </section>
@@ -1,119 +1,38 @@
1
- <h1 id="api">API v<%= @v %></h1>
2
-
3
- <ol class="breadcrumb">
4
- <li><a href="<%= escape_html(root) %>"><%= escape_html(host) %></a></li>
5
- <li class="active">v<%= @v %></li>
6
- </ol>
7
-
8
- <p>
9
- This page contains a list of resources available in API v<%= @v %>, their actions,
10
- description, parameters and example usage.
11
- </p>
12
-
13
- <p>
14
- This API is based on the <a href="https://github.com/vpsfreecz/haveapi">HaveAPI</a> framework.
15
- You can access it using existing clients:
16
- </p>
17
-
18
- <ul>
19
- <li><a href="https://github.com/vpsfreecz/haveapi/tree/master/clients/ruby" target="_blank" rel="noopener">Ruby library and CLI</a></li>
20
- <li><a href="https://github.com/vpsfreecz/haveapi/tree/master/clients/js" target="_blank" rel="noopener">JavaScript and TypeScript (callback and async)</a></li>
21
- <li><a href="https://github.com/vpsfreecz/haveapi/tree/master/clients/python" target="_blank" rel="noopener">Python (sync and async)</a></li>
22
- <% settings.api_server.documentation_client_profiles(@v).each do |language, profile| %>
23
- <li><a href="https://github.com/vpsfreecz/haveapi/tree/master/clients/<%= escape_html(language) %>" target="_blank" rel="noopener"><%= { go: 'Go', rust: 'Rust (async and blocking)', typescript: 'TypeScript (generated)' }.fetch(language) %></a>: <code><%= escape_html(profile.package_name) %></code><% if profile.package_version %> <%= escape_html(profile.package_version) %><% end %></li>
1
+ <% if @documentation_page == 'overview' %>
2
+ <h1 id="api">API v<%= escape_html(@v) %><%= documentation_permalink('api', "API v#{@v}") %></h1>
3
+ <%= erb :'version_page/usage' %>
4
+ <p>Connect to <code><%= escape_html("#{base_url}#{root}") %></code> with a <a href="https://github.com/vpsfreecz/haveapi">HaveAPI client</a>.</p>
5
+ <%= erb :'version_page/client_overview' %>
6
+ <p>Examples target API v<%= escape_html(@v) %>. API clients use their own package versions and must match this API.</p>
7
+ <section id="initialization" data-doc-section>
8
+ <h2>Initialization<%= documentation_permalink('initialization', 'Initialization') %></h2>
9
+ <p>Initialize your client, then follow the <a href="<%= escape_html(documentation_url(page: 'authentication')) %>">authentication instructions</a> when credentials are required.</p>
10
+ <%= erb :'version_page/example_panels', locals: {baseid: 'init', kind: :init, changes: {}} %>
11
+ </section>
12
+ <p><a href="<%= escape_html(documentation_url(page: 'resources')) %>" data-resource-directory-link>Browse all resources</a> to find their actions, parameters and examples.</p>
13
+ <% elsif @documentation_page == 'resources' %>
14
+ <%= erb :'version_page/resource_directory' %>
15
+ <% elsif @documentation_page == 'authentication' %>
16
+ <nav aria-label="Breadcrumb"><ol><li><a href="<%= escape_html(documentation_url) %>">Overview</a></li><li aria-current="page">Authentication</li></ol></nav>
17
+ <h1 id="auth">Authentication<%= documentation_permalink('auth', 'Authentication') %></h1>
18
+ <p>Initialize your client using the <a href="<%= escape_html(documentation_url(anchor: 'initialization')) %>">overview examples</a>, then choose an authentication method.</p>
19
+ <% if @help[:authentication].empty? %><p>Authentication is disabled for this API.</p><% end %>
20
+ <% @help[:authentication].each do |name, info| %>
21
+ <%= erb :'version_page/auth_body', locals: {name: name, info: info} %>
24
22
  <% end %>
25
- <li><a href="https://github.com/vpsfreecz/haveapi/tree/master/clients/php" target="_blank" rel="noopener">PHP</a></li>
26
- <li>
27
- <a href="https://github.com/vpsfreecz/haveapi-webui" target="_blank">Generic web interface</a>
28
- (<a href="https://webui.haveapi.org/v<%= version %>/#<%= urlescape(base_url) %>" target="_blank">connect to this API</a>)
29
- </li>
30
- </ul>
31
-
32
- <p>
33
- These examples target API v<%= escape_html(@v) %>. The framework and dynamic
34
- clients share HaveAPI package versions. Generated Go, Rust and TypeScript SDKs use their
35
- own package versions. Their configured SDKs are expected to match this API.
36
- </p>
37
-
38
- <h2>Initialization</h2>
39
-
40
- <div id="init-tabbar"></div>
41
-
42
- <div id="init-examples">
43
- <% documentation_panels(:init).each do |client, result| %>
44
- <div id="<%= escape_html("init-#{client.id}") %>">
45
- <%= erb :"version_page/client_init", locals: {client: client, result: result} %>
46
- </div>
47
- <% end %>
48
- </div>
49
-
50
- <script type="text/javascript">
51
- nojsTabs({
52
- tabs: document.getElementById('init-examples'),
53
- titleSelector: 'h4',
54
- tabBar: document.getElementById('init-tabbar'),
55
- hiddenClass: 'tab-hidden',
56
- activeClass: 'active',
57
- createElement: function (el) {
58
- if (el.tagName == 'UL')
59
- el.classList.add('nav', 'nav-tabs');
60
-
61
- else if (el.tagName == 'LI')
62
- el.setAttribute('role', 'presentation');
63
- }
64
- });
65
- </script>
66
-
67
- <h1 id="auth">Authentication methods</h1>
68
- <% @help[:authentication].each do |name, info| %>
69
- <%= erb :"version_page/auth_body", locals: {name: name, info: info} %>
70
- <% end %>
71
-
72
- <h1 id="resources">Resources</h1>
73
- <p>Follows a list of all resources in this API and their actions.</p>
74
-
75
- <% sort_hash(@help[:resources]).each do |resource, info| %>
76
- <%=
77
- erb :"version_page/resource_body", locals: {
78
- resource: resource,
79
- info: info,
80
- path: [],
81
- prefix: 'root',
82
- name: nil,
83
- }
84
- %>
23
+ <% else %>
24
+ <% entry = @documentation_resource %>
25
+ <nav aria-label="Breadcrumb" data-resource-breadcrumbs>
26
+ <ol>
27
+ <li><a href="<%= escape_html(documentation_url(page: 'resources')) %>">Resources</a></li>
28
+ <% entry[:path].each_with_index do |part, index| %>
29
+ <% if index == entry[:path].length - 1 %>
30
+ <li aria-current="page"><%= escape_html(part.humanize) %></li>
31
+ <% else %>
32
+ <li><a href="<%= escape_html(documentation_url(resource: entry[:path][0..index])) %>"><%= escape_html(part.humanize) %></a></li>
33
+ <% end %>
34
+ <% end %>
35
+ </ol>
36
+ </nav>
37
+ <%= erb :'version_page/resource_body', locals: {resource: entry[:path].last, info: entry[:info], path: entry[:path][0...-1], prefix: "root#{entry[:path][0...-1].map { |part| "-#{part}" }.join}", name: entry[:key], authentication_resource: false} %>
85
38
  <% end %>
86
- </div>
87
-
88
- <script type="text/javascript">
89
- $(document).ready(function(){
90
- // Login/logout user
91
- $('.authentication a.login').click(function(event){
92
- $.ajax({
93
- type: 'GET',
94
- url: this.href,
95
- async: false,
96
- complete: function (){
97
- window.location.reload();
98
- }
99
- });
100
-
101
- event.preventDefault();
102
- });
103
-
104
- $('.authentication a.logout').click(function(event){
105
- $.ajax({
106
- type: 'GET',
107
- url: this.href,
108
- async: true,
109
- username: '_log',
110
- password: 'out',
111
- complete: function() {
112
- window.location.reload();
113
- }
114
- });
115
-
116
- event.preventDefault();
117
- });
118
- });
119
- </script>
@@ -1,20 +1,16 @@
1
- <ul>
1
+ <ul class="docs-authentication-submenu">
2
2
  <% methods.each do |method, info| %>
3
- <li>
4
- <a href="#auth-<%= method %>"><%= method.to_s.humanize %></a>
5
- <% if info[:resources] %>
6
- <ul>
7
- <% sort_hash(info[:resources]).each do |resource, info| %>
8
- <%=
9
- erb :"version_sidebar/resource_nav", locals: {
10
- resource: resource.to_s,
11
- info: info,
12
- prefix: "auth-#{method}",
13
- }
14
- %>
15
- <% end %>
16
- </ul>
17
- <% end %>
3
+ <% target = "auth-#{method}" %>
4
+ <li data-doc-nav-owner="<%= escape_html(target) %>">
5
+ <a data-doc-primary href="#<%= escape_html(target) %>"><%= escape_html(method.to_s.humanize) %></a>
6
+ <ul data-doc-subnav="<%= escape_html(target) %>">
7
+ <% unless (info[:resources] || {}).empty? %>
8
+ <li><a data-doc-subsection href="#<%= escape_html(documentation_reference_anchor(authentication: method, section: :resources)) %>">Resources</a>
9
+ <%= erb :'version_sidebar/auth_resource_nav', locals: {resources: info[:resources], path: [], authentication_provider: method} %>
10
+ </li>
11
+ <% end %>
12
+ <li><a data-doc-subsection href="#<%= escape_html(documentation_reference_anchor(authentication: method, section: :examples)) %>">Examples</a></li>
13
+ </ul>
18
14
  </li>
19
15
  <% end %>
20
16
  </ul>