nexmo-oas-renderer 2.4.1 → 2.5.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: 76599ec305ebd6c8c31bb6ef59866f9ee4973dbb58e5214517e74c522357398e
4
- data.tar.gz: f0b864fa9c8751ddf292728f492d0f0b920b751fa2898ab6c5b6a3694b192bb8
3
+ metadata.gz: 370c5844bff4cc86ca8a558fe2d1f0dcc54103440325e836c3b9fb1043ab7c92
4
+ data.tar.gz: e62da1e342e6a00571750c398ec673e6ffb01252afa50c360e0a4cc3ea568ff2
5
5
  SHA512:
6
- metadata.gz: d97b6959b622e3c407d385af7e54af0690a34ae6ef6720dee5e75c3db05850c3b3a37b1d60f6e1826c10d76584bcd56dfddde8a3d0055aba9fae9c529f6275a6
7
- data.tar.gz: a30ee39bf768f4c3d04adbe43bc5127db3d9af982bd90cf457481868c8154bef574219ab7a0e04525ae76990212f80b1a76301863ebe4e03d0d885ff180b65fc
6
+ metadata.gz: 4332086bfd477d6d137e16943b014487788f24a78125ce7f23e0b05f9e81debc09709415c7e734050e41c4e43b1a354a8292dcff8e89213c19ea868c0a5510ff
7
+ data.tar.gz: f6f1dd5a4545f2be0fa1381596577514a530c3623a070f9b69a48e17ef7ae209b6058ad0b66f1fc5cafca526a438ce5b4be8172cfb5542411ccb5797ad4bc7bb
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nexmo-oas-renderer (2.4.0)
4
+ nexmo-oas-renderer (2.5.0)
5
5
  activemodel (~> 6.0)
6
6
  activesupport (~> 6.0)
7
7
  banzai (~> 0.1.2)
@@ -10,7 +10,7 @@ PATH
10
10
  nexmo_markdown_renderer (~> 0.3)
11
11
  oas_parser (~> 0.25.1)
12
12
  octicons_helper (~> 8.2)
13
- redcarpet (= 3.4.0)
13
+ redcarpet (= 3.5.1)
14
14
  sass (~> 3.1)
15
15
  shotgun (~> 0.9)
16
16
  sinatra (~> 2.0)
@@ -84,7 +84,7 @@ GEM
84
84
  diff-lcs (1.4.2)
85
85
  dotenv (2.7.6)
86
86
  erubi (1.9.0)
87
- ffi (1.13.1)
87
+ ffi (1.14.2)
88
88
  globalid (0.4.2)
89
89
  activesupport (>= 4.2.0)
90
90
  hansi (0.2.0)
@@ -101,7 +101,7 @@ GEM
101
101
  method_source (1.0.0)
102
102
  mimemagic (0.3.5)
103
103
  mini_mime (1.0.2)
104
- mini_portile2 (2.4.0)
104
+ mini_portile2 (2.5.0)
105
105
  minitest (5.14.2)
106
106
  mustermann (1.1.1)
107
107
  ruby2_keywords (~> 0.0.1)
@@ -109,7 +109,7 @@ GEM
109
109
  hansi (~> 0.2.0)
110
110
  mustermann (= 1.1.1)
111
111
  neatjson (0.9)
112
- nexmo_markdown_renderer (0.5.0)
112
+ nexmo_markdown_renderer (0.7.5)
113
113
  activemodel (~> 6.0)
114
114
  banzai (~> 0.1.2)
115
115
  i18n (~> 1.7)
@@ -118,8 +118,9 @@ GEM
118
118
  redcarpet (~> 3.4)
119
119
  rouge (~> 2.0.7)
120
120
  nio4r (2.5.4)
121
- nokogiri (1.10.10)
122
- mini_portile2 (~> 2.4.0)
121
+ nokogiri (1.11.1)
122
+ mini_portile2 (~> 2.5.0)
123
+ racc (~> 1.4)
123
124
  oas_parser (0.25.1)
124
125
  activesupport (>= 4.0.0)
125
126
  addressable (~> 2.3)
@@ -137,6 +138,7 @@ GEM
137
138
  parser (2.7.1.4)
138
139
  ast (~> 2.4.1)
139
140
  public_suffix (4.0.6)
141
+ racc (1.5.2)
140
142
  rack (2.2.3)
141
143
  rack-protection (2.1.0)
142
144
  rack
@@ -173,7 +175,7 @@ GEM
173
175
  rb-fsevent (0.10.4)
174
176
  rb-inotify (0.10.1)
175
177
  ffi (~> 1.0)
176
- redcarpet (3.4.0)
178
+ redcarpet (3.5.1)
177
179
  regexp_parser (1.7.1)
178
180
  rexml (3.2.4)
179
181
  rouge (2.0.7)
@@ -5,7 +5,9 @@ module Nexmo
5
5
  module Renderer
6
6
  module Presenters
7
7
  class ContentSwitcher
8
- def initialize(format:, label:, theme_light:, force_type: nil)
8
+ attr_reader :panels
9
+
10
+ def initialize(format:, label: nil, theme_light:, force_type: nil)
9
11
  @format = format
10
12
  @panels = []
11
13
  @label = label
@@ -24,6 +24,10 @@ module Nexmo
24
24
  end
25
25
 
26
26
  def content
27
+ if @content.is_a?(Nexmo::OAS::Renderer::Presenters::ContentSwitcher)
28
+ return @content.render
29
+ end
30
+
27
31
  if @content == :responses
28
32
  Nexmo::OAS::Renderer::ResponseParserDecorator
29
33
  .new(@schema)
@@ -32,17 +32,50 @@ module Nexmo
32
32
  def tab_panels
