scalar_ruby 1.0.0 → 2.0.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.
- checksums.yaml +4 -4
- data/README.md +113 -16
- data/lib/generators/scalar/install/USAGE +11 -0
- data/lib/generators/scalar/install/install_generator.rb +37 -0
- data/lib/generators/scalar/install/templates/initializer.rb +23 -0
- data/lib/scalar/config.rb +15 -12
- data/lib/scalar/template.erb +8 -6
- data/lib/scalar/version.rb +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a21547938d1fb384cf1a97984c15eb33dd883d0f4c0e4e4a2bea9482d37215ce
|
|
4
|
+
data.tar.gz: df9316873f075b3a1b5e3e46734ac2a90d0febaa29a86d02ecdcd7b6c9231e6c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d5b51185f6c4677087b0dc9529db5d0fa476354b2862cca2be6b2560b592d6ee696eaf6e65c2202e0d27c5e337ff7de3c224fc1bd2d5e10ecb118dc7a37f23a1
|
|
7
|
+
data.tar.gz: bc7f9f3c0acd9e159c97bf58770ed627f75847dc655941fc1e164c420a9b306a923313ef704ee82a34e1031230ca6775c608959e0a977eaa3f87c119e5ef47ac
|
data/README.md
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
[](https://badge.fury.io/rb/scalar_ruby)
|
|
2
|
+
[](https://github.com/dmytroshevchuk/scalar_ruby/actions/workflows/check.yml)
|
|
3
|
+
|
|
1
4
|
# Scalar API Reference for Ruby
|
|
2
5
|
|
|
3
6
|
This gem simplifies the integration of [Scalar](https://scalar.com), a modern open-source developer experience platform for your APIs into Ruby applications.
|
|
4
7
|
|
|
8
|
+
## Requirements
|
|
9
|
+
|
|
10
|
+
This gem is tested and supported on the Ruby 2.7, 3.0, 3.1, 3.2, 3.3, and 3.4. Other Ruby versions might work but are not officially supported.
|
|
11
|
+
|
|
5
12
|
## Installation
|
|
6
13
|
|
|
7
14
|
Add the gem to your application's Gemfile by executing in the terminal:
|
|
@@ -27,35 +34,43 @@ end
|
|
|
27
34
|
|
|
28
35
|
Restart the Rails server, and hit `localhost:3000/docs`. You'll see the default view of the Scalar API reference. It uses the `@scalar/galaxy` OpenAPI reference so that you will have something to play with immediately.
|
|
29
36
|
|
|
30
|
-
Then, if you want to use your OpenAPI specification, you need to re-configure
|
|
37
|
+
Then, if you want to use your OpenAPI specification, you need to re-configure Scalar.
|
|
31
38
|
|
|
32
|
-
First, create an initializer, say `config/initializers/scalar.rb`. Then, set the desired specification
|
|
39
|
+
First, create an initializer, say `config/initializers/scalar.rb`. Then, set the desired specification URL via the `config.configuration` setting using the `Scalar.setup` method:
|
|
33
40
|
|
|
34
41
|
```ruby
|
|
35
42
|
# config/initializers/scalar.rb
|
|
36
43
|
|
|
37
44
|
Scalar.setup do |config|
|
|
38
|
-
config.
|
|
45
|
+
config.configuration = { url: 'https://example.com/openapi.json' }
|
|
39
46
|
end
|
|
40
47
|
```
|
|
41
48
|
|
|
42
|
-
|
|
49
|
+
Or embed the file content directly:
|
|
43
50
|
|
|
44
51
|
```ruby
|
|
45
52
|
# config/initializers/scalar.rb
|
|
46
53
|
|
|
47
54
|
Scalar.setup do |config|
|
|
48
|
-
config.
|
|
55
|
+
config.configuration = { content: File.read(Rails.root.join('docs/openapi.yml')) }
|
|
49
56
|
end
|
|
50
57
|
```
|
|
51
58
|
|
|
52
59
|
And that's it! More detailed information on other configuration options is in the section below.
|
|
53
60
|
|
|
61
|
+
## Integrations
|
|
62
|
+
|
|
63
|
+
You can use the built-in generator to set up the gem in [Ruby on Rails](https://rubyonrails.org) by running:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
bin/rails generate scalar:install
|
|
67
|
+
```
|
|
68
|
+
|
|
54
69
|
## Configuration
|
|
55
70
|
|
|
56
71
|
Once mounted to your application, the library requires no further configuration. You can immediately start playing with the provided API reference example.
|
|
57
72
|
|
|
58
|
-
Having default configurations set may be an excellent way to validate whether
|
|
73
|
+
Having default configurations set may be an excellent way to validate whether Scalar fits your project. However, most users would love to utilize their specifications and adjust settings.
|
|
59
74
|
|
|
60
75
|
The default configuration can be changed using the `Scalar.setup` method in `config/initializers/scalar.rb`.
|
|
61
76
|
|
|
@@ -63,18 +78,97 @@ The default configuration can be changed using the `Scalar.setup` method in `con
|
|
|
63
78
|
# config/initializers/scalar.rb
|
|
64
79
|
|
|
65
80
|
Scalar.setup do |config|
|
|
66
|
-
|
|
81
|
+
config.page_title = 'My awesome API!'
|
|
82
|
+
end
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Use the `config.configuration` setting to pass your API specification and customize Scalar's appearance. The value is a hash passed directly to the Scalar JavaScript library and supports all of Scalar's native configuration options.
|
|
86
|
+
|
|
87
|
+
Pass a URL to your specification:
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
# config/initializers/scalar.rb
|
|
91
|
+
|
|
92
|
+
Scalar.setup do |config|
|
|
93
|
+
config.configuration = { url: 'https://example.com/openapi.json' }
|
|
94
|
+
end
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Or embed the file content:
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
# config/initializers/scalar.rb
|
|
101
|
+
|
|
102
|
+
Scalar.setup do |config|
|
|
103
|
+
config.configuration = { content: File.read(Rails.root.join('docs/openapi.yml')) }
|
|
104
|
+
end
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
You can also set `config.configuration` to `:demo`, and the `@scalar/galaxy` spec will be used. It may come in handy if you want to try out the library.
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
# config/initializers/scalar.rb
|
|
111
|
+
|
|
112
|
+
Scalar.setup do |config|
|
|
113
|
+
config.configuration = :demo
|
|
114
|
+
end
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Multiple API Documents
|
|
118
|
+
|
|
119
|
+
To display multiple OpenAPI documents, use the `sources` array. The first entry is shown by default; add `default: true` to any source to override that.
|
|
120
|
+
|
|
121
|
+
```ruby
|
|
122
|
+
# config/initializers/scalar.rb
|
|
123
|
+
|
|
124
|
+
Scalar.setup do |config|
|
|
125
|
+
config.configuration = {
|
|
126
|
+
sources: [
|
|
127
|
+
{ title: 'Public API', url: '/openapi/public.json' },
|
|
128
|
+
{ title: 'Internal API', url: '/openapi/internal.json', default: true },
|
|
129
|
+
{ title: 'Legacy API', content: File.read(Rails.root.join('docs/legacy.yml')) }
|
|
130
|
+
]
|
|
131
|
+
}
|
|
67
132
|
end
|
|
68
133
|
```
|
|
69
134
|
|
|
70
|
-
|
|
135
|
+
You can also apply distinct settings per document by passing an array of configuration objects instead of a single hash:
|
|
136
|
+
|
|
137
|
+
```ruby
|
|
138
|
+
# config/initializers/scalar.rb
|
|
139
|
+
|
|
140
|
+
Scalar.setup do |config|
|
|
141
|
+
config.configuration = [
|
|
142
|
+
{
|
|
143
|
+
title: 'Public API',
|
|
144
|
+
url: '/openapi/public.json',
|
|
145
|
+
theme: 'purple'
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
title: 'Internal API',
|
|
149
|
+
url: '/openapi/internal.json',
|
|
150
|
+
theme: 'bluePlanet',
|
|
151
|
+
default: true
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
end
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Each source accepts:
|
|
158
|
+
|
|
159
|
+
- `url` — absolute or relative URL to the OpenAPI document
|
|
160
|
+
- `content` — inline JSON or YAML string
|
|
161
|
+
- `title` — display name shown in the UI (auto-generated if omitted)
|
|
162
|
+
- `slug` — URL identifier (auto-generated from title if omitted)
|
|
163
|
+
- `default` — set to `true` to make this the initially displayed document
|
|
164
|
+
|
|
165
|
+
Below, you'll find a complete list of configuration settings:
|
|
71
166
|
|
|
72
|
-
Parameter
|
|
73
|
-
|
|
74
|
-
`config.page_title`
|
|
75
|
-
`config.library_url`
|
|
76
|
-
`config.
|
|
77
|
-
`config.specification` | Allows users to pass their OpenAPI specification to Scalar. It can be a URL to specification or a string object in JSON or YAML format. | https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml
|
|
167
|
+
Parameter | Description | Default
|
|
168
|
+
------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------
|
|
169
|
+
`config.page_title` | Defines the page title displayed in the browser tab. | API Reference
|
|
170
|
+
`config.library_url` | Allows setting a specific version of Scalar. By default, it uses the latest version, so users get the latest updates and bug fixes. | https://cdn.jsdelivr.net/npm/@scalar/api-reference
|
|
171
|
+
`config.configuration` | A hash passed directly to the Scalar JavaScript library. Accepts all [Scalar configuration options](https://github.com/scalar/scalar/blob/main/documentation/configuration.md) (e.g. `url`, `content`, `sources`, `theme`). Set to `:demo` to use the `@scalar/galaxy` demo spec. | `{}`
|
|
78
172
|
|
|
79
173
|
Example of setting configuration options:
|
|
80
174
|
|
|
@@ -82,7 +176,10 @@ Example of setting configuration options:
|
|
|
82
176
|
# config/initializers/scalar.rb
|
|
83
177
|
|
|
84
178
|
Scalar.setup do |config|
|
|
85
|
-
|
|
179
|
+
config.configuration = {
|
|
180
|
+
theme: 'purple',
|
|
181
|
+
url: 'https://example.com/openapi.json'
|
|
182
|
+
}
|
|
86
183
|
end
|
|
87
184
|
```
|
|
88
185
|
|
|
@@ -102,4 +199,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
102
199
|
|
|
103
200
|
## Code of Conduct
|
|
104
201
|
|
|
105
|
-
Everyone interacting in the Scalar::Ruby project
|
|
202
|
+
Everyone interacting in the Scalar::Ruby project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/dmytroshevchuk/scalar_ruby/blob/master/CODE_OF_CONDUCT.md).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Scalar
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
|
7
|
+
|
|
8
|
+
desc 'Installs Scalar into a Rails app'
|
|
9
|
+
|
|
10
|
+
def introduction
|
|
11
|
+
say <<~INTRODUCTION
|
|
12
|
+
|
|
13
|
+
👋 Let's install Scalar into your Rails app!
|
|
14
|
+
|
|
15
|
+
INTRODUCTION
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def update_routes
|
|
19
|
+
insert_into_file Rails.root.join('config/routes.rb'), after: 'Rails.application.routes.draw do' do
|
|
20
|
+
"\n mount Scalar::UI, at: \"/docs\""
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create_initializer
|
|
25
|
+
template 'initializer.rb', 'config/initializers/scalar.rb'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def farewell
|
|
29
|
+
say <<~FAREWELL
|
|
30
|
+
|
|
31
|
+
We're done! Your can run "/docs" to observe a scalar API platform
|
|
32
|
+
|
|
33
|
+
FAREWELL
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Scalar.setup do |config|
|
|
4
|
+
# Specify the version of the Scalar. By default, it uses the latest one
|
|
5
|
+
#
|
|
6
|
+
# config.library_url = "https://cdn.jsdelivr.net/npm/@scalar/api-reference"
|
|
7
|
+
|
|
8
|
+
# Add custom page title displayed in the browser tab
|
|
9
|
+
#
|
|
10
|
+
# config.page_title = "API Reference"
|
|
11
|
+
|
|
12
|
+
# Set Scalar configuration (e.g. theme, single/multiple specifications or,
|
|
13
|
+
# document sources, etc.)
|
|
14
|
+
#
|
|
15
|
+
# config.scalar_configuration = {
|
|
16
|
+
# theme: "purple",
|
|
17
|
+
# url: '...'
|
|
18
|
+
# }
|
|
19
|
+
#
|
|
20
|
+
# To enable demo mode, uncomment the configuration below
|
|
21
|
+
#
|
|
22
|
+
# config.configuration = :demo
|
|
23
|
+
end
|
data/lib/scalar/config.rb
CHANGED
|
@@ -9,27 +9,30 @@ module Scalar
|
|
|
9
9
|
|
|
10
10
|
DEFAULT_LIBRARY_URL = 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
|
|
11
11
|
DEFAULT_PAGE_TITLE = 'API Reference'
|
|
12
|
-
|
|
13
|
-
DEFAULT_SPECIFICATION = 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml'
|
|
12
|
+
DEFAULT_CONFIGURATION = {}.freeze
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
DEMO_CONFIGURATION = {
|
|
15
|
+
url: 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml'
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
attr_accessor :configuration,
|
|
19
|
+
:library_url,
|
|
20
|
+
:page_title
|
|
19
21
|
|
|
20
22
|
def initialize
|
|
21
|
-
set_defaults
|
|
23
|
+
set_defaults
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
def
|
|
25
|
-
JSON.dump(
|
|
26
|
+
def configuration_to_json
|
|
27
|
+
return JSON.dump(DEMO_CONFIGURATION) if configuration == :demo
|
|
28
|
+
|
|
29
|
+
JSON.dump(configuration)
|
|
26
30
|
end
|
|
27
31
|
|
|
28
|
-
def set_defaults
|
|
32
|
+
def set_defaults
|
|
29
33
|
@library_url = DEFAULT_LIBRARY_URL
|
|
30
34
|
@page_title = DEFAULT_PAGE_TITLE
|
|
31
|
-
@
|
|
32
|
-
@specification = DEFAULT_SPECIFICATION
|
|
35
|
+
@configuration = DEFAULT_CONFIGURATION
|
|
33
36
|
end
|
|
34
37
|
end
|
|
35
38
|
end
|
data/lib/scalar/template.erb
CHANGED
|
@@ -8,13 +8,15 @@
|
|
|
8
8
|
</head>
|
|
9
9
|
|
|
10
10
|
<body>
|
|
11
|
-
<
|
|
12
|
-
id="api-reference"
|
|
13
|
-
data-configuration=<%= config.scalar_configuration_to_json %>
|
|
14
|
-
>
|
|
15
|
-
<%= config.specification %>
|
|
16
|
-
</script>
|
|
11
|
+
<div id="app"></div>
|
|
17
12
|
|
|
18
13
|
<script src="<%= config.library_url %>"></script>
|
|
14
|
+
|
|
15
|
+
<script>
|
|
16
|
+
Scalar.createApiReference(
|
|
17
|
+
'#app',
|
|
18
|
+
<%= config.configuration_to_json %>
|
|
19
|
+
)
|
|
20
|
+
</script>
|
|
19
21
|
</body>
|
|
20
22
|
</html>
|
data/lib/scalar/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: scalar_ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmytro Shevchuk
|
|
8
8
|
- Serhii Ponomarov
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies: []
|
|
14
|
-
description:
|
|
15
13
|
email:
|
|
16
14
|
- dmytro@hey.com
|
|
17
15
|
- sergii.ponomarov@gmail.com
|
|
@@ -21,6 +19,9 @@ extra_rdoc_files: []
|
|
|
21
19
|
files:
|
|
22
20
|
- README.md
|
|
23
21
|
- Rakefile
|
|
22
|
+
- lib/generators/scalar/install/USAGE
|
|
23
|
+
- lib/generators/scalar/install/install_generator.rb
|
|
24
|
+
- lib/generators/scalar/install/templates/initializer.rb
|
|
24
25
|
- lib/scalar/config.rb
|
|
25
26
|
- lib/scalar/template.erb
|
|
26
27
|
- lib/scalar/ui.rb
|
|
@@ -33,7 +34,6 @@ metadata:
|
|
|
33
34
|
homepage_uri: https://github.com/dmytroshevchuk/scalar_ruby
|
|
34
35
|
rubygems_mfa_required: 'true'
|
|
35
36
|
source_code_uri: https://github.com/dmytroshevchuk/scalar_ruby
|
|
36
|
-
post_install_message:
|
|
37
37
|
rdoc_options: []
|
|
38
38
|
require_paths:
|
|
39
39
|
- lib
|
|
@@ -41,15 +41,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
41
41
|
requirements:
|
|
42
42
|
- - ">="
|
|
43
43
|
- !ruby/object:Gem::Version
|
|
44
|
-
version: 2.
|
|
44
|
+
version: '2.7'
|
|
45
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements:
|
|
47
47
|
- - ">="
|
|
48
48
|
- !ruby/object:Gem::Version
|
|
49
49
|
version: '0'
|
|
50
50
|
requirements: []
|
|
51
|
-
rubygems_version: 3.
|
|
52
|
-
signing_key:
|
|
51
|
+
rubygems_version: 3.6.9
|
|
53
52
|
specification_version: 4
|
|
54
53
|
summary: A gem to automate using Scalar with Ruby apps
|
|
55
54
|
test_files: []
|