nexmo-oas-renderer 2.1.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91aab3edd9be633271fd990e068b50382b9084e487c7cfd305fe02f0ac47158b
4
- data.tar.gz: e5fb1777e48e43054d461fceabdf0ce7786211303fcf468e5e8057e6ebaaa1db
3
+ metadata.gz: 016a49c9888907ebeabf72eec4ac343c5640ed75ae30e25c26ec8db60d635b15
4
+ data.tar.gz: 848b18e42b84eb80fbd32f58f07884800fcb377fc81cac9c4c46a023bdf112fe
5
5
  SHA512:
6
- metadata.gz: 8077595864ec381244b429efdcb6b87013d469d8f1c69ef81c83ba5d3891274259150ee8cec94c8b66a249ab301dff2c7e73d951da85f70f766983867fd7d93d
7
- data.tar.gz: 14bd51335bbb81fbe9a3d7c11ffbb234eafda74e11f3436bf280a51996d8e1deb3536561f40cbb207586cb6c1bd1ed9da3585f57ea07df10b8a899c6203a0420
6
+ metadata.gz: ec4dbcdd04b93935e0edfc7d83d25aaceefd03a96ca57bc93307c2d46ece8c808311ed0d5d5b3dbada11e919d8b6089dd1dd9ee08d03d1918900d6097c8fff1a
7
+ data.tar.gz: e2d8cc466dc06b928e6a79477b4e9eb65ff628b14cb8b348e4f08fd3d5118a978ed334a1d70b5668eeb39207c6d70003a499fff7aaaecef826cbfeb88f59b29f
@@ -0,0 +1,14 @@
1
+ name: Review App
2
+ on:
3
+ pull_request_target:
4
+ types: [opened, reopened, synchronize, labeled, closed]
5
+ jobs:
6
+ create-review-app:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - name: Create Review App
10
+ uses: mheap/github-action-pr-heroku-review-app@v1
11
+ env:
12
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13
+ HEROKU_PIPELINE_ID: ${{ secrets.HEROKU_PIPELINE_ID }}
14
+ HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }}
@@ -1,3 +1,6 @@
1
+ # 2.2.0
2
+ * Add error list to API reference
3
+
1
4
  # 0.11.3
2
5
  * Change oas url constructor to be entire config parameter and not only partial
3
6
  * Bump websocket-extensions, fixes CVE-2020-7663
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nexmo-oas-renderer (2.1.1)
4
+ nexmo-oas-renderer (2.3.0)
5
5
  activemodel (~> 6.0)
6
6
  activesupport (~> 6.0)
7
7
  banzai (~> 0.1.2)
@@ -18,56 +18,56 @@ PATH
18
18
  GEM
19
19
  remote: https://rubygems.org/
20
20
  specs:
21
- actioncable (6.0.3.2)
22
- actionpack (= 6.0.3.2)
21
+ actioncable (6.0.3.4)
22
+ actionpack (= 6.0.3.4)
23
23
  nio4r (~> 2.0)
24
24
  websocket-driver (>= 0.6.1)
25
- actionmailbox (6.0.3.2)
26
- actionpack (= 6.0.3.2)
27
- activejob (= 6.0.3.2)
28
- activerecord (= 6.0.3.2)
29
- activestorage (= 6.0.3.2)
30
- activesupport (= 6.0.3.2)
25
+ actionmailbox (6.0.3.4)
26
+ actionpack (= 6.0.3.4)
27
+ activejob (= 6.0.3.4)
28
+ activerecord (= 6.0.3.4)
29
+ activestorage (= 6.0.3.4)
30
+ activesupport (= 6.0.3.4)
31
31
  mail (>= 2.7.1)
32
- actionmailer (6.0.3.2)
33
- actionpack (= 6.0.3.2)
34
- actionview (= 6.0.3.2)
35
- activejob (= 6.0.3.2)
32
+ actionmailer (6.0.3.4)
33
+ actionpack (= 6.0.3.4)
34
+ actionview (= 6.0.3.4)
35
+ activejob (= 6.0.3.4)
36
36
  mail (~> 2.5, >= 2.5.4)
37
37
  rails-dom-testing (~> 2.0)
38
- actionpack (6.0.3.2)
39
- actionview (= 6.0.3.2)
40
- activesupport (= 6.0.3.2)
38
+ actionpack (6.0.3.4)
39
+ actionview (= 6.0.3.4)
40
+ activesupport (= 6.0.3.4)
41
41
  rack (~> 2.0, >= 2.0.8)
42
42
  rack-test (>= 0.6.3)
43
43
  rails-dom-testing (~> 2.0)
44
44
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
45
- actiontext (6.0.3.2)
46
- actionpack (= 6.0.3.2)
47
- activerecord (= 6.0.3.2)
48
- activestorage (= 6.0.3.2)
49
- activesupport (= 6.0.3.2)
45
+ actiontext (6.0.3.4)
46
+ actionpack (= 6.0.3.4)
47
+ activerecord (= 6.0.3.4)
48
+ activestorage (= 6.0.3.4)
49
+ activesupport (= 6.0.3.4)
50
50
  nokogiri (>= 1.8.5)
51
- actionview (6.0.3.2)
52
- activesupport (= 6.0.3.2)
51
+ actionview (6.0.3.4)
52
+ activesupport (= 6.0.3.4)
53
53
  builder (~> 3.1)
54
54
  erubi (~> 1.4)
55
55
  rails-dom-testing (~> 2.0)
