swaggard 1.5.1 → 4.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 +84 -131
- data/app/views/swaggard/swagger/index.html.erb +51 -53
- data/lib/swaggard/api_definition.rb +42 -28
- data/lib/swaggard/configuration.rb +1 -5
- data/lib/swaggard/engine.rb +0 -10
- data/lib/swaggard/parsers/routes.rb +1 -1
- data/lib/swaggard/swagger/operation.rb +32 -12
- data/lib/swaggard/swagger/parameters/base.rb +7 -6
- data/lib/swaggard/swagger/parameters/body.rb +9 -9
- data/lib/swaggard/swagger/parameters/form.rb +10 -1
- data/lib/swaggard/swagger/parameters/list.rb +6 -8
- data/lib/swaggard/swagger/parameters/query.rb +9 -9
- data/lib/swaggard/swagger/response.rb +15 -8
- data/lib/swaggard/swagger/response_header.rb +1 -1
- data/lib/swaggard/swagger/type.rb +2 -2
- data/lib/swaggard/version.rb +1 -1
- data/lib/swaggard.rb +9 -1
- data/spec/fixtures/api.json +1 -1
- data/{app/assets/stylesheets/swaggard/typography.css.scss → spec/fixtures/dummy/app/assets/config/manifest.js} +0 -0
- data/spec/fixtures/openapi_3_1_schema.json +1440 -0
- data/spec/integration/openapi_spec.rb +28 -0
- metadata +16 -52
- data/app/assets/fonts/swaggard/DroidSans-Bold.ttf +0 -0
- data/app/assets/fonts/swaggard/DroidSans.ttf +0 -0
- data/app/assets/javascripts/swaggard/application.js +0 -28
- data/app/assets/javascripts/swaggard/lang/ca.js +0 -53
- data/app/assets/javascripts/swaggard/lang/el.js +0 -56
- data/app/assets/javascripts/swaggard/lang/en.js +0 -56
- data/app/assets/javascripts/swaggard/lang/es.js +0 -53
- data/app/assets/javascripts/swaggard/lang/fr.js +0 -54
- data/app/assets/javascripts/swaggard/lang/geo.js +0 -56
- data/app/assets/javascripts/swaggard/lang/it.js +0 -52
- data/app/assets/javascripts/swaggard/lang/ja.js +0 -56
- data/app/assets/javascripts/swaggard/lang/ko-kr.js +0 -53
- data/app/assets/javascripts/swaggard/lang/pl.js +0 -53
- data/app/assets/javascripts/swaggard/lang/pt.js +0 -53
- data/app/assets/javascripts/swaggard/lang/ru.js +0 -56
- data/app/assets/javascripts/swaggard/lang/tr.js +0 -53
- data/app/assets/javascripts/swaggard/lang/zh-cn.js +0 -56
- data/app/assets/javascripts/swaggard/lib/backbone-min.js +0 -1
- data/app/assets/javascripts/swaggard/lib/handlebars-4.0.5.js +0 -3
- data/app/assets/javascripts/swaggard/lib/highlight.9.1.0.pack.js +0 -1
- data/app/assets/javascripts/swaggard/lib/highlight.9.1.0.pack_extended.js +0 -1
- data/app/assets/javascripts/swaggard/lib/jquery-1.8.0.min.js +0 -3
- data/app/assets/javascripts/swaggard/lib/jquery.ba-bbq.min.js +0 -1
- data/app/assets/javascripts/swaggard/lib/jquery.slideto.min.js +0 -1
- data/app/assets/javascripts/swaggard/lib/jquery.wiggle.min.js +0 -1
- data/app/assets/javascripts/swaggard/lib/jsoneditor.min.js +0 -5
- data/app/assets/javascripts/swaggard/lib/lodash.min.js +0 -2
- data/app/assets/javascripts/swaggard/lib/marked.js +0 -1
- data/app/assets/javascripts/swaggard/lib/object-assign-pollyfill.js +0 -1
- data/app/assets/javascripts/swaggard/lib/swagger-oauth.js +0 -1
- data/app/assets/javascripts/swaggard/swaggard.js +0 -72
- data/app/assets/javascripts/swaggard/swagger-ui.js +0 -25378
- data/app/assets/javascripts/swaggard/translator.js +0 -39
- data/app/assets/stylesheets/swaggard/application.css +0 -16
- data/app/assets/stylesheets/swaggard/application_print.css +0 -15
- data/app/assets/stylesheets/swaggard/print.css.scss +0 -4
- data/app/assets/stylesheets/swaggard/reset.css +0 -1
- data/app/assets/stylesheets/swaggard/screen.css.scss +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c18dab011ccdb176dd6324a815a0138f051d85cb9383a60681a857c886d516a5
|
|
4
|
+
data.tar.gz: b8bd9f253e75c56c5308bae421f92cd12b54457edc40aa3d2857b1ac15d1764a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8406ac609bb110a3cb6d67647e5d775db2d293f0ab754020920442a86f202b80064da43843e616144f084ec9d93694b4bd086119f92413c055bd68d80266bb0
|
|
7
|
+
data.tar.gz: 5caa69ecc7b014dccca548a27cdad88428c30f423ff2d922104fef04d0861b7f083af89cd7c0aec21d5f9a52e4173bd822cfb5757cb7bfe245100e3f84481d27
|
data/README.md
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
# Swaggard
|
|
2
2
|
|
|
3
|
-
Swaggard is a Rails Engine that
|
|
3
|
+
Swaggard is a Rails Engine that documents a REST API by generating a JSON file compliant with [OpenAPI 3.1](https://spec.openapis.org/oas/v3.1.0) and displaying it using [Swagger UI 5](https://github.com/swagger-api/swagger-ui).
|
|
4
4
|
This gem is inspired and based on [SwaggerYard](https://github.com/synctv/swagger_yard) by [Chris Trinh](https://github.com/chtrinh).
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
## Compatibility
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
1.
|
|
15
|
-
|
|
16
|
-
0.
|
|
17
|
-
0.
|
|
18
|
-
0.
|
|
19
|
-
0.
|
|
20
|
-
0.
|
|
21
|
-
0.0.x | 2.1.8-M1 | 4
|
|
9
|
+
Swaggard Version | OpenAPI Version | Swagger UI Version | Supported Rails Versions
|
|
10
|
+
---------------- | --------------- | ------------------- | ------------------------
|
|
11
|
+
4.0.x | 3.1 | 5.32.0 | 7 - 8
|
|
12
|
+
2.0.x | 2.0 | 2.2.8 | 7 - 8
|
|
13
|
+
1.1.x | 2.0 | 2.2.8 | 4 - 6
|
|
14
|
+
1.0.x | 2.0 | 2.2.8 | 4 - 5
|
|
15
|
+
0.5.x | 2.0 | 2.2.8 | 4 - 5
|
|
16
|
+
0.4.x | 2.0 | 2.2.8 | 4
|
|
17
|
+
0.3.x | 2.0 | 2.1.3 | 4
|
|
18
|
+
0.2.x | 2.0 | 2.1.3 | 4
|
|
19
|
+
0.1.x | 2.0 | 2.1.3 | 4
|
|
20
|
+
0.0.x | 2.0 | 2.1.8-M1 | 4
|
|
22
21
|
|
|
23
22
|
|
|
24
23
|
## Installation
|
|
@@ -31,47 +30,35 @@ Install the gem with Bundler:
|
|
|
31
30
|
|
|
32
31
|
bundle install
|
|
33
32
|
|
|
33
|
+
|
|
34
34
|
## Getting Started
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
Generate a Swaggard configuration initializer:
|
|
37
37
|
|
|
38
38
|
rails g swaggard:install
|
|
39
39
|
|
|
40
|
-
This
|
|
41
|
-
|
|
42
|
-
Mount your engine
|
|
43
|
-
|
|
44
|
-
# config/routes.rb
|
|
45
|
-
|
|
46
|
-
mount Swaggard::Engine, at: '/api_docs/swagger/'
|
|
47
|
-
|
|
48
|
-
Make sure the asset pipeline is enabled by either requiring all railties
|
|
49
|
-
or just the sprockets one:
|
|
50
|
-
|
|
51
|
-
# config/application.rb
|
|
40
|
+
This installs `config/initializers/swaggard.rb` which you can edit to configure the gem.
|
|
52
41
|
|
|
53
|
-
|
|
42
|
+
Mount the engine:
|
|
54
43
|
|
|
55
|
-
|
|
44
|
+
# config/routes.rb
|
|
45
|
+
mount Swaggard::Engine, at: '/api_docs/swagger/'
|
|
56
46
|
|
|
57
|
-
|
|
47
|
+
Access the documentation UI:
|
|
58
48
|
|
|
49
|
+
open http://localhost:3000/api_docs/swagger/
|
|
59
50
|
|
|
60
|
-
Access the raw
|
|
51
|
+
Access the raw OpenAPI JSON:
|
|
61
52
|
|
|
62
|
-
|
|
53
|
+
open http://localhost:3000/api_docs/swagger.json
|
|
63
54
|
|
|
64
55
|
|
|
65
56
|
## Example
|
|
66
57
|
|
|
67
58
|
By just using Swaggard you'll get documentation for the endpoints that exist on your service:
|
|
68
|
-
|
|
69
|
-
each path.
|
|
70
|
-
|
|
71
|
-
This is fine base but you should add more documentation in order to provide more information
|
|
72
|
-
of the expected inputs and outputs or even change the grouping of the endpoints.
|
|
59
|
+
HTTP method, path, and path parameters. Grouping is done based on the controller that holds each path.
|
|
73
60
|
|
|
74
|
-
|
|
61
|
+
Add YARD comments to provide richer documentation:
|
|
75
62
|
|
|
76
63
|
# config/routes.rb
|
|
77
64
|
|
|
@@ -145,40 +132,43 @@ Here is a example of how to use Swaggard
|
|
|
145
132
|
|
|
146
133
|
end
|
|
147
134
|
|
|
148
|
-
Will generate
|
|
149
|
-
|
|
150
|
-

|
|
151
135
|
|
|
152
|
-
|
|
153
|
-
## Available tags
|
|
136
|
+
## Available Tags
|
|
154
137
|
|
|
155
138
|
### Controllers
|
|
156
139
|
|
|
157
|
-
- `@tag name`
|
|
158
|
-
- `@query_parameter [type] name`
|
|
159
|
-
- `@body_parameter [type] name`
|
|
160
|
-
- `@
|
|
161
|
-
- `@
|
|
162
|
-
- `@
|
|
163
|
-
- `@
|
|
164
|
-
- `@
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
140
|
+
- `@tag name` — Group this controller under `name`. Defaults to the controller path if `ignore_untagged_controllers` is false.
|
|
141
|
+
- `@query_parameter [type] name` — Query string parameter.
|
|
142
|
+
- `@body_parameter [type] name` — Request body property. Generates a `requestBody` in the OpenAPI output.
|
|
143
|
+
- `@form_parameter [type] name` — Form data parameter (`application/x-www-form-urlencoded`).
|
|
144
|
+
- `@parameter_list` — Enum-style query parameter list.
|
|
145
|
+
- `@response_class type` — Response schema type. Supports `Array<Type>` for array responses.
|
|
146
|
+
- `@response_status 200` — HTTP response status code.
|
|
147
|
+
- `@response_root name` — Wrap the response in a root key.
|
|
148
|
+
- `@response_description text` — Description for the response.
|
|
149
|
+
- `@response_example path/to/example.json` — Example response. Inlined if the file exists on disk, otherwise used as an `externalValue` URI.
|
|
150
|
+
- `@response_header [type] name description` — Response header.
|
|
151
|
+
- `@operation_id id` — Override the `operationId`.
|
|
152
|
+
- `@body_required` — Mark the request body as required.
|
|
153
|
+
- `@body_title title` — Title for the generated request body schema.
|
|
154
|
+
- `@body_definition SchemaName` — Reference an existing schema by name as the request body.
|
|
155
|
+
|
|
156
|
+
To document all controllers including those without a `@tag`:
|
|
157
|
+
|
|
168
158
|
Swaggard.configure do |config|
|
|
169
|
-
...
|
|
170
159
|
config.ignore_untagged_controllers = false
|
|
171
|
-
...
|
|
172
160
|
end
|
|
173
161
|
|
|
174
162
|
|
|
175
163
|
### Models
|
|
176
164
|
|
|
177
|
-
- `@attr [type] name`
|
|
165
|
+
- `@attr [type] name` — Model attribute.
|
|
166
|
+
- `@ignore_inherited` — Do not inherit properties from parent class.
|
|
167
|
+
|
|
178
168
|
|
|
179
169
|
## Primitives
|
|
180
170
|
|
|
181
|
-
When one of these types is
|
|
171
|
+
When one of these types is used Swaggard maps it to an inline schema instead of a `$ref`:
|
|
182
172
|
|
|
183
173
|
- integer
|
|
184
174
|
- long
|
|
@@ -194,128 +184,92 @@ When one of these types is given Swaggard will handle them directly instead of s
|
|
|
194
184
|
- hash
|
|
195
185
|
|
|
196
186
|
|
|
197
|
-
##
|
|
198
|
-
|
|
199
|
-
Swaggard supports two types of authentication: header and query.
|
|
187
|
+
## Custom Types
|
|
200
188
|
|
|
201
|
-
|
|
189
|
+
Define reusable object schemas that are placed in `components/schemas` and referenced via `$ref`:
|
|
202
190
|
|
|
203
|
-
# config/initializers/swaggard.rb
|
|
204
191
|
Swaggard.configure do |config|
|
|
205
|
-
config.
|
|
206
|
-
|
|
207
|
-
|
|
192
|
+
config.add_custom_type('Address', type: :object,
|
|
193
|
+
properties: {
|
|
194
|
+
line1: { type: :string },
|
|
195
|
+
city: { type: :string },
|
|
196
|
+
state: { type: :string },
|
|
197
|
+
zip: { type: :string },
|
|
198
|
+
},
|
|
199
|
+
required: %i[line1 city state zip])
|
|
208
200
|
end
|
|
209
201
|
|
|
210
|
-
Even if you provide a authentication_value you can later change it from the ui.
|
|
211
202
|
|
|
203
|
+
## Authentication
|
|
212
204
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
Swaggard supports access authorization.
|
|
216
|
-
|
|
217
|
-
You can configure it as follows:
|
|
205
|
+
Swaggard supports injecting auth credentials into every request via `requestInterceptor`.
|
|
218
206
|
|
|
219
|
-
# config/initializers/swaggard.rb
|
|
220
207
|
Swaggard.configure do |config|
|
|
221
|
-
config.
|
|
222
|
-
config.
|
|
208
|
+
config.authentication_type = 'header' # or 'query'. Defaults to 'query'
|
|
209
|
+
config.authentication_key = 'X-AUTH-TOKEN' # Defaults to 'api_key'
|
|
210
|
+
config.authentication_value = 'your-secret-key' # Defaults to ''
|
|
223
211
|
end
|
|
224
212
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
## Additional parameters
|
|
213
|
+
For OAuth2 / API key schemes visible in the Swagger UI Authorize dialog, use `add_security_definition` and `add_security`:
|
|
229
214
|
|
|
230
|
-
Swaggard supports additional parameters to be sent on every request, either as a header or as part of the query.
|
|
231
|
-
|
|
232
|
-
You can configure it as follows:
|
|
233
|
-
|
|
234
|
-
# config/initializers/swaggard.rb
|
|
235
215
|
Swaggard.configure do |config|
|
|
236
|
-
config.
|
|
216
|
+
config.add_security_definition('api_key', type: 'apiKey', name: 'Authorization', in: 'header')
|
|
217
|
+
config.add_security('api_key')
|
|
237
218
|
end
|
|
238
219
|
|
|
239
|
-
type can be 'header' or 'query'.
|
|
240
|
-
If value is provided then it will be used as a default.
|
|
241
|
-
You can change/set the value for the parameters in the ui.
|
|
242
|
-
|
|
243
220
|
|
|
244
|
-
##
|
|
221
|
+
## Access Authorization
|
|
245
222
|
|
|
246
|
-
|
|
223
|
+
Protect the documentation UI with HTTP Basic auth:
|
|
247
224
|
|
|
248
|
-
# config/initializers/swaggard.rb
|
|
249
225
|
Swaggard.configure do |config|
|
|
250
|
-
config.
|
|
226
|
+
config.access_username = 'admin'
|
|
227
|
+
config.access_password = 'password'
|
|
251
228
|
end
|
|
252
229
|
|
|
253
|
-
If
|
|
230
|
+
If `access_username` is not set, the UI is publicly accessible.
|
|
254
231
|
|
|
255
232
|
|
|
256
|
-
##
|
|
233
|
+
## Additional Parameters
|
|
257
234
|
|
|
258
|
-
|
|
235
|
+
Inject extra headers or query parameters into every request:
|
|
259
236
|
|
|
260
|
-
# config/initializers/swaggard.rb
|
|
261
237
|
Swaggard.configure do |config|
|
|
262
|
-
config.
|
|
238
|
+
config.additional_parameters = [{ key: 'STORE-CODE', type: 'header', value: '1' }]
|
|
263
239
|
end
|
|
264
240
|
|
|
265
|
-
|
|
266
|
-
Supported values are:
|
|
267
|
-
- ca
|
|
268
|
-
- el
|
|
269
|
-
- en
|
|
270
|
-
- es
|
|
271
|
-
- fr
|
|
272
|
-
- geo
|
|
273
|
-
- it
|
|
274
|
-
- ja
|
|
275
|
-
- ko-kr
|
|
276
|
-
- pl
|
|
277
|
-
- pt
|
|
278
|
-
- ru
|
|
279
|
-
- tr
|
|
280
|
-
- zh-cn
|
|
241
|
+
`type` can be `'header'` or `'query'`.
|
|
281
242
|
|
|
282
243
|
|
|
283
244
|
## Caching
|
|
284
245
|
|
|
285
|
-
|
|
246
|
+
Cache the generated OpenAPI JSON for better performance:
|
|
286
247
|
|
|
287
|
-
# config/initializers/swaggard.rb
|
|
288
248
|
Swaggard.configure do |config|
|
|
289
249
|
config.use_cache = Rails.env.production?
|
|
290
250
|
end
|
|
291
251
|
|
|
292
|
-
|
|
252
|
+
Clear the cache with:
|
|
293
253
|
|
|
294
|
-
|
|
254
|
+
rake swaggard:clear_cache
|
|
295
255
|
|
|
296
256
|
|
|
297
257
|
## Documentation Scoping
|
|
298
258
|
|
|
299
|
-
|
|
300
|
-
to do this you just need to use the `controllers_path` config option.
|
|
301
|
-
For instance to only generate documentation for the controllers under `app/controllers/api` you
|
|
302
|
-
need do this:
|
|
259
|
+
Limit documentation to a subset of controllers:
|
|
303
260
|
|
|
304
|
-
# config/initializers/swaggard.rb
|
|
305
261
|
Swaggard.configure do |config|
|
|
306
|
-
...
|
|
307
262
|
config.controllers_path = "#{Rails.root}/app/controllers/api/**/*.rb"
|
|
308
|
-
...
|
|
309
263
|
end
|
|
310
264
|
|
|
311
|
-
|
|
265
|
+
Default: `"#{Rails.root}/app/controllers/**/*.rb"`.
|
|
312
266
|
|
|
313
267
|
|
|
314
268
|
## More Information
|
|
315
269
|
|
|
316
|
-
- [
|
|
317
|
-
- [Swagger
|
|
318
|
-
- [
|
|
270
|
+
- [OpenAPI 3.1 Specification](https://spec.openapis.org/oas/v3.1.0)
|
|
271
|
+
- [Swagger UI](https://github.com/swagger-api/swagger-ui)
|
|
272
|
+
- [YARD](https://github.com/lsegal/yard)
|
|
319
273
|
|
|
320
274
|
|
|
321
275
|
## Author
|
|
@@ -325,5 +279,4 @@ The default value for `controllers_path` is `"#{Rails.root}/app/controllers/**/*
|
|
|
325
279
|
|
|
326
280
|
## Credits
|
|
327
281
|
|
|
328
|
-
[Chris Trinh](https://github.com/chtrinh) author of [SwaggerYard](https://github.com/synctv/swagger_yard)
|
|
329
|
-
inspired and used a base.
|
|
282
|
+
[Chris Trinh](https://github.com/chtrinh) — author of [SwaggerYard](https://github.com/synctv/swagger_yard), which this gem is inspired by and based on.
|
|
@@ -2,61 +2,59 @@
|
|
|
2
2
|
<html>
|
|
3
3
|
<head>
|
|
4
4
|
<title>Swagger UI</title>
|
|
5
|
-
|
|
6
5
|
<%= favicon_link_tag 'swaggard/favicon-32x32.png', sizes: '32x32' %>
|
|
7
6
|
<%= favicon_link_tag 'swaggard/favicon-16x16.png', sizes: '16x16' %>
|
|
8
|
-
|
|
9
|
-
<%= stylesheet_link_tag 'swaggard/application', media: :screen %>
|
|
10
|
-
<%= stylesheet_link_tag 'swaggard/application_print', media: :print %>
|
|
11
|
-
|
|
12
|
-
<%= javascript_include_tag 'swaggard/application' %>
|
|
13
|
-
<%= javascript_include_tag "swaggard/lang/#{Swaggard.configuration.language}" %>
|
|
14
|
-
|
|
15
|
-
<%= javascript_tag do %>
|
|
16
|
-
window.default_content_type = '<%= Swaggard.configuration.default_content_type %>';
|
|
17
|
-
<% end %>
|
|
18
|
-
|
|
7
|
+
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.32.0/swagger-ui.css">
|
|
19
8
|
</head>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
9
|
+
<body>
|
|
10
|
+
<div id="swagger-ui"></div>
|
|
11
|
+
|
|
12
|
+
<script id="swagger-config" type="application/json">
|
|
13
|
+
<%= {
|
|
14
|
+
url: doc_path(format: :json),
|
|
15
|
+
authType: @authentication_type,
|
|
16
|
+
authKey: @authentication_key,
|
|
17
|
+
authValue: @authentication_value,
|
|
18
|
+
additionalParameters: Swaggard.configuration.additional_parameters
|
|
19
|
+
}.to_json.html_safe %>
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script src="https://unpkg.com/swagger-ui-dist@5.32.0/swagger-ui-bundle.js"></script>
|
|
23
|
+
<script>
|
|
24
|
+
window.onload = function() {
|
|
25
|
+
var config = JSON.parse(document.getElementById('swagger-config').textContent);
|
|
26
|
+
|
|
27
|
+
SwaggerUIBundle({
|
|
28
|
+
url: config.url,
|
|
29
|
+
dom_id: '#swagger-ui',
|
|
30
|
+
deepLinking: true,
|
|
31
|
+
presets: [SwaggerUIBundle.presets.apis],
|
|
32
|
+
plugins: [SwaggerUIBundle.plugins.DownloadUrl],
|
|
33
|
+
requestInterceptor: function(request) {
|
|
34
|
+
if (config.authValue) {
|
|
35
|
+
if (config.authType === 'header') {
|
|
36
|
+
request.headers[config.authKey] = config.authValue;
|
|
37
|
+
} else {
|
|
38
|
+
var url = new URL(request.url);
|
|
39
|
+
url.searchParams.set(config.authKey, config.authValue);
|
|
40
|
+
request.url = url.toString();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
(config.additionalParameters || []).forEach(function(param) {
|
|
45
|
+
if (param.type === 'header') {
|
|
46
|
+
request.headers[param.key] = param.value;
|
|
47
|
+
} else if (param.type === 'query') {
|
|
48
|
+
var url = new URL(request.url);
|
|
49
|
+
url.searchParams.set(param.key, param.value);
|
|
50
|
+
request.url = url.toString();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return request;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
</script>
|
|
61
59
|
</body>
|
|
62
60
|
</html>
|
|
@@ -34,25 +34,31 @@ module Swaggard
|
|
|
34
34
|
license = { 'name' => Swaggard.configuration.license_name }
|
|
35
35
|
license['url'] = Swaggard.configuration.license_url if Swaggard.configuration.license_url.present?
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
}
|
|
37
|
+
config = Swaggard.configuration
|
|
38
|
+
server_url = "#{config.schemes.first}://#{config.host}#{config.api_base_path}"
|
|
39
|
+
|
|
40
|
+
info = {
|
|
41
|
+
'version' => config.api_version,
|
|
42
|
+
'title' => config.title,
|
|
43
|
+
'description' => config.description,
|
|
44
|
+
'contact' => contact,
|
|
45
|
+
'license' => license,
|
|
46
|
+
}
|
|
47
|
+
info['termsOfService'] = config.tos if config.tos.present?
|
|
48
|
+
|
|
49
|
+
doc = {
|
|
50
|
+
'openapi' => '3.1.0',
|
|
51
|
+
'info' => info,
|
|
52
|
+
'servers' => [{ 'url' => server_url }],
|
|
53
|
+
'tags' => @tags.map { |_, tag| tag.to_doc },
|
|
54
|
+
'paths' => Hash[@paths.values.map { |path| [format_path(path.path), path.to_doc] }],
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
components = build_components
|
|
58
|
+
doc['components'] = components unless components.empty?
|
|
59
|
+
doc['security'] = config.security unless config.security.empty?
|
|
60
|
+
|
|
61
|
+
doc
|
|
56
62
|
end
|
|
57
63
|
|
|
58
64
|
private
|
|
@@ -63,21 +69,29 @@ module Swaggard
|
|
|
63
69
|
path.gsub(Swaggard.configuration.api_base_path, '')
|
|
64
70
|
end
|
|
65
71
|
|
|
66
|
-
def
|
|
67
|
-
|
|
72
|
+
def build_components
|
|
73
|
+
custom_type_schemas = Swaggard.configuration.custom_types
|
|
74
|
+
.transform_keys { |k| Swaggard.ref_name(k) }
|
|
68
75
|
|
|
69
|
-
|
|
76
|
+
definition_schemas = Hash[
|
|
77
|
+
@definitions.merge(Swaggard.configuration.definitions)
|
|
78
|
+
.map { |id, definition| [Swaggard.ref_name(id), definition.to_doc(@definitions)] }
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
schemas = custom_type_schemas.merge(definition_schemas)
|
|
82
|
+
|
|
83
|
+
security_schemes = Swaggard.configuration.security_definitions
|
|
70
84
|
|
|
71
85
|
Swaggard.configuration.security.flat_map(&:keys).each do |authentication_type|
|
|
72
|
-
next if
|
|
86
|
+
next if security_schemes.key?(authentication_type)
|
|
73
87
|
|
|
74
|
-
warn "#{authentication_type} not supported by
|
|
88
|
+
warn "#{authentication_type} not supported by components/securitySchemes"
|
|
75
89
|
end
|
|
76
90
|
|
|
77
|
-
{
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
result = {}
|
|
92
|
+
result['schemas'] = schemas unless schemas.empty?
|
|
93
|
+
result['securitySchemes'] = security_schemes unless security_schemes.empty?
|
|
94
|
+
result
|
|
81
95
|
end
|
|
82
96
|
end
|
|
83
97
|
end
|
|
@@ -14,7 +14,7 @@ module Swaggard
|
|
|
14
14
|
|
|
15
15
|
attr_accessor :controllers_path, :models_paths, :routes
|
|
16
16
|
|
|
17
|
-
attr_writer :
|
|
17
|
+
attr_writer :api_base_path, :api_version, :api_formats, :title,
|
|
18
18
|
:description, :tos, :contact_email, :contact_name, :contact_url, :host,
|
|
19
19
|
:authentication_type, :authentication_key, :authentication_value,
|
|
20
20
|
:access_username, :access_password, :default_content_type, :use_cache,
|
|
@@ -23,10 +23,6 @@ module Swaggard
|
|
|
23
23
|
:default_response_status_code, :excluded_paths, :path_parameter_description,
|
|
24
24
|
:ignore_put_if_patch_exists, :ignore_untagged_controllers
|
|
25
25
|
|
|
26
|
-
def swagger_version
|
|
27
|
-
@swagger_version ||= '2.0'
|
|
28
|
-
end
|
|
29
|
-
|
|
30
26
|
def api_version
|
|
31
27
|
@api_version ||= '0.1'
|
|
32
28
|
end
|
data/lib/swaggard/engine.rb
CHANGED
|
@@ -9,15 +9,6 @@ module Swaggard
|
|
|
9
9
|
initializer 'swaggard.finisher_hook', after: :finisher_hook do |app|
|
|
10
10
|
app.reload_routes!
|
|
11
11
|
|
|
12
|
-
if Rails.env.development? && !rake? && !app.methods.include?(:assets_manifest)
|
|
13
|
-
warn <<~END
|
|
14
|
-
[Swaggard] It seems you are using an api only rails setup, but swaggard
|
|
15
|
-
[Swaggard] web app needs sprockets in order to work. Make sure to add
|
|
16
|
-
[Swaggard] require 'sprockets/railtie'.
|
|
17
|
-
[Swaggard] If you plan to use it
|
|
18
|
-
END
|
|
19
|
-
end
|
|
20
|
-
|
|
21
12
|
Swaggard.configure do |config|
|
|
22
13
|
unless config.controllers_path
|
|
23
14
|
config.controllers_path = "#{app.root}/app/controllers/**/*.rb"
|
|
@@ -32,6 +23,5 @@ module Swaggard
|
|
|
32
23
|
|
|
33
24
|
Swaggard.register_custom_yard_tags!
|
|
34
25
|
end
|
|
35
|
-
|
|
36
26
|
end
|
|
37
27
|
end
|