swaggard 2.0.0 → 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 -132
- 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 -32
- 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/spec/fixtures/dummy/config/application.rb +0 -1
- data/spec/fixtures/openapi_3_1_schema.json +1440 -0
- data/spec/integration/openapi_spec.rb +28 -0
- metadata +8 -43
- 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
- data/app/assets/stylesheets/swaggard/typography.css.scss +0 -0
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,25 +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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
0.
|
|
18
|
-
0.
|
|
19
|
-
0.
|
|
20
|
-
0.
|
|
21
|
-
0.1.x | 2.1.3 | 4
|
|
22
|
-
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
|
|
23
21
|
|
|
24
22
|
|
|
25
23
|
## Installation
|
|
@@ -32,47 +30,35 @@ Install the gem with Bundler:
|
|
|
32
30
|
|
|
33
31
|
bundle install
|
|
34
32
|
|
|
33
|
+
|
|
35
34
|
## Getting Started
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
Generate a Swaggard configuration initializer:
|
|
38
37
|
|
|
39
38
|
rails g swaggard:install
|
|
40
39
|
|
|
41
|
-
This
|
|
42
|
-
|
|
43
|
-
Mount your engine
|
|
44
|
-
|
|
45
|
-
# config/routes.rb
|
|
46
|
-
|
|
47
|
-
mount Swaggard::Engine, at: '/api_docs/swagger/'
|
|
48
|
-
|
|
49
|
-
Make sure the asset pipeline is enabled by either requiring all railties
|
|
50
|
-
or just the sprockets one:
|
|
51
|
-
|
|
52
|
-
# config/application.rb
|
|
40
|
+
This installs `config/initializers/swaggard.rb` which you can edit to configure the gem.
|
|
53
41
|
|
|
54
|
-
|
|
42
|
+
Mount the engine:
|
|
55
43
|
|
|
56
|
-
|
|
44
|
+
# config/routes.rb
|
|
45
|
+
mount Swaggard::Engine, at: '/api_docs/swagger/'
|
|
57
46
|
|
|
58
|
-
|
|
47
|
+
Access the documentation UI:
|
|
59
48
|
|
|
49
|
+
open http://localhost:3000/api_docs/swagger/
|
|
60
50
|
|
|
61
|
-
Access the raw
|
|
51
|
+
Access the raw OpenAPI JSON:
|
|
62
52
|
|
|
63
|
-
|
|
53
|
+
open http://localhost:3000/api_docs/swagger.json
|
|
64
54
|
|
|
65
55
|
|
|
66
56
|
## Example
|
|
67
57
|
|
|
68
58
|
By just using Swaggard you'll get documentation for the endpoints that exist on your service:
|
|
69
|
-
|
|
70
|
-
each path.
|
|
71
|
-
|
|
72
|
-
This is fine base but you should add more documentation in order to provide more information
|
|
73
|
-
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.
|
|
74
60
|
|
|
75
|
-
|
|
61
|
+
Add YARD comments to provide richer documentation:
|
|
76
62
|
|
|
77
63
|
# config/routes.rb
|
|
78
64
|
|
|
@@ -146,40 +132,43 @@ Here is a example of how to use Swaggard
|
|
|
146
132
|
|
|
147
133
|
end
|
|
148
134
|
|
|
149
|
-
Will generate
|
|
150
|
-
|
|
151
|
-