56
56
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
57
- activejob (6.0.3.2)
58
- activesupport (= 6.0.3.2)
57
+ activejob (6.0.3.4)
58
+ activesupport (= 6.0.3.4)
59
59
  globalid (>= 0.3.6)
60
- activemodel (6.0.3.2)
61
- activesupport (= 6.0.3.2)
62
- activerecord (6.0.3.2)
63
- activemodel (= 6.0.3.2)
64
- activesupport (= 6.0.3.2)
65
- activestorage (6.0.3.2)
66
- actionpack (= 6.0.3.2)
67
- activejob (= 6.0.3.2)
68
- activerecord (= 6.0.3.2)
60
+ activemodel (6.0.3.4)
61
+ activesupport (= 6.0.3.4)
62
+ activerecord (6.0.3.4)
63
+ activemodel (= 6.0.3.4)
64
+ activesupport (= 6.0.3.4)
65
+ activestorage (6.0.3.4)
66
+ actionpack (= 6.0.3.4)
67
+ activejob (= 6.0.3.4)
68
+ activerecord (= 6.0.3.4)
69
69
  marcel (~> 0.3.1)
70
- activesupport (6.0.3.2)
70
+ activesupport (6.0.3.4)
71
71
  concurrent-ruby (~> 1.0, >= 1.0.2)
72
72
  i18n (>= 0.7, < 2)
73
73
  minitest (~> 5.1)
@@ -78,7 +78,7 @@ GEM
78
78
  ast (2.4.1)
79
79
  banzai (0.1.3)
80
80
  builder (3.2.4)
81
- concurrent-ruby (1.1.6)
81
+ concurrent-ruby (1.1.7)
82
82
  crass (1.0.6)
83
83
  deep_merge (1.2.1)
84
84
  diff-lcs (1.4.2)
@@ -89,9 +89,9 @@ GEM
89
89
  activesupport (>= 4.2.0)
90
90
  hansi (0.2.0)
91
91
  hash-deep-merge (0.1.1)
92
- i18n (1.8.3)
92
+ i18n (1.8.5)
93
93
  concurrent-ruby (~> 1.0)
94
- loofah (2.6.0)
94
+ loofah (2.7.0)
95
95
  crass (~> 1.0.2)
96
96
  nokogiri (>= 1.5.9)
97
97
  mail (2.7.1)
@@ -102,14 +102,14 @@ GEM
102
102
  mimemagic (0.3.5)
103
103
  mini_mime (1.0.2)
104
104
  mini_portile2 (2.4.0)
105
- minitest (5.14.1)
105
+ minitest (5.14.2)
106
106
  mustermann (1.1.1)
107
107
  ruby2_keywords (~> 0.0.1)
108
108
  mustermann-contrib (1.1.1)
109
109
  hansi (~> 0.2.0)
110
110
  mustermann (= 1.1.1)
111
111
  neatjson (0.9)
112
- nexmo_markdown_renderer (0.4.1)
112
+ nexmo_markdown_renderer (0.4.2)
113
113
  activemodel (~> 6.0)
114
114
  banzai (~> 0.1.2)
115
115
  i18n (~> 1.7)
@@ -117,8 +117,8 @@ GEM
117
117
  octicons_helper (~> 8.2)
118
118
  redcarpet (~> 3.4)
119
119
  rouge (~> 2.0.7)
120
- nio4r (2.5.2)
121
- nokogiri (1.10.9)
120
+ nio4r (2.5.4)
121
+ nokogiri (1.10.10)
122
122
  mini_portile2 (~> 2.4.0)
123
123
  oas_parser (0.25.1)
124
124
  activesupport (>= 4.0.0)
@@ -136,35 +136,35 @@ GEM
136
136
  parallel (1.19.2)
137
137
  parser (2.7.1.4)
138
138
  ast (~> 2.4.1)
139
- public_suffix (4.0.5)
139
+ public_suffix (4.0.6)
140
140
  rack (2.2.3)
141
- rack-protection (2.0.8.1)
141
+ rack-protection (2.1.0)
142
142
  rack
143
143
  rack-test (1.1.0)
144
144
  rack (>= 1.0, < 3)
145
- rails (6.0.3.2)
146
- actioncable (= 6.0.3.2)
147
- actionmailbox (= 6.0.3.2)
148
- actionmailer (= 6.0.3.2)
149
- actionpack (= 6.0.3.2)
150
- actiontext (= 6.0.3.2)
151
- actionview (= 6.0.3.2)
152
- activejob (= 6.0.3.2)
153
- activemodel (= 6.0.3.2)
154
- activerecord (= 6.0.3.2)
155
- activestorage (= 6.0.3.2)
156
- activesupport (= 6.0.3.2)
145
+ rails (6.0.3.4)
146
+ actioncable (= 6.0.3.4)
147
+ actionmailbox (= 6.0.3.4)
148
+ actionmailer (= 6.0.3.4)
149
+ actionpack (= 6.0.3.4)
150
+ actiontext (= 6.0.3.4)
151
+ actionview (= 6.0.3.4)
152
+ activejob (= 6.0.3.4)
153
+ activemodel (= 6.0.3.4)
154
+ activerecord (= 6.0.3.4)
155
+ activestorage (= 6.0.3.4)
156
+ activesupport (= 6.0.3.4)
157
157
  bundler (>= 1.3.0)
158
- railties (= 6.0.3.2)
158
+ railties (= 6.0.3.4)
159
159
  sprockets-rails (>= 2.0.0)
160
160
  rails-dom-testing (2.0.3)
161
161
  activesupport (>= 4.2.0)
162
162
  nokogiri (>= 1.6)
