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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebbb3b25b5e211a1aba05134d5f54aee9117073edf95f14c55dadd34c26a5141
4
- data.tar.gz: d7918de252e40550258ad63b169c9fd6b8be93531390d54950c98f1dd0ca7bc7
3
+ metadata.gz: a21547938d1fb384cf1a97984c15eb33dd883d0f4c0e4e4a2bea9482d37215ce
4
+ data.tar.gz: df9316873f075b3a1b5e3e46734ac2a90d0febaa29a86d02ecdcd7b6c9231e6c
5
5
  SHA512:
6
- metadata.gz: f6f20de57d3558a21630d3f8937ceb3d6863269189c77c75248b756868e2ab903dc6fdc30da9482c6a6e6db690e551b3e49b703ccbc5919bd1e6a3f7a2148472
7
- data.tar.gz: 4f28e02faa358651f1aad4fc4f9908086f585d4bf2df05cf3081b13876a307173c91d795af7058755a54d0eb545a3a81c060c19889def3c158b04e3c76ae72b9
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 following Ruby versions:
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 the Scalar.
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 as `config.specification` using the `Scalar.setup` method:
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.specification = File.read(Rails.root.join('docs/openapi.yml'))
45
+ config.configuration = { url: 'https://example.com/openapi.json' }
50
46
  end
51
47
  ```
52
48
 
53
- Also, you can pass a URL to the specification:
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.specification = "#{ActionMailer::Base.default_url_options[:host]/openapi.json}"
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-build generator to setup gem into [Ruby in Rails](https://rubyonrails.org) framework by running:
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
- ```ruby
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 the Scalar fits your project. However, most users would love to utilize their specifications and be able to alter settings.
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
- config.page_title = 'My awesome API!'
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
- Below, you’ll find a complete list of configuration settings:
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 | Description | Default
92
- -------------------------------------------|---------------------------------------------------------|------------------------
93
- `config.page_title` | Defines the page title displayed in the browser tab. | API Reference
94
- `config.library_url` | Allows to set a specific version of Scalar. By default, it uses the latest version of Scalar, so users get the latest updates and bug fixes. | https://cdn.jsdelivr.net/npm/@scalar/api-reference
95
- `config.scalar_configuration` | Scalar has a rich set of configuration options if you want to change how it works and looks. A complete list of configuration options can be found [here](https://github.com/scalar/scalar/blob/main/documentation/configuration.md). | {}
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
- config.scalar_configuration = { theme: 'purple' }
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 projects 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).
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 specific version of the Scalar. By default it uses the latest one
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
- # Pass your API specification. It may be URL or file content in OpenAPI format
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
- DEFAULT_SCALAR_CONFIGURATION = {}.freeze
13
- DEFAULT_SPECIFICATION = 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml'
12
+ DEFAULT_CONFIGURATION = {}.freeze
14
13
 
15
- attr_accessor :library_url,
16
- :page_title,
17
- :scalar_configuration,
18
- :specification
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 scalar_configuration_to_json
25
- JSON.dump(scalar_configuration)
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
- @scalar_configuration = DEFAULT_SCALAR_CONFIGURATION
32
- @specification = DEFAULT_SPECIFICATION
35
+ @configuration = DEFAULT_CONFIGURATION
33
36
  end
34
37
  end
35
38
  end
@@ -8,13 +8,15 @@
8
8
  </head>
9
9
 
10
10
  <body>
11
- <script
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>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scalar
4
- VERSION = '1.1.0'
4
+ VERSION = '2.0.0'
5
5
  end
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: 1.1.0
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: 2025-02-10 00:00:00.000000000 Z
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: '3.0'
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.3
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: []