scalar_ruby 1.1.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 +101 -23
- data/lib/generators/scalar/install/templates/initializer.rb +9 -7
- data/lib/scalar/config.rb +15 -12
- data/lib/scalar/template.erb +8 -6
- data/lib/scalar/version.rb +1 -1
- metadata +4 -4
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
|
@@ -7,11 +7,7 @@ This gem simplifies the integration of [Scalar](https://scalar.com), a modern op
|
|
|
7
7
|
|
|
8
8
|
## Requirements
|
|
9
9
|
|
|
10
|
-
This gem is tested and supported on the
|
|
11
|
-
|
|
12
|
-
- Ruby 3.0, 3.1, 3.2, 3.3
|
|
13
|
-
|
|
14
|
-
Other Ruby versions might work but are not officially supported.
|
|
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.
|
|
15
11
|
|
|
16
12
|
## Installation
|
|
17
13
|
|
|
@@ -38,25 +34,25 @@ end
|
|
|
38
34
|
|
|
39
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.
|
|
40
36
|
|
|
41
|
-
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.
|
|
42
38
|
|
|
43
|
-
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:
|
|
44
40
|
|
|
45
41
|
```ruby
|
|
46
42
|
# config/initializers/scalar.rb
|
|
47
43
|
|
|
48
44
|
Scalar.setup do |config|
|
|
49
|
-
config.
|
|
45
|
+
config.configuration = { url: 'https://example.com/openapi.json' }
|
|
50
46
|
end
|
|
51
47
|
```
|
|
52
48
|
|
|
53
|
-
|
|
49
|
+
Or embed the file content directly:
|
|
54
50
|
|
|
55
51
|
```ruby
|
|
56
52
|
# config/initializers/scalar.rb
|
|
57
53
|
|
|
58
54
|
Scalar.setup do |config|
|
|
59
|
-
config.
|
|
55
|
+
config.configuration = { content: File.read(Rails.root.join('docs/openapi.yml')) }
|
|
60
56
|
end
|
|
61
57
|
```
|
|
62
58
|
|
|
@@ -64,9 +60,9 @@ And that's it! More detailed information on other configuration options is in th
|
|
|
64
60
|
|
|
65
61
|
## Integrations
|
|
66
62
|
|
|
67
|
-
You can use in
|
|
63
|
+
You can use the built-in generator to set up the gem in [Ruby on Rails](https://rubyonrails.org) by running:
|
|
68
64
|
|
|
69
|
-
```
|
|
65
|
+
```bash
|
|
70
66
|
bin/rails generate scalar:install
|
|
71
67
|
```
|
|
72
68
|
|
|
@@ -74,7 +70,7 @@ bin/rails generate scalar:install
|
|
|
74
70
|
|
|
75
71
|
Once mounted to your application, the library requires no further configuration. You can immediately start playing with the provided API reference example.
|
|
76
72
|
|
|
77
|
-
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.
|
|
78
74
|
|
|
79
75
|
The default configuration can be changed using the `Scalar.setup` method in `config/initializers/scalar.rb`.
|
|
80
76
|
|
|
@@ -82,18 +78,97 @@ The default configuration can be changed using the `Scalar.setup` method in `con
|
|
|
82
78
|
# config/initializers/scalar.rb
|
|
83
79
|
|
|
84
80
|
Scalar.setup do |config|
|
|
85
|
-
|
|
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
|
+
}
|
|
132
|
+
end
|
|
133
|
+
```
|
|
134
|
+
|
|
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
|
+
]
|
|
86
154
|
end
|
|
87
155
|
```
|
|
88
156
|
|
|
89
|
-
|
|
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:
|
|
90
166
|
|
|
91
|
-
Parameter
|
|
92
|
-
|
|
93
|
-
`config.page_title`
|
|
94
|
-
`config.library_url`
|
|
95
|
-
`config.
|
|
96
|
-
`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. | `{}`
|
|
97
172
|
|
|
98
173
|
Example of setting configuration options:
|
|
99
174
|
|
|
@@ -101,7 +176,10 @@ Example of setting configuration options:
|
|
|
101
176
|
# config/initializers/scalar.rb
|
|
102
177
|
|
|
103
178
|
Scalar.setup do |config|
|
|
104
|
-
|
|
179
|
+
config.configuration = {
|
|
180
|
+
theme: 'purple',
|
|
181
|
+
url: 'https://example.com/openapi.json'
|
|
182
|
+
}
|
|
105
183
|
end
|
|
106
184
|
```
|
|
107
185
|
|
|
@@ -121,4 +199,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
121
199
|
|
|
122
200
|
## Code of Conduct
|
|
123
201
|
|
|
124
|
-
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).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
Scalar.setup do |config|
|
|
4
|
-
# Specify the
|
|
4
|
+
# Specify the version of the Scalar. By default, it uses the latest one
|
|
5
5
|
#
|
|
6
6
|
# config.library_url = "https://cdn.jsdelivr.net/npm/@scalar/api-reference"
|
|
7
7
|
|
|
@@ -9,13 +9,15 @@ Scalar.setup do |config|
|
|
|
9
9
|
#
|
|
10
10
|
# config.page_title = "API Reference"
|
|
11
11
|
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
# config.specification = File.read(Rails.root.join("docs/openapi.yml"))
|
|
15
|
-
|
|
16
|
-
# Additional Scalar configuration (e.g. theme) can be set here
|
|
12
|
+
# Set Scalar configuration (e.g. theme, single/multiple specifications or,
|
|
13
|
+
# document sources, etc.)
|
|
17
14
|
#
|
|
18
15
|
# config.scalar_configuration = {
|
|
19
|
-
# theme: "purple"
|
|
16
|
+
# theme: "purple",
|
|
17
|
+
# url: '...'
|
|
20
18
|
# }
|
|
19
|
+
#
|
|
20
|
+
# To enable demo mode, uncomment the configuration below
|
|
21
|
+
#
|
|
22
|
+
# config.configuration = :demo
|
|
21
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,14 +1,14 @@
|
|
|
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
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
email:
|
|
14
14
|
- dmytro@hey.com
|
|
@@ -41,14 +41,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
41
41
|
requirements:
|
|
42
42
|
- - ">="
|
|
43
43
|
- !ruby/object:Gem::Version
|
|
44
|
-
version: '
|
|
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.6.
|
|
51
|
+
rubygems_version: 3.6.9
|
|
52
52
|
specification_version: 4
|
|
53
53
|
summary: A gem to automate using Scalar with Ruby apps
|
|
54
54
|
test_files: []
|