33
33
  @tab_panels ||= @response.split_schemas(@format).map.with_index do |schema, index|
34
34
  schema = handle_all_of(schema)
35
+ examples = examples_for_schema(schema)
35
36
  ResponseTab::Panel.new(
36
37
  schema: schema,
37
38
  index: index,
38
39
  format: @format,
39
- content: @content,
40
+ content: examples || @content,
40
41
  endpoint: @endpoint,
41
42
  theme_light: @theme_light
42
43
  )
43
44
  end
44
45
  end
45
46
 
47
+ def examples_for_schema(schema)
48
+ # If there are any examples, show them
49
+ examples = @response.raw.dig('content', @format, 'examples')
50
+ return nil unless @content == :responses && @format == 'application/json' && examples
51
+
52
+ example_switcher = Nexmo::OAS::Renderer::Presenters::ContentSwitcher.new(format: format, force_type: 'dropdown', theme_light: @theme_light)
53
+
54
+ has_visible_panel = false
55
+ examples.each_with_index do |v, _k|
56
+ # Only if the example key is listed in x-examples in the schema
57
+ next unless schema['x-examples']&.include?(v[0])
58
+
59
+ response = JSON.neat_generate(v[1], {
60
+ wrap: true,
61
+ after_colon: 1,
62
+ })
63
+
64
+ content = <<~HEREDOC
65
+ <pre class="pre-wrap language-json #{@theme_light ? 'Vlt-prism--dark' : ''} Vlt-prism--copy-disabled"><code>#{response}</code></pre>
66
+ HEREDOC
67
+
68
+ example_switcher.add_content(
69
+ title: v[0].titleize,
70
+ content: content,
71
+ tab_id: v[0],
72
+ active: !has_visible_panel
73
+ )
74
+ has_visible_panel = true
75
+ end
76
+ return example_switcher if example_switcher.panels.size.positive?
77
+ end
78
+
46
79
  def handle_all_of(schema)
47
80
  if schema['allOf']
48
81
  schema['allOf'].each do |p|
@@ -3,7 +3,7 @@
3
3
  module Nexmo
4
4
  module OAS
5
5
  module Renderer
6
- VERSION = '2.4.1'
6
+ VERSION = '2.5.0'
7
7
  end
8
8
  end
9
9
  end
@@ -1,6 +1,6 @@
1
1
  <div class="Vlt-grid">
2
2
  <div class="Vlt-col oas-left-panel header-row" style="padding-top:20px;">
3
- <a href="<%= @theme_link %>" class="Vlt-switch Vlt-switch--secondary" style="float:right;">
3
+ <a href="<%= @theme_link %>" class="Vlt-switch Vlt-switch--secondary" style="float:right;" title="colour theme switcher">
4
4
  <span class="Vlt-switch__slider"></span>
5
5
  </a>
6
6
 
@@ -4,12 +4,12 @@
4
4
  switcher = Nexmo::OAS::Renderer::Presenters::ContentSwitcher.new(label: "Response Example", format: format, force_type: tabs.switcher, theme_light: @theme_light)
5
5
 
6
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
- )
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
13
  end
14
14
  %>
15
15
 
@@ -1,5 +1,7 @@
1
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>
2
+ <div class="Vlt-dropdown__trigger Vlt-dropdown__trigger--btn"><button class="Vlt-btn Vlt-btn--<%= (theme_light ? "secondary" : "tertiary") %>">
3
+ <%= label ? "#{label}: " : ""%><span class="Vlt-dropdown__selection"><%= panels[0]['title'] %></span>
4
+ </button></div>
3
5
  <div class="Vlt-dropdown__panel">
4
6
  <div data-tab-content="<%= switcher.id %>" class="Vlt-dropdown__panel__content">
5
7
  <% panels.each do |panel| %>
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
39
39
  spec.add_runtime_dependency 'nexmo_markdown_renderer', '~> 0.3'
40
40
  spec.add_runtime_dependency 'oas_parser', '~> 0.25.1'
41
41
  spec.add_runtime_dependency 'octicons_helper', '~> 8.2'
42
- spec.add_runtime_dependency 'redcarpet', '3.4.0'
42
+ spec.add_runtime_dependency 'redcarpet', '3.5.1'
43
43
  spec.add_runtime_dependency 'sass', '~> 3.1'
44
44
  spec.add_runtime_dependency 'shotgun', '~> 0.9'
45
45
  spec.add_runtime_dependency 'sinatra', '~> 2.0'
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.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabian Rodriguez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-19 00:00:00.000000000 Z
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 3.4.0
131
+ version: 3.5.1
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 3.4.0
138
+ version: 3.5.1
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: sass
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -234,7 +234,7 @@ dependencies:
234
234
  - - "~>"
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0.86'
237
- description:
237
+ description:
238
238
  email:
239
239
  - fabian.rodriguez@vonage.com
240
240
  executables:
@@ -382,7 +382,7 @@ licenses:
382
382
  metadata:
383
383
  homepage_uri: https://github.com/Nexmo/nexmo-oas-renderer
384
384
  source_code_uri: https://github.com/Nexmo/nexmo-oas-renderer
385
- post_install_message:
385
+ post_install_message:
386
386
  rdoc_options: []
387
387
  require_paths:
388
388
  - lib
@@ -397,8 +397,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
397
397
  - !ruby/object:Gem::Version
398
398
  version: '0'
399
399
  requirements: []
400
- rubygems_version: 3.1.4
401
- signing_key:
400
+ rubyforge_project:
401
+ rubygems_version: 2.7.6.2
402
+ signing_key:
402
403
  specification_version: 4
403
404
  summary: OpenAPI Specification renderer.
404
405
  test_files: []