|
|
152
135
|
|
|
153
|
-
|
|
154
|
-
## Available tags
|
|
136
|
+
## Available Tags
|
|
155
137
|
|
|
156
138
|
### Controllers
|
|
157
139
|
|
|
158
|
-
- `@tag name`
|
|
159
|
-
- `@query_parameter [type] name`
|
|
160
|
-
- `@body_parameter [type] name`
|
|
161
|
-
- `@
|
|
162
|
-
- `@
|
|
163
|
-
- `@
|
|
164
|
-
- `@
|
|
165
|
-
- `@
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
+
|
|
169
158
|
Swaggard.configure do |config|
|
|
170
|
-
...
|
|
171
159
|
config.ignore_untagged_controllers = false
|
|
172
|
-
...
|
|
173
160
|
end
|
|
174
161
|
|
|
175
162
|
|
|
176
163
|
### Models
|
|
177
164
|
|
|
178
|
-
- `@attr [type] name`
|
|
165
|
+
- `@attr [type] name` — Model attribute.
|
|
166
|
+
- `@ignore_inherited` — Do not inherit properties from parent class.
|
|
167
|
+
|
|
179
168
|
|
|
180
169
|
## Primitives
|
|
181
170
|
|
|
182
|
-
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`:
|
|
183
172
|
|
|
184
173
|
- integer
|
|
185
174
|
- long
|
|
@@ -195,128 +184,92 @@ When one of these types is given Swaggard will handle them directly instead of s
|
|
|
195
184
|
- hash
|
|
196
185
|
|
|
197
186
|
|
|
198
|
-
##
|
|
199
|
-
|
|
200
|
-
Swaggard supports two types of authentication: header and query.
|
|
187
|
+
## Custom Types
|
|
201
188
|
|
|
202
|
-
|
|
189
|
+
Define reusable object schemas that are placed in `components/schemas` and referenced via `$ref`:
|
|
203
190
|
|
|
204
|
-
# config/initializers/swaggard.rb
|
|
205
191
|
Swaggard.configure do |config|
|
|
206
|
-
config.
|
|
207
|
-
|
|
208
|
-
|
|
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])
|
|
209
200
|
end
|
|
210
201
|
|
|
211
|
-
Even if you provide a authentication_value you can later change it from the ui.
|
|
212
202
|
|
|
203
|
+
## Authentication
|
|
213
204
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
Swaggard supports access authorization.
|
|
217
|
-
|
|
218
|
-
You can configure it as follows:
|
|
205
|
+
Swaggard supports injecting auth credentials into every request via `requestInterceptor`.
|
|
219
206
|
|
|
220
|
-
# config/initializers/swaggard.rb
|
|
221
207
|
Swaggard.configure do |config|
|
|
222
|
-
config.
|
|
223
|
-
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 ''
|
|
224
211
|
end
|
|
225
212
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
## Additional parameters
|
|
213
|
+
For OAuth2 / API key schemes visible in the Swagger UI Authorize dialog, use `add_security_definition` and `add_security`:
|
|
230
214
|
|
|
231
|
-
Swaggard supports additional parameters to be sent on every request, either as a header or as part of the query.
|
|
232
|
-
|
|
233
|
-
You can configure it as follows:
|
|
234
|
-
|
|
235
|
-
# config/initializers/swaggard.rb
|
|
236
215
|
Swaggard.configure do |config|
|
|
237
|
-
config.
|
|
216
|
+
config.add_security_definition('api_key', type: 'apiKey', name: 'Authorization', in: 'header')
|
|
217
|
+
config.add_security('api_key')
|
|
238
218
|
end
|
|
239
219
|
|
|
240
|
-
type can be 'header' or 'query'.
|
|
241
|
-
If value is provided then it will be used as a default.
|
|
242
|
-
You can change/set the value for the parameters in the ui.
|
|
243
|
-
|
|
244
220
|
|
|
245
|
-
##
|
|
221
|
+
## Access Authorization
|
|
246
222
|
|
|
247
|
-
|
|
223
|
+
Protect the documentation UI with HTTP Basic auth:
|
|
248
224
|
|
|
249
|
-
# config/initializers/swaggard.rb
|
|
250
225
|
Swaggard.configure do |config|
|
|
251
|
-
config.
|
|
226
|
+
config.access_username = 'admin'
|
|
227
|
+
config.access_password = 'password'
|
|
252
228
|
end
|
|
253
229
|
|
|
254
|
-
If
|
|
230
|
+
If `access_username` is not set, the UI is publicly accessible.
|
|
255
231
|
|
|
256
232
|
|
|
257
|
-
##
|
|
233
|
+
## Additional Parameters
|
|
258
234
|
|
|
259
|
-
|
|
235
|
+
Inject extra headers or query parameters into every request:
|
|
260
236
|
|
|
261
|
-
# config/initializers/swaggard.rb
|
|
262
237
|
Swaggard.configure do |config|
|
|
263
|
-
config.
|
|
238
|
+
config.additional_parameters = [{ key: 'STORE-CODE', type: 'header', value: '1' }]
|
|
264
239
|
end
|
|
265
240
|
|
|
266
|
-
|
|
267
|
-
Supported values are:
|
|
268
|
-
- ca
|
|
269
|
-
- el
|
|
270
|
-
- en
|
|
271
|
-
- es
|
|
272
|
-
- fr
|
|
273
|
-
- geo
|
|
274
|
-
- it
|
|
275
|
-
- ja
|
|
276
|
-
- ko-kr
|
|
277
|
-
- pl
|
|
278
|
-
- pt
|
|
279
|
-
- ru
|
|
280
|
-
- tr
|
|
281
|
-
- zh-cn
|
|
241
|
+
`type` can be `'header'` or `'query'`.
|
|
282
242
|
|
|
283
243
|
|
|
284
244
|
## Caching
|
|
285
245
|
|
|
286
|
-
|
|
246
|
+
Cache the generated OpenAPI JSON for better performance:
|
|
287
247
|
|
|
288
|
-
# config/initializers/swaggard.rb
|
|
289
248
|
Swaggard.configure do |config|
|
|
290
249
|
config.use_cache = Rails.env.production?
|
|
291
250
|
end
|
|
292
251
|
|
|
293
|
-
|
|
252
|
+
Clear the cache with:
|
|
294
253
|
|
|
295
|
-
|
|
254
|
+
rake swaggard:clear_cache
|
|
296
255
|
|
|
297
256
|
|
|
298
257
|
## Documentation Scoping
|
|
299
258
|
|
|
300
|
-
|
|
301
|
-
to do this you just need to use the `controllers_path` config option.
|
|
302
|
-
For instance to only generate documentation for the controllers under `app/controllers/api` you
|
|
303
|
-
need do this:
|
|
259
|
+
Limit documentation to a subset of controllers:
|
|
304
260
|
|
|
305
|
-
# config/initializers/swaggard.rb
|
|
306
261
|
Swaggard.configure do |config|
|
|
307
|
-
...
|
|
308
262
|
config.controllers_path = "#{Rails.root}/app/controllers/api/**/*.rb"
|
|
309
|
-
...
|
|
310
263
|
end
|
|
311
264
|
|
|
312
|
-
|
|
265
|
+
Default: `"#{Rails.root}/app/controllers/**/*.rb"`.
|
|
313
266
|
|
|
314
267
|
|
|
315
268
|
## More Information
|
|
316
269
|
|
|
317
|
-
- [
|
|
318
|
-
- [Swagger
|
|
319
|
-
- [
|
|
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)
|
|
320
273
|
|
|
321
274
|
|
|
322
275
|
## Author
|
|
@@ -326,5 +279,4 @@ The default value for `controllers_path` is `"#{Rails.root}/app/controllers/**/*
|
|
|
326
279
|
|
|
327
280
|
## Credits
|
|
328
281
|
|
|
329
|
-
[Chris Trinh](https://github.com/chtrinh) author of [SwaggerYard](https://github.com/synctv/swagger_yard)
|
|
330
|
-
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,28 +23,5 @@ module Swaggard
|
|
|
32
23
|
|
|
33
24
|
Swaggard.register_custom_yard_tags!
|
|
34
25
|
end
|
|
35
|
-
|
|
36
|
-
initializer "swaggard.assets.precompile", after: 'assets.precompile' do |app|
|
|
37
|
-
next unless app.config.respond_to?(:assets)
|
|
38
|
-
|
|
39
|
-
app.config.assets.precompile += %w(
|
|
40
|
-
swaggard/application.css
|
|
41
|
-
swaggard/application.js
|
|
42
|
-
swaggard/lang/ca.js
|
|
43
|
-
swaggard/lang/el.js
|
|
44
|
-
swaggard/lang/en.js
|
|
45
|
-
swaggard/lang/es.js
|
|
46
|
-
swaggard/lang/fr.js
|
|
47
|
-
swaggard/lang/geo.js
|
|
48
|
-
swaggard/lang/it.js
|
|
49
|
-
swaggard/lang/ja.js
|
|
50
|
-
swaggard/lang/ko-kr.js
|
|
51
|
-
swaggard/lang/pl.js
|
|
52
|
-
swaggard/lang/pt.js
|
|
53
|
-
swaggard/lang/ru.js
|
|
54
|
-
swaggard/lang/tr.js
|
|
55
|
-
swaggard/lang/zh-cn.js
|
|
56
|
-
)
|
|
57
|
-
end
|
|
58
26
|
end
|
|
59
27
|
end
|