163
163
  rails-html-sanitizer (1.3.0)
164
164
  loofah (~> 2.3)
165
- railties (6.0.3.2)
166
- actionpack (= 6.0.3.2)
167
- activesupport (= 6.0.3.2)
165
+ railties (6.0.3.4)
166
+ actionpack (= 6.0.3.4)
167
+ activesupport (= 6.0.3.4)
168
168
  method_source
169
169
  rake (>= 0.8.7)
170
170
  thor (>= 0.20.3, < 2.0)
@@ -210,15 +210,15 @@ GEM
210
210
  rb-inotify (~> 0.9, >= 0.9.7)
211
211
  shotgun (0.9.2)
212
212
  rack (>= 1.0)
213
- sinatra (2.0.8.1)
213
+ sinatra (2.1.0)
214
214
  mustermann (~> 1.0)
215
- rack (~> 2.0)
216
- rack-protection (= 2.0.8.1)
215
+ rack (~> 2.2)
216
+ rack-protection (= 2.1.0)
217
217
  tilt (~> 2.0)
218
218
  sprockets (4.0.2)
219
219
  concurrent-ruby (~> 1.0)
220
220
  rack (> 1, < 3)
221
- sprockets-rails (3.2.1)
221
+ sprockets-rails (3.2.2)
222
222
  actionpack (>= 4.0)
223
223
  activesupport (>= 4.0)
224
224
  sprockets (>= 3.0.0)
@@ -228,10 +228,10 @@ GEM
228
228
  tzinfo (1.2.7)
229
229
  thread_safe (~> 0.1)
230
230
  unicode-display_width (1.7.0)
231
- websocket-driver (0.7.2)
231
+ websocket-driver (0.7.3)
232
232
  websocket-extensions (>= 0.1.0)
233
233
  websocket-extensions (0.1.5)
234
- zeitwerk (2.3.1)
234
+ zeitwerk (2.4.1)
235
235
 
236
236
  PLATFORMS
237
237
  ruby
@@ -0,0 +1 @@
1
+ web: bundle exec ./exe/nexmo-oas-renderer
@@ -0,0 +1,15 @@
1
+ {
2
+ "buildpacks": [{ "url": "heroku/ruby" }],
3
+ "env": {
4
+ "RACK_ENV": "production",
5
+ "RAILS_ENV": "production",
6
+ "OAS_PATH": "samples"
7
+ },
8
+ "stack": "heroku-18",
9
+ "formation": {
10
+ "web": {
11
+ "quantity": 1,
12
+ "size": "free"
13
+ }
14
+ }
15
+ }
@@ -13,6 +13,7 @@ require_relative './presenters/open_api_specification'
13
13
  require_relative './presenters/navigation'
14
14
  require_relative './presenters/request_body_raw'
15
15
  require_relative './presenters/response_tabs'
16
+ require_relative './presenters/content_switcher'
16
17
  require_relative './helpers/render'
17
18
  require_relative './helpers/navigation'
18
19
  require_relative './helpers/summary'
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nexmo
4
+ module OAS
5
+ module Renderer
6
+ module Presenters
7
+ class ContentSwitcher
8
+ def initialize(format:, label:, theme_light:, force_type: nil)
9
+ @format = format
10
+ @panels = []
11
+ @label = label
12
+ @force_type = force_type
13
+ @theme_light = theme_light
14
+ end
15
+
16
+ def add_content(title:, content:, tab_id:, active:)
17
+ @panels.push({
18
+ 'title' => title,
19
+ 'content' => content,
20
+ 'x-tab-id' => tab_id,
21
+ 'active' => active,
22
+ })
23
+ end
24
+
25
+ def render
26
+ type = 'tabs'
27
+ type = 'dropdown' if @panels.length >= 8
28
+
29
+ type = @force_type if @force_type
30
+
31
+ [:"open_api/content_switcher/_#{type}", locals: {
32
+ panels: @panels,
33
+ format: @format,
34
+ label: @label,
35
+ switcher: self,
36
+ theme_light: @theme_light,
37
+ }]
38
+ end
39
+
40
+ def id
41
+ @id ||= "s-#{SecureRandom.hex}"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -8,7 +8,7 @@ module Nexmo
8
8
  module Renderer
9
9
  module Presenters
10
10
  class ResponseTabs
11
- attr_reader :format
11
+ attr_reader :format, :switcher
12
12
 
13
13
  def initialize(format, response, content, endpoint, theme_light: nil)
14
14
  @format = format
@@ -16,6 +16,7 @@ module Nexmo
16
16
  @content = content
17
17
  @endpoint = endpoint
18
18
  @theme_light = theme_light
19
+ @switcher ||= @response.schema(@format)['x-switcher']
19
20
  end
20
21
 
21
22
  def tab_links
