nexmo-oas-renderer 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +1 -0
- data/.github/workflows/push-docker-publish.yml +19 -0
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/.rubocop.yml +135 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +58 -0
- data/CONTRIBUTING.md +46 -0
- data/Dockerfile +6 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +248 -0
- data/LICENSE.txt +21 -0
- data/README.md +103 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/nexmo-oas-renderer +5 -0
- data/lib/nexmo/oas/engine.rb +11 -0
- data/lib/nexmo/oas/renderer.rb +13 -0
- data/lib/nexmo/oas/renderer/app.rb +201 -0
- data/lib/nexmo/oas/renderer/config.ru +9 -0
- data/lib/nexmo/oas/renderer/config/code_languages.yml +138 -0
- data/lib/nexmo/oas/renderer/config/dynamic_content.yml +1 -0
- data/lib/nexmo/oas/renderer/decorators/response_parser_decorator.rb +55 -0
- data/lib/nexmo/oas/renderer/helpers/navigation.rb +66 -0
- data/lib/nexmo/oas/renderer/helpers/render.rb +25 -0
- data/lib/nexmo/oas/renderer/helpers/summary.rb +33 -0
- data/lib/nexmo/oas/renderer/helpers/url.rb +19 -0
- data/lib/nexmo/oas/renderer/presenters/api_specification.rb +54 -0
- data/lib/nexmo/oas/renderer/presenters/endpoint.rb +21 -0
- data/lib/nexmo/oas/renderer/presenters/groups.rb +39 -0
- data/lib/nexmo/oas/renderer/presenters/navigation.rb +26 -0
- data/lib/nexmo/oas/renderer/presenters/open_api_specification.rb +62 -0
- data/lib/nexmo/oas/renderer/presenters/request_body_raw.rb +141 -0
- data/lib/nexmo/oas/renderer/presenters/response_format.rb +29 -0
- data/lib/nexmo/oas/renderer/presenters/response_tab/link.rb +36 -0
- data/lib/nexmo/oas/renderer/presenters/response_tab/panel.rb +45 -0
- data/lib/nexmo/oas/renderer/presenters/response_tabs.rb +58 -0
- data/lib/nexmo/oas/renderer/presenters/versions.rb +51 -0
- data/lib/nexmo/oas/renderer/public/500.html +66 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/android.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/curl.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/dotnet.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/ios.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/java.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/javascript.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/node.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/php.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/python.svg +11 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/ruby.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/lost.svg +37 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/components/format.js +47 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/nexmo-oas-renderer.js +65 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/popper.min.js +5 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/prism.js +22 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/tooltip.min.js +5 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.accordion.js +307 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.core.js +230 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.modal.js +300 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.tabs.js +143 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.tooltip.js +76 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/nexmo-oas-renderer.css +287 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/nexmo-oas-renderer.css.map +7 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/api.scss +341 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/mediaqueries.scss +48 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/style.scss +6 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/themes/dark.scss +89 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/themes/light.scss +68 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/variables.scss +91 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta-prism.min.css +1 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta.min.css +1 -0
- data/lib/nexmo/oas/renderer/public/assets/symbol/volta-icons.svg +1 -0
- data/lib/nexmo/oas/renderer/public/favicon.ico +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-Regular.eot +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-Regular.ttf +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-Regular.woff +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-Regular.woff2 +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiBold.eot +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiBold.ttf +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiBold.woff +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiBold.woff2 +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiMonoSemiBold.eot +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiMonoSemiBold.ttf +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiMonoSemiBold.woff +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiMonoSemiBold.woff2 +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-WideMedium.eot +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-WideMedium.ttf +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-WideMedium.woff +0 -0
- data/lib/nexmo/oas/renderer/public/fonts/Spezia-WideMedium.woff2 +0 -0
- data/lib/nexmo/oas/renderer/services/oas_parser.rb +23 -0
- data/lib/nexmo/oas/renderer/services/open_api_definition_resolver.rb +35 -0
- data/lib/nexmo/oas/renderer/version.rb +9 -0
- data/lib/nexmo/oas/renderer/views/api/index.erb +19 -0
- data/lib/nexmo/oas/renderer/views/api/show.erb +1 -0
- data/lib/nexmo/oas/renderer/views/concepts/list/plain.html.erb +5 -0
- data/lib/nexmo/oas/renderer/views/layouts/_head.erb +6 -0
- data/lib/nexmo/oas/renderer/views/layouts/_javascripts.erb +14 -0
- data/lib/nexmo/oas/renderer/views/layouts/api.erb +23 -0
- data/lib/nexmo/oas/renderer/views/layouts/open_api.erb +12 -0
- data/lib/nexmo/oas/renderer/views/open_api/_auth.erb +74 -0
- data/lib/nexmo/oas/renderer/views/open_api/_available_endpoints.erb +25 -0
- data/lib/nexmo/oas/renderer/views/open_api/_callback.erb +5 -0
- data/lib/nexmo/oas/renderer/views/open_api/_callback_endpoint.erb +38 -0
- data/lib/nexmo/oas/renderer/views/open_api/_callbacks.erb +5 -0
- data/lib/nexmo/oas/renderer/views/open_api/_code_examples.erb +16 -0
- data/lib/nexmo/oas/renderer/views/open_api/_endpoint.erb +54 -0
- data/lib/nexmo/oas/renderer/views/open_api/_header.erb +71 -0
- data/lib/nexmo/oas/renderer/views/open_api/_model.erb +43 -0
- data/lib/nexmo/oas/renderer/views/open_api/_navigation.erb +68 -0
- data/lib/nexmo/oas/renderer/views/open_api/_parameter_groups.erb +56 -0
- data/lib/nexmo/oas/renderer/views/open_api/_parameters.erb +115 -0
- data/lib/nexmo/oas/renderer/views/open_api/_request_json.erb +4 -0
- data/lib/nexmo/oas/renderer/views/open_api/_request_one_of.erb +70 -0
- data/lib/nexmo/oas/renderer/views/open_api/_request_single.erb +53 -0
- data/lib/nexmo/oas/renderer/views/open_api/_requests.erb +22 -0
- data/lib/nexmo/oas/renderer/views/open_api/_response_description_parameters.erb +130 -0
- data/lib/nexmo/oas/renderer/views/open_api/_response_descriptions.erb +45 -0
- data/lib/nexmo/oas/renderer/views/open_api/_response_fields.erb +3 -0
- data/lib/nexmo/oas/renderer/views/open_api/_response_tabs.erb +18 -0
- data/lib/nexmo/oas/renderer/views/open_api/_responses.erb +51 -0
- data/lib/nexmo/oas/renderer/views/open_api/_tabbed_parameters.erb +64 -0
- data/lib/nexmo/oas/renderer/views/open_api/_tabbed_single_parameter.erb +56 -0
- data/lib/nexmo/oas/renderer/views/open_api/_webhooks.erb +30 -0
- data/lib/nexmo/oas/renderer/views/open_api/show.erb +26 -0
- data/lib/nexmo/oas/renderer/views/static/404.erb +6 -0
- data/nexmo-oas-renderer.gemspec +51 -0
- metadata +397 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Nexmo Inc
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# Nexmo OAS Renderer
|
2
|
+
Sinatra application that provides a preview of how the OAS documents will be rendered within [Nexmo Developer](https://developer.nexmo.com/).
|
3
|
+
|
4
|
+
* [Dependencies](#requirements)
|
5
|
+
* [Installation and Usage](#installation-and-usage)
|
6
|
+
* [Using Docker](#using-docker)
|
7
|
+
* [As a standalone application](#as-a-standalone-application)
|
8
|
+
* [Mounted into a Rails application](#mounted-into-a-rails-application)
|
9
|
+
* [Specifying the path to the documents](#specifying-the-path-to-the-documents)
|
10
|
+
* [Contributing](#contributing)
|
11
|
+
* [License](#license)
|
12
|
+
|
13
|
+
## Dependencies
|
14
|
+
|
15
|
+
|
16
|
+
## Installation and Usage
|
17
|
+
|
18
|
+
### Using Docker
|
19
|
+
|
20
|
+
You can run using Docker and it will serve the current directory (this will usually be the api-specification repo):
|
21
|
+
|
22
|
+
#### Mac/Linux
|
23
|
+
|
24
|
+
```bash
|
25
|
+
docker run --rm -p 4567:4567 -v `pwd`:/definitions -e 'OAS_PATH=/definitions' nexmodev/nexmo-oas-renderer:latest
|
26
|
+
```
|
27
|
+
|
28
|
+
Alternatively, add the following to your `~/.bashrc` file and you'll be able to run `nexmo-oas-renderer`
|
29
|
+
|
30
|
+
```
|
31
|
+
function nexmo-oas-renderer() {
|
32
|
+
docker run --rm -p 4567:4567 -v `pwd`:/definitions -e 'OAS_PATH=/definitions' nexmodev/nexmo-oas-renderer:latest
|
33
|
+
}
|
34
|
+
```
|
35
|
+
|
36
|
+
#### Windows
|
37
|
+
|
38
|
+
```ps
|
39
|
+
docker run --rm -p 4567:4567 -v %CD%:/definitions -e 'OAS_PATH=/definitions' nexmodev/nexmo-oas-renderer:latest
|
40
|
+
```
|
41
|
+
|
42
|
+
### As a standalone application
|
43
|
+
|
44
|
+
Install the gem:
|
45
|
+
|
46
|
+
``` shell
|
47
|
+
$ gem install nexmo-oas-renderer
|
48
|
+
```
|
49
|
+
|
50
|
+
And simply run the executable with the corresponding env variables set (see [Note](#note)):
|
51
|
+
``` shell
|
52
|
+
$ nexmo-oas-renderer
|
53
|
+
```
|
54
|
+
|
55
|
+
Or, if you want to make code changes, just run the following command which will start the web server on http://localhost:9393:
|
56
|
+
``` shell
|
57
|
+
OAS_PATH=... bundle exec shotgun lib/nexmo/oas/renderer/config.ru
|
58
|
+
```
|
59
|
+
|
60
|
+
### Mounted into a Rails Application
|
61
|
+
|
62
|
+
Add this to your application's `Gemfile`:
|
63
|
+
|
64
|
+
```
|
65
|
+
gem 'nexmo-oas-renderer', require: false
|
66
|
+
```
|
67
|
+
|
68
|
+
And then run `bundle install`.
|
69
|
+
|
70
|
+
Require the gem in `config/environment.rb` as follows:
|
71
|
+
|
72
|
+
``` ruby
|
73
|
+
# Load the Rails application.
|
74
|
+
require_relative 'application'
|
75
|
+
|
76
|
+
require 'nexmo/oas/renderer'
|
77
|
+
|
78
|
+
# Initialize the Rails application.
|
79
|
+
Rails.application.initialize!
|
80
|
+
```
|
81
|
+
|
82
|
+
And finally mount the Sinatra app into your Rails application by adding the following line to `config/routes.rb`:
|
83
|
+
|
84
|
+
``` ruby
|
85
|
+
mount Nexmo::OAS::Renderer::API, at: '/api'
|
86
|
+
```
|
87
|
+
|
88
|
+
### Specifying the path to the documents
|
89
|
+
|
90
|
+
This gem uses [dotenv](https://github.com/bkeepers/dotenv) to handle environment variables, so you should copy the `.env.example` provided by running:
|
91
|
+
``` shell
|
92
|
+
$ cp .env.example .env
|
93
|
+
```
|
94
|
+
and assign values to the corresponding variables.
|
95
|
+
|
96
|
+
#### Note
|
97
|
+
The env variable `OAS_PATH` indicates the path to the documents that will be rendered.
|
98
|
+
|
99
|
+
## Contributing
|
100
|
+
We ❤️ contributions from everyone! [Bug reports](https://github.com/Nexmo/nexmo-oas-renderer/issues), [bug fixes](https://github.com/Nexmo/nexmo-oas-renderer/pulls) and feedback on the library is always appreciated. Look at the [Contributor Guidelines](https://github.com/Nexmo/nexmo-oas-renderer/blob/master/CONTRIBUTING.md) for more information and please follow the [GitHub Flow](https://guides.github.com/introduction/flow/index.html).
|
101
|
+
|
102
|
+
## License
|
103
|
+
This project is under the [MIT LICENSE](https://github.com/Nexmo/nexmo-oas-renderer/blob/master/LICENSE).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'nexmo/oas/renderer'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/core_ext/array/conversions'
|
6
|
+
require 'active_support/core_ext/string/output_safety'
|
7
|
+
require 'active_model'
|
8
|
+
require 'nexmo_markdown_renderer'
|
9
|
+
|
10
|
+
require_relative './decorators/response_parser_decorator'
|
11
|
+
require_relative './presenters/api_specification'
|
12
|
+
require_relative './presenters/open_api_specification'
|
13
|
+
require_relative './presenters/navigation'
|
14
|
+
require_relative './presenters/request_body_raw'
|
15
|
+
require_relative './presenters/response_tabs'
|
16
|
+
require_relative './helpers/render'
|
17
|
+
require_relative './helpers/navigation'
|
18
|
+
require_relative './helpers/summary'
|
19
|
+
require_relative './helpers/url'
|
20
|
+
|
21
|
+
require 'dotenv/load'
|
22
|
+
|
23
|
+
module Nexmo
|
24
|
+
module OAS
|
25
|
+
module Renderer
|
26
|
+
class API < Sinatra::Base
|
27
|
+
Tilt.register Tilt::ERBTemplate, 'html.erb'
|
28
|
+
|
29
|
+
if defined?(NexmoDeveloper::Application)
|
30
|
+
view_paths = [views, NexmoDeveloper::Application.root.join('app', 'views')]
|
31
|
+
set :views, view_paths
|
32
|
+
end
|
33
|
+
|
34
|
+
set :mustermann_opts, { type: :rails }
|
35
|
+
set :oas_path, (ENV['OAS_PATH'] || './')
|
36
|
+
set :bind, '0.0.0.0'
|
37
|
+
set :github_path, (proc { load_business_yaml })
|
38
|
+
|
39
|
+
helpers do
|
40
|
+
include Helpers::Render
|
41
|
+
include Helpers::Navigation
|
42
|
+
include Helpers::Summary
|
43
|
+
include Helpers::URL
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_params(extension)
|
47
|
+
extensions = extension.split('.')
|
48
|
+
case extensions.size
|
49
|
+
when 1
|
50
|
+
{ definition: extensions.first }
|
51
|
+
when 2
|
52
|
+
if extensions.second.match?(/v\d+/)
|
53
|
+
{ definition: extensions.first, version: extensions.second }
|
54
|
+
else
|
55
|
+
{ definition: extensions.first, format: extensions.second }
|
56
|
+
end
|
57
|
+
when 3
|
58
|
+
{ definition: extensions.first, version: extensions.second, format: extensions.last }
|
59
|
+
else
|
60
|
+
{}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.load_business_yaml
|
65
|
+
raise "Application requires a 'config/business_info.yml' file to be defined inside the documentation path." if defined?(NexmoDeveloper::Application) && !File.exist?("#{Rails.configuration.docs_base_path}/config/business_info.yml")
|
66
|
+
|
67
|
+
if defined?(NexmoDeveloper::Application) && File.exist?("#{Rails.configuration.docs_base_path}/config/business_info.yml")
|
68
|
+
@url ||= begin
|
69
|
+
config = YAML.load_file("#{Rails.configuration.docs_base_path}/config/business_info.yml")
|
70
|
+
config['oas_url']
|
71
|
+
end
|
72
|
+
else
|
73
|
+
'https://www.github.com/nexmo/api-specification/blob/master/definitions'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def check_redirect!
|
78
|
+
return unless defined?(NexmoDeveloper::Application)
|
79
|
+
|
80
|
+
redirect_path = Redirector.find(request)
|
81
|
+
redirect(redirect_path) if redirect_path
|
82
|
+
end
|
83
|
+
|
84
|
+
def check_oas_constraints!(definition)
|
85
|
+
return unless defined?(NexmoDeveloper::Application)
|
86
|
+
|
87
|
+
pass unless OpenApiConstraint.match?(definition)
|
88
|
+
end
|
89
|
+
|
90
|
+
error Errno::ENOENT do
|
91
|
+
layout = defined?(NexmoDeveloper::Application) ? :'layouts/api.html' : false
|
92
|
+
not_found erb :'static/404', layout: layout
|
93
|
+
end
|
94
|
+
|
95
|
+
error Exception do
|
96
|
+
File.read("#{API.root}/public/500.html")
|
97
|
+
end
|
98
|
+
|
99
|
+
unless defined?(NexmoDeveloper::Application)
|
100
|
+
get '/' do
|
101
|
+
prefix = API.oas_path.to_s
|
102
|
+
@definitions = Dir.glob("#{prefix}/**/*.yml").map do |d|
|
103
|
+
d.gsub("#{prefix}/", '').gsub('.yml', '')
|
104
|
+
end
|
105
|
+
|
106
|
+
@definitions = @definitions.sort.reject { |d| d.include? 'common/' }
|
107
|
+
erb :'api/index', layout: false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def set_code_language
|
112
|
+
return if params[:code_language] == 'templates'
|
113
|
+
|
114
|
+
@code_language = params[:code_language]
|
115
|
+
end
|
116
|
+
|
117
|
+
def set_theme
|
118
|
+
persisted_theme = nil
|
119
|
+
|
120
|
+
if defined?(NexmoDeveloper::Application)
|
121
|
+
session[:persisted_theme] = params[:theme] if params[:theme]
|
122
|
+
persisted_theme = session[:persisted_theme]
|
123
|
+
end
|
124
|
+
|
125
|
+
@theme = params[:theme] || persisted_theme
|
126
|
+
|
127
|
+
@theme = 'light' unless %w[light dark].include?(@theme)
|
128
|
+
|
129
|
+
@theme_light = @theme == 'light'
|
130
|
+
|
131
|
+
alternate_theme = @theme == 'light' ? 'dark' : 'light'
|
132
|
+
@theme_link = "#{request.path_info}?theme=#{alternate_theme}"
|
133
|
+
@theme_link = "/api#{@theme_link}" if defined?(NexmoDeveloper::Application)
|
134
|
+
end
|
135
|
+
|
136
|
+
before do
|
137
|
+
set_code_language
|
138
|
+
set_theme
|
139
|
+
end
|
140
|
+
|
141
|
+
get '(/api)/*definition' do
|
142
|
+
check_redirect!
|
143
|
+
|
144
|
+
parameters = parse_params(params[:definition])
|
145
|
+
definition = [parameters[:definition], parameters[:version]].compact.join('.')
|
146
|
+
check_oas_constraints!(definition)
|
147
|
+
|
148
|
+
@specification = Presenters::OpenApiSpecification.new(
|
149
|
+
definition_name: definition,
|
150
|
+
expand_responses: params.fetch(:expandResponses, nil)
|
151
|
+
)
|
152
|
+
|
153
|
+
if %w[yml json].include?(parameters[:format])
|
154
|
+
next send_file @specification.definition.path, disposition: :attachment
|
155
|
+
end
|
156
|
+
|
157
|
+
if defined?(NexmoDeveloper::Application)
|
158
|
+
erb :'open_api/show', layout: :'layouts/open-api.html'
|
159
|
+
else
|
160
|
+
erb :'open_api/show', layout: :'layouts/open_api'
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def set_document
|
165
|
+
@document = if params[:code_language] == 'templates'
|
166
|
+
'verify/templates'
|
167
|
+
elsif params[:code_language] == 'ncco'
|
168
|
+
'voice/ncco'
|
169
|
+
elsif ::Nexmo::Markdown::CodeLanguage.exists?(params[:code_language])
|
170
|
+
params[:document]
|
171
|
+
else
|
172
|
+
"#{params[:document]}/#{params[:code_language]}"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
get '(/api)/*document(/:code_language)' do
|
177
|
+
set_document
|
178
|
+
|
179
|
+
@specification = Presenters::ApiSpecification.new(
|
180
|
+
document_name: @document,
|
181
|
+
code_language: @code_language
|
182
|
+
)
|
183
|
+
|
184
|
+
@navigation = Presenters::Navigation.new(
|
185
|
+
content: @specification.content,
|
186
|
+
title: @specification.side_navigation_title
|
187
|
+
)
|
188
|
+
|
189
|
+
if defined?(NexmoDeveloper::Application)
|
190
|
+
@content = @navigation.content
|
191
|
+
@side_navigation_title = @navigation.title
|
192
|
+
|
193
|
+
erb :'api/show', layout: :'layouts/api.html'
|
194
|
+
else
|
195
|
+
erb :'api/show', layout: :'layouts/api'
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
terminal_programs:
|
2
|
+
curl:
|
3
|
+
weight: 1
|
4
|
+
label: cURL
|
5
|
+
lexer: sh
|
6
|
+
icon: curl
|
7
|
+
run_command: 'sh {filename}'
|
8
|
+
cli:
|
9
|
+
label: CLI
|
10
|
+
lexer: sh
|
11
|
+
linkable: false
|
12
|
+
|
13
|
+
languages:
|
14
|
+
javascript:
|
15
|
+
weight: 2
|
16
|
+
label: JavaScript
|
17
|
+
lexer: javascript
|
18
|
+
icon: javascript
|
19
|
+
dependencies:
|
20
|
+
- 'nexmo'
|
21
|
+
|
22
|
+
node:
|
23
|
+
weight: 2
|
24
|
+
label: Node.js
|
25
|
+
lexer: javascript
|
26
|
+
icon: node
|
27
|
+
dependencies:
|
28
|
+
- 'nexmo'
|
29
|
+
run_command: 'node {filename}'
|
30
|
+
|
31
|
+
java:
|
32
|
+
weight: 3
|
33
|
+
label: Java
|
34
|
+
lexer: java
|
35
|
+
unindent: true
|
36
|
+
icon: java
|
37
|
+
dependencies:
|
38
|
+
- 'com.nexmo:client:@latest'
|
39
|
+
|
40
|
+
dotnet:
|
41
|
+
weight: 4
|
42
|
+
label: .NET
|
43
|
+
lexer: c#
|
44
|
+
unindent: true
|
45
|
+
icon: dotnet
|
46
|
+
dependencies:
|
47
|
+
- 'Nexmo.Csharp.Client'
|
48
|
+
csharp:
|
49
|
+
weight: 4
|
50
|
+
label: .NET
|
51
|
+
lexer: c#
|
52
|
+
unindent: true
|
53
|
+
icon: dotnet
|
54
|
+
dependencies:
|
55
|
+
- 'Nexmo.Csharp.Client'
|
56
|
+
|
57
|
+
php:
|
58
|
+
weight: 5
|
59
|
+
label: PHP
|
60
|
+
lexer: php
|
61
|
+
icon: php
|
62
|
+
dependencies:
|
63
|
+
- 'nexmo/client'
|
64
|
+
run_command: 'php {filename}'
|
65
|
+
|
66
|
+
python:
|
67
|
+
weight: 6
|
68
|
+
label: Python
|
69
|
+
lexer: python
|
70
|
+
icon: python
|
71
|
+
dependencies:
|
72
|
+
- 'nexmo'
|
73
|
+
run_command: 'python {filename}'
|
74
|
+
|
75
|
+
ruby:
|
76
|
+
weight: 7
|
77
|
+
label: Ruby
|
78
|
+
lexer: ruby
|
79
|
+
icon: ruby
|
80
|
+
dependencies:
|
81
|
+
- 'nexmo'
|
82
|
+
run_command: 'ruby {filename}'
|
83
|
+
|
84
|
+
kotlin:
|
85
|
+
weight: 8
|
86
|
+
label: Kotlin
|
87
|
+
lexer: java
|
88
|
+
icon: android
|
89
|
+
dependencies: []
|
90
|
+
|
91
|
+
android:
|
92
|
+
weight: 9
|
93
|
+
label: Java
|
94
|
+
lexer: java
|
95
|
+
icon: android
|
96
|
+
dependencies: []
|
97
|
+
|
98
|
+
swift:
|
99
|
+
weight: 10
|
100
|
+
label: Swift
|
101
|
+
lexer: swift
|
102
|
+
icon: ios
|
103
|
+
dependencies: []
|
104
|
+
|
105
|
+
objective_c:
|
106
|
+
weight: 11
|
107
|
+
label: Objective-C
|
108
|
+
lexer: objective_c
|
109
|
+
icon: ios
|
110
|
+
dependencies: []
|
111
|
+
|
112
|
+
platforms:
|
113
|
+
ios:
|
114
|
+
languages:
|
115
|
+
- swift
|
116
|
+
- objective_c
|
117
|
+
android:
|
118
|
+
languages:
|
119
|
+
- java
|
120
|
+
web:
|
121
|
+
languages:
|
122
|
+
- javascript
|
123
|
+
|
124
|
+
data:
|
125
|
+
ncco:
|
126
|
+
label: NCCO
|
127
|
+
lexer: json
|
128
|
+
linkable: false
|
129
|
+
json:
|
130
|
+
weight: 1
|
131
|
+
label: JSON
|
132
|
+
lexer: json
|
133
|
+
linkable: false
|
134
|
+
xml:
|
135
|
+
weight: 2
|
136
|
+
label: XML
|
137
|
+
lexer: xml
|
138
|
+
linkable: false
|