@@ -1,4 +1,9 @@
1
- if(document.querySelector(".oas-wrapper")){
1
+ document.addEventListener("DOMContentLoaded", function() {
2
+ // Only run this JS on OAS pages
3
+ if(!document.querySelector(".oas-wrapper")){
4
+ return;
5
+ }
6
+
2
7
  if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
3
8
  var queryString = new URLSearchParams(window.location.search);
4
9
  if (!queryString.get('theme')) {
@@ -7,59 +12,64 @@ if(document.querySelector(".oas-wrapper")){
7
12
  }
8
13
  }
9
14
 
10
- document.addEventListener("DOMContentLoaded", function() {
11
- // Handle people clicking on oneOf tabs by changing every one on the page
12
- var oneOfTabs = document.querySelectorAll('[data-tab-link]');
13
- Array.from(oneOfTabs).forEach(function (element) {
14
- element.addEventListener('click', function (event) {
15
- var link = event.target.getAttribute('data-tab-link');
16
- var matchingTabs = document.querySelectorAll('[data-tab-link="' + link + '"]');
17
- Array.from(matchingTabs).forEach(function (element) {
18
- element.dispatchEvent(new Event('toggle'));
19
- });
15
+ // Handle people clicking on oneOf tabs by changing every one on the page
16
+ var oneOfTabs = document.querySelectorAll('[data-tab-link]');
17
+ Array.from(oneOfTabs).forEach(function (element) {
18
+ element.addEventListener('click', function (event) {
19
+ var link = event.target.getAttribute('data-tab-link');
20
+ var matchingTabs = document.querySelectorAll('[data-tab-link="' + link + '"]');
21
+ Array.from(matchingTabs).forEach(function (element) {
22
+ element.dispatchEvent(new Event('toggle'));
23
+
24
+ // Switch anything that's in a dropdown
25
+ if (element.parentNode.className.indexOf("Vlt-dropdown__panel__content") !== -1) {
26
+ // This is *very* structure dependent, but also the most compatible way to handle it
27
+ var panel = element.parentNode.parentNode;
28
+ var titleNodes = Array.from(panel.previousSibling.previousSibling.firstChild.childNodes);
29
+ titleNodes[1].textContent = element.textContent;
30
+ }
20
31
  });
21
32
  });
33
+ });
22
34
 
23
- var toggleTopNav = function(event, closeOnly) {
35
+ var toggleTopNav = function(event, closeOnly) {
24
36
 
25
- if (event) {
26
- if (!Array.from(event.target.classList).includes("oas-trigger")) {
27
- return;
28
- }
29
- }
30
-
31
- var c = document.querySelector('.oas-trigger-content');
32
- if (closeOnly === true) {
33
- c.style.display = "none";
37
+ if (event) {
38
+ if (!Array.from(event.target.classList).includes("oas-trigger")) {
34
39
  return;
35
40
  }
36
- c.style.display = c.style.display == 'block' ? 'none' : "block";
37
- };
41
+ }
38
42
 
39
- if (document.querySelector('.oas-trigger')) {
40
- document.querySelector('.oas-trigger').addEventListener("click", toggleTopNav);
43
+ var c = document.querySelector('.oas-trigger-content');
44
+ if (closeOnly === true) {
45
+ c.style.display = "none";
46
+ return;
41
47
  }
48
+ c.style.display = c.style.display == 'block' ? 'none' : "block";
49
+ };
50
+
51
+ if (document.querySelector('.oas-trigger')) {
52
+ document.querySelector('.oas-trigger').addEventListener("click", toggleTopNav);
53
+ }
42
54
 
43
- document.querySelectorAll('a').forEach((element) => {
44
- var href = element.getAttribute("href");
45
- if (!href){ return; }
46
- if (href.slice(0,1) !== "#"){ return; }
47
- element.addEventListener('click', function (event) {
48
- event.preventDefault();
55
+ document.querySelectorAll('a').forEach((element) => {
56
+ var href = element.getAttribute("href");
57
+ if (!href){ return; }
58
+ if (href.slice(0,1) !== "#"){ return; }
59
+ element.addEventListener('click', function (event) {
60
+ event.preventDefault();
49
61
 
50
- toggleTopNav(null, true);
62
+ toggleTopNav(null, true);
51
63
 
52
- var to = document.querySelector(event.target.hash)
53
- history.pushState({}, '', event.target.href);
54
- window.scrollTo({
55
- top: (window.scrollY + to.getBoundingClientRect().y) - 70,
56
- left: 0,
57
- })
64
+ var to = document.querySelector(event.target.hash)
65
+ history.pushState({}, '', event.target.href);
66
+ window.scrollTo({
67
+ top: (window.scrollY + to.getBoundingClientRect().y) - 70,
68
+ left: 0,
69
+ })
58
70
 
59
71
 
60
- });
61
72
  });
62
-
63
73
  });
64
- }
74
+ });
65
75
 
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Copyright (c) 2001-present, Vonage.
3
+ *
4
+ * Dropdowns (requires core)
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ Volta.dropdown = function () {
10
+ var _class = {
11
+ wrapper: 'Vlt-dropdown',
12
+ block: 'Vlt-dropdown__block',
13
+ btn: 'Vlt-dropdown__trigger',
14
+ btnLegacy: 'Vlt-dropdown__btn',
15
+ dismissed: 'Vlt-callout--dismissed',
16
+ expanded: 'Vlt-dropdown--expanded',
17
+ label: 'Vlt-dropdown__label',
18
+ link: 'Vlt-dropdown__link',
19
+ noCloseLink: 'Vlt-dropdown__link--noclose',
20
+ noCloseBlock: 'Vlt-dropdown__block--noclose',
21
+ panel: 'Vlt-dropdown__panel',
22
+ panelContent: 'Vlt-dropdown__panel__content',
23
+ selection: 'Vlt-dropdown__selection',
24
+ switch: 'Vlt-switch',
25
+ switchSlider: 'Vlt-switch__slider'
26
+ }
27
+
28
+ function Dropdown() {}
29
+
30
+ Dropdown.prototype = {
31
+ init: function(element, supressClickHandler) {
32
+ this.dropdown = element;
33
+ this.selection = this.dropdown.querySelector('.' + _class.selection);
34
+ this.isSelectionVisible = !!this.selection;
35
+ this.btn = this.dropdown.querySelector('.' + _class.btn) || this.dropdown.querySelector('.' + _class.btnLegacy);
36
+ this._suppress = supressClickHandler;
37
+
38
+ if(!this._suppress) {
39
+ this._addEventListener();
40
+ }
41
+ },
42
+ _addEventListener: function(){
43
+ var openHandler = this.open.bind(this);
44
+ this.dropdown.addEventListener('click', openHandler, { once: true })
45
+ },
46
+ close: function(text) {
47
+ if(text) {
48
+ this._setDropdownSelectionText(text);
49
+ }
50
+ this.dropdown.classList.remove(_class.expanded);
51
+
52
+ if(!this._suppress){
53
+ this._addEventListener();
54
+ }
55
+
56
+ },
57
+ _closeEventHandler: undefined,
58
+ _closeEvent: function(e) {
59
+ var targetIsPanel = Volta._hasClass(e.target, _class.panel);
60
+ var parentIsPanel = Volta._closest(e.target, '.' + _class.panelContent, _class.panel) !== null;
61
+ var parentLink = Volta._closest(e.target, '.' + _class.link, _class.wrapper);
62
+ var parentIsLink = parentLink && parentLink.length === 1;
63
+ var isSwitchSlider = Volta._hasClass(e.target, _class.switchSlider);
64
+ var isParentSwitch = Volta._closest(e.target,'.' + _class.switch, _class.link);
65
+ var isNoClose = Volta._hasClass(e.target, _class.noCloseLink) || Volta._hasClass(e.target, _class.noCloseBlock);
66
+ var isNoCloseParent = Volta._closest(e.target,'.' + _class.noCloseLink, _class.link) || Volta._closest(e.target,'.' + _class.noCloseBlock, _class.noCloseBlock);
67
+ var isInput = e.target instanceof HTMLInputElement;
68
+
69
+ if(!targetIsPanel && !parentIsPanel && !parentIsLink && !isNoClose && !isInput && !isNoCloseParent) {
70
+ e.preventDefault();
71
+ e.stopPropagation();
72
+ }
73
+
74
+ if(isSwitchSlider || isParentSwitch || isNoClose || isInput || isNoCloseParent) {
75
+ return null;
76
+ }
77
+
78
+ var text;
79
+ if(parentIsPanel && Volta._hasClass(e.target, _class.label)) {
80
+ text = e.target.innerHTML;
81
+ } else if (parentIsPanel) {
82
+ var label = e.target.querySelector('.' + _class.label);
83
+ if(label) {
84
+ text = label.innerHTML;
85
+ }
86
+ }
87
+
88
+ this.close(text);
89
+
90
+ document.querySelector('body').removeEventListener('click', this._closeEventHandler );
91
+ },
92
+ open: function(event) {
93
+ if(event) {
94
+ event.preventDefault();
95
+ event.stopPropagation();
96
+ }
97
+
98
+ this.dropdown.classList.add(_class.expanded);
99
+
100
+ if(!this._suppress){
101
+ this._closeEventHandler = this._closeEvent.bind(this);
102
+ document.querySelector('body').addEventListener('click', this._closeEventHandler );
103
+ }
104
+ },
105
+ _setDropdownSelectionText: function(text) {
106
+ if(this.isSelectionVisible) {
107
+ this.selection.innerText = text;
108
+ } else {
109
+ this.btn.innerText = text;
110
+ this.btn.value = text;
111
+ }
112
+ },
113
+ _suppress: false
114
+ }
115
+
116
+ return {
117
+ create: create,
118
+ init: attachDropdownHandlers
119
+ }
120
+
121
+ /**
122
+ * @public
123
+ *
124
+ * @description Attach a listeners to dropdowns
125
+ */
126
+ function attachDropdownHandlers() {
127
+ document.querySelectorAll('.' + _class.wrapper).forEach(attachHandler);
128
+
129
+ function attachHandler(dropdown) {
130
+ create(dropdown);
131
+ }
132
+ }
133
+
134
+ /**
135
+ * @private
136
+ *
137
+ * @description Create a dropdown element
138
+ * @param {HTMLElement} element
139
+ */
140
+ function create(element){
141
+ var dropdown = Object.create(Dropdown.prototype, {})
142
+ dropdown.init(element);
143
+ return dropdown;
144
+ }
145
+ }();
@@ -53,6 +53,7 @@
53
53
  .oas-wrapper .oas-parameter-description {
54
54
  margin-left: 16px; }
55
55
  .oas-wrapper .oas-parameter-meta {
56
+ padding-bottom: 2px;
56
57
  border-bottom: 1px solid #ccc;
57
58
  margin-bottom: 4px; }
58
59
  .oas-wrapper .oas-parameter-nested {
@@ -3,7 +3,7 @@
3
3
  module Nexmo
4
4
  module OAS
5
5
  module Renderer
6
- VERSION = '2.1.1'
6
+ VERSION = '2.4.0'
7
7
  end
8
8
  end
9
9
  end
@@ -5,10 +5,11 @@
5
5
  <script src="/assets/javascripts/volta.accordion.js"></script>
6
6
  <script src="/assets/javascripts/volta.tabs.js"></script>
7
7
  <script src="/assets/javascripts/volta.modal.js"></script>
8
+ <script src="/assets/javascripts/volta.dropdown.js"></script>
8
9
  <script src="/assets/javascripts/volta.tooltip.js"></script>
9
10
  <script src="/assets/javascripts/nexmo-oas-renderer.js?a=1"></script>
10
11
  <script src="/assets/javascripts/components/format.js"></script>
11
12
  <script type="text/javascript">
12
- Volta.init(["accordion", "tab", "modal", "tooltip"]);
13
+ Volta.init(["accordion", "tab", "modal", "tooltip", "dropdown"]);
13
14
  new Format
14
15
  </script>
@@ -0,0 +1,34 @@
1
+ <% if definition.raw['x-errors'] %>
2
+ <div>
3
+ <div class="Vlt-grid">
4
+ <div class="Vlt-col oas-left-panel" style="padding-bottom: 36px;">
5
+ <h2 id="errors">Errors</h2>
6
+ <p>
7
+ The following is a non-exhaustive list of error codes that may occur while using this API. These codes are in addition to any of our <a href="/api-errors">generic error codes</a>.
8
+ </p>
9
+ </div>
10
+ <div class="Vlt-col oas-right-panel"></div>
11
+ </div>
12
+ <div class="Vlt-grid">
13
+ <div class="Vlt-col Vlt-table oas-left-panel">
14
+ <table>
15
+ <thead>
16
+ <tr>
17
+ <th>Code</th>
18
+ <th>Details</th>
19
+ </tr>
20
+ </thead>
21
+ <tbody>
22
+ <% definition.raw['x-errors'].each do |name, body| %>
23
+ <tr>
24
+ <td><a href="/api-errors/<%= @specification.definition_name %>#<%= name %>"><b><%= name %></b></a></td>
25
+ <td><%= body['description'].render_markdown %> </td>
26
+ </tr>
27
+ <% end %>
28
+ </tbody>
29
+ </table>
30
+ </div>
31
+ <div class="Vlt-col oas-right-panel"></div>
32
+ </div>
33
+ </div>
34
+ <% end %>
@@ -39,6 +39,20 @@
39
39
  </div>
40
40
  </div>
41
41
 
42
+
43
+ <% if @specification.groups.size > 1 %>
44
+ <h4>Jump to:</h4>
45
+ <div style="margin-bottom: 30px; padding: 8px;">
46
+ <% @specification.groups.each do |name, endpoints| %>
47
+ <% if name %>
48
+ <% group = definition.raw['tags'].detect { |tag| tag['name'].capitalize == name.capitalize } %>
49
+ <p><a href="#<%= group['name'].parameterize %>"><%= group['name'] %> &raquo;</a></p>
50
+ <p class="Vlt-grey-darker"><%= group['description']&.render_markdown %></p>
51
+ <% end %>
52
+ <% end %>
53
+ </div>
54
+ <% end %>
55
+
42
56
  <%
43
57
  # If there's only one group, everything is untagged
44
58
  if @specification.groups.size === 1
@@ -13,6 +13,9 @@
13
13
  <a href="#webhooks" class="Vlt-btn Vlt-btn--tertiary group-link">Webhooks</a>
14
14
  <% end %>
15
15
 
16
+ <% if definition.raw['x-errors'] %>
17
+ <a href="#errors" class="Vlt-btn Vlt-btn--tertiary group-link">Errors</a>
18
+ <% end %>
16
19
 
17
20
  <% if @specification.formats.size > 1 %>
18
21
  <div class="Vlt-native-dropdown">
@@ -44,6 +47,10 @@
44
47
  <a href="#top" class="Vlt-btn Vlt-btn--tertiary group-link">Available Operations</a>
45
48
  <% end %>
46
49
 
50
+ <% if definition.raw['x-errors'] %>
51
+ <a href="#errors" class="Vlt-btn Vlt-btn--tertiary group-link">Errors</a>
52
+ <% end %>
53
+
47
54
  <br />
48
55
  <br />
49
56
 
@@ -29,14 +29,7 @@
29
29
  <% unless endpoint.request_body.exhibits_one_of_multiple_schemas?(format) %>
30
30
 
31
31
  <%
32
- # @mheap: This is hacky handling for allOf, but it works for now
33
- # We probably want real allOf support in OasParser, but that's more time than I have right now
34
- allOf = endpoint.request_body.content[format]['schema']['allOf']
35
- if allOf
36
- params = endpoint.request_body.handle_all_of(allOf)
37
- else
38
- params = endpoint.request_body.properties_for_format(format)
39
- end
32
+ params = endpoint.request_body.properties_for_format(format)
40
33
  if params
41
34
  %>
42
35
 
@@ -46,9 +39,10 @@
46
39
 
47
40
  <%
48
41
  # This can likely be better done as a presenter, but it works for now
49
- schema = endpoint.request_body.content[format]['schema']['oneOf']
42
+ request = endpoint.request_body.content[format]['schema']
43
+ schema = request['oneOf']
50
44
  %>
51
- <%= erb :'open_api/_tabbed_parameters', locals: { body: endpoint.request_body, schema: schema, format: format, callback: callback } %>
45
+ <%= erb :'open_api/_tabbed_parameters', locals: { body: endpoint.request_body, request: request, schema: schema, format: format, callback: callback } %>
52
46
  <%
53
47
  end
54
48
  end
@@ -65,6 +65,12 @@
65
65
  <% if parameter.maximum || parameter.raw['maxLength'] %>
66
66
  | <span class="constraint">Max:</span> <%= parameter.maximum || parameter.raw['maxLength'] %>
67
67
  <% end %>
68
+ <% if parameter.raw['deprecated'] %>
69
+ | <span class="constraint">DEPRECATED</span> <span>: This field has been deprecated. </span>
70
+ <% end %>
71
+ <% if parameter.raw['x-replace-with']%>
72
+ <span> <%= 'Please use ' + '<code>'+ parameter.raw['x-replace-with'] + '</code>' + ' instead.' %> </span>
73
+ <% end %>
68
74
  </div>
69
75
 
70
76
  <%= (parameter.description || parameter.schema['description'] || '').render_markdown %>
@@ -1,18 +1,16 @@
1
- <% tabs = Nexmo::OAS::Renderer::Presenters::ResponseTabs.new(format, response, content, endpoint, theme_light: @theme_light) %>
1
+ <%
2
+ tabs = Nexmo::OAS::Renderer::Presenters::ResponseTabs.new(format, response, content, endpoint, theme_light: @theme_light)
2
3
 
3
- <div class='Vlt-tabs js-format' data-format='<%= tabs.format %>'>
4
- <div class='Vlt-tabs__header' role='tablist' aria-label='Responses'>
5
- <% tabs.tab_links.each do |link| %>
6
- <div role='tab' class='<%= link.css_classes %>' <% if link.data_tab_link %>data-tab-link="<%= link.data_tab_link %>"<% end %>>
7
- <%= link.content %>
8
- </div>
9
- <% end %>
10
- </div>
11
- <div class='Vlt-tabs__content'>
12
- <% tabs.tab_panels.each do |panel| %>
13
- <div class='<%= panel.css_classes %>'>
14
- <%= erb *panel.content %>
15
- </div>
16
- <% end %>
17
- </div>
18
- </div>
4
+ switcher = Nexmo::OAS::Renderer::Presenters::ContentSwitcher.new(label: "Response Example", format: format, force_type: tabs.switcher, theme_light: @theme_light)
5
+
6
+ tabs.tab_links.each_with_index do |v,k|
7
+ switcher.add_content(
8
+ title: v.content,
9
+ content: (erb *tabs.tab_panels[k].content),
10
+ tab_id: v.data_tab_link,
11
+ active: k == 0
12
+ )
13
+ end
14
+ %>
15
+
16
+ <%= erb *switcher.render %>
@@ -12,8 +12,7 @@
12
12
  s
13
13
  end
14
14
 
15
-
16
- panels = []
15
+ switcher = Nexmo::OAS::Renderer::Presenters::ContentSwitcher.new(label: "Request Details", format: format, force_type: request['x-switcher'], theme_light: @theme_light)
17
16
 
18
17
  schemas.each_with_index do |schema, index|
19
18
  if schema['properties']
@@ -25,40 +24,21 @@
25
24
  end
26
25
  end
27
26
 
28
- panels.push({
29
- 'description' => schema['title'] || schema['description'],
30
- 'parameters' => schema['properties'],
31
- 'oneOf' => schema['oneOf'],
32
- 'x-tab-id' => schema['x-tab-id'] || schema['title'].parameterize,
33
- 'active' => index == 0
34
- })
27
+
28
+ if schema['oneOf']
29
+ content = (erb :'open_api/_tabbed_parameters', locals: { body: body, request: schema, schema: schema['oneOf'], format: format, callback: callback })
30
+ else
31
+ content = (erb :'open_api/_parameters', locals: { parameters: schema['properties'], callback: callback })
32
+ end
33
+
34
+ switcher.add_content(
35
+ title: schema['title'] || schema['description'],
36
+ content: content,
37
+ tab_id: schema['x-tab-id'],
38
+ active: index == 0
39
+ )
35
40
  end
36
41
  %>
37
42
 
38
- <div class="Vlt-tabs js-format" data-format="<%= format %>">
39
- <div class="Vlt-tabs__header" role="tablist" aria-label="Responses">
40
- <% panels.each do |panel| %>
41
- <div role="tab" data-tab-link="<%= panel['x-tab-id'] %>" class="Vlt-tabs__link <%= panel['active'] ? 'Vlt-tabs__link_active' : '' %>">
42
- <%= panel['description'] %>
43
- </div>
44
- <% end %>
45
- </div>
46
- <div class="Vlt-tabs__content">
47
- <% panels.each do |panel| %>
48
- <div class="Vlt-tabs__panel <%= panel['active'] ? 'Vlt-tabs__panel_active' : '' %>">
49
- <%
50
- # Nested oneOf?
51
- if panel['oneOf']
52
- %>
53
- <%= erb :'open_api/_tabbed_parameters', locals: { body: body, schema: panel['oneOf'], format: format, callback: callback } %>
54
- <%
55
- else
56
- %>
57
-
58
- <%= erb :'open_api/_parameters', locals: { parameters: panel['parameters'], callback: callback } %>
59
- <% end %>
60
- </div>
61
- <% end %>
62
- </div>
63
- </div>
43
+ <%= erb *switcher.render %>
64
44
 
@@ -0,0 +1,22 @@
1
+ <div class="Vlt-dropdown Vlt-dropdown--full-width">
2
+ <div class="Vlt-dropdown__trigger Vlt-dropdown__trigger--btn"><button class="Vlt-btn Vlt-btn--<%= (theme_light ? "secondary" : "tertiary") %>"><%= label %>: <span class="Vlt-dropdown__selection"><%= panels[0]['title'] %></span></button></div>
3
+ <div class="Vlt-dropdown__panel">
4
+ <div data-tab-content="<%= switcher.id %>" class="Vlt-dropdown__panel__content">
5
+ <% panels.each do |panel| %>
6
+ <div role="tab" data-tab-link="<%= panel['x-tab-id'] || panel['title'].parameterize %>" class="Vlt-dropdown__link Vlt-dropdown__label Vlt-js-tabs__link"><%= panel['title'] %></div>
7
+ <% end %>
8
+ </div>
9
+ </div>
10
+ </div>
11
+
12
+
13
+ <div class="js-format" data-format="<%= format %>">
14
+ <div id="<%= switcher.id %>" class="Vlt-js-tabs__content">
15
+ <% panels.each do |panel| %>
16
+ <div class="Vlt-js-tabs__panel <%= panel['active'] ? 'Vlt-js-tabs__panel_active' : '' %>">
17
+ <%= panel['content'] %>
18
+ </div>
19
+ <% end %>
20
+ </div>
21
+ </div>
22
+
@@ -0,0 +1,18 @@
1
+ <div class="Vlt-tabs js-format" data-format="<%= format %>">
2
+ <div class="Vlt-tabs__header" role="tablist" aria-label="<%= label %>">
3
+ <% panels.each do |panel| %>
4
+ <div role="tab" data-tab-link="<%= panel['x-tab-id'] || panel['title'].parameterize %>" class="Vlt-tabs__link <%= panel['active'] ? 'Vlt-tabs__link_active' : '' %>">
5
+ <%= panel['title'] %>
6
+ </div>
7
+ <% end %>
8
+ </div>
9
+ <div class="Vlt-tabs__content">
10
+ <% panels.each do |panel| %>
11
+ <div class="Vlt-tabs__panel <%= panel['active'] ? 'Vlt-tabs__panel_active' : '' %>">
12
+ <%= panel['content'] %>
13
+ </div>
14
+ <% end %>
15
+ </div>
16
+ </div>
17
+
18
+
@@ -21,6 +21,6 @@
21
21
  <% end %>
22
22
 
23
23
  <%= erb :'open_api/_webhooks', locals: { definition: definition } %>
24
-
24
+ <%= erb :'open_api/_errors', locals: {definition: definition } %>
25
25
  </div>
26
26
  </div>
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  # Specify which files should be added to the gem when it is released.
26
26
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
27
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|samples)/}) }
29
29
  end
30
30
  spec.bindir = 'exe'
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexmo-oas-renderer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabian Rodriguez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-21 00:00:00.000000000 Z
11
+ date: 2020-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -243,6 +243,7 @@ extensions: []
243
243
  extra_rdoc_files: []
244
244
  files:
245
245
  - ".env.example"
246
+ - ".github/workflows/pull_request-review.yml"
246
247
  - ".github/workflows/push-docker-publish.yml"
247
248
  - ".gitignore"
248
249
  - ".rspec"
@@ -254,8 +255,10 @@ files:
254
255
  - Gemfile
255
256
  - Gemfile.lock
256
257
  - LICENSE.txt
258
+ - Procfile
257
259
  - README.md
258
260
  - Rakefile
261
+ - app.json
259
262
  - bin/console
260
263
  - bin/setup
261
264
  - exe/nexmo-oas-renderer
@@ -271,6 +274,7 @@ files:
271
274
  - lib/nexmo/oas/renderer/helpers/summary.rb
272
275
  - lib/nexmo/oas/renderer/helpers/url.rb
273
276
  - lib/nexmo/oas/renderer/presenters/api_specification.rb
277
+ - lib/nexmo/oas/renderer/presenters/content_switcher.rb
274
278
  - lib/nexmo/oas/renderer/presenters/endpoint.rb
275
279
  - lib/nexmo/oas/renderer/presenters/groups.rb
276
280
  - lib/nexmo/oas/renderer/presenters/navigation.rb
@@ -300,6 +304,7 @@ files:
300
304
  - lib/nexmo/oas/renderer/public/assets/javascripts/tooltip.min.js
301
305
  - lib/nexmo/oas/renderer/public/assets/javascripts/volta.accordion.js
302
306
  - lib/nexmo/oas/renderer/public/assets/javascripts/volta.core.js
307
+ - lib/nexmo/oas/renderer/public/assets/javascripts/volta.dropdown.js
303
308
  - lib/nexmo/oas/renderer/public/assets/javascripts/volta.modal.js
304
309
  - lib/nexmo/oas/renderer/public/assets/javascripts/volta.tabs.js
305
310
  - lib/nexmo/oas/renderer/public/assets/javascripts/volta.tooltip.js
@@ -348,6 +353,7 @@ files:
348
353
  - lib/nexmo/oas/renderer/views/open_api/_callbacks.erb
349
354
  - lib/nexmo/oas/renderer/views/open_api/_code_examples.erb
350
355
  - lib/nexmo/oas/renderer/views/open_api/_endpoint.erb
356
+ - lib/nexmo/oas/renderer/views/open_api/_errors.erb
351
357
  - lib/nexmo/oas/renderer/views/open_api/_header.erb
352
358
  - lib/nexmo/oas/renderer/views/open_api/_model.erb
353
359
  - lib/nexmo/oas/renderer/views/open_api/_navigation.erb
@@ -365,6 +371,8 @@ files:
365
371
  - lib/nexmo/oas/renderer/views/open_api/_tabbed_parameters.erb
366
372
  - lib/nexmo/oas/renderer/views/open_api/_tabbed_single_parameter.erb
367
373
  - lib/nexmo/oas/renderer/views/open_api/_webhooks.erb
374
+ - lib/nexmo/oas/renderer/views/open_api/content_switcher/_dropdown.erb
375
+ - lib/nexmo/oas/renderer/views/open_api/content_switcher/_tabs.erb
368
376
  - lib/nexmo/oas/renderer/views/open_api/show.erb
369
377
  - lib/nexmo/oas/renderer/views/static/404.erb
370
378
  - nexmo-oas-renderer.gemspec