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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +84 -132
  3. data/app/views/swaggard/swagger/index.html.erb +51 -53
  4. data/lib/swaggard/api_definition.rb +42 -28
  5. data/lib/swaggard/configuration.rb +1 -5
  6. data/lib/swaggard/engine.rb +0 -32
  7. data/lib/swaggard/swagger/operation.rb +32 -12
  8. data/lib/swaggard/swagger/parameters/base.rb +7 -6
  9. data/lib/swaggard/swagger/parameters/body.rb +9 -9
  10. data/lib/swaggard/swagger/parameters/form.rb +10 -1
  11. data/lib/swaggard/swagger/parameters/list.rb +6 -8
  12. data/lib/swaggard/swagger/parameters/query.rb +9 -9
  13. data/lib/swaggard/swagger/response.rb +15 -8
  14. data/lib/swaggard/swagger/response_header.rb +1 -1
  15. data/lib/swaggard/swagger/type.rb +2 -2
  16. data/lib/swaggard/version.rb +1 -1
  17. data/lib/swaggard.rb +9 -1
  18. data/spec/fixtures/api.json +1 -1
  19. data/spec/fixtures/dummy/config/application.rb +0 -1
  20. data/spec/fixtures/openapi_3_1_schema.json +1440 -0
  21. data/spec/integration/openapi_spec.rb +28 -0
  22. metadata +8 -43
  23. data/app/assets/fonts/swaggard/DroidSans-Bold.ttf +0 -0
  24. data/app/assets/fonts/swaggard/DroidSans.ttf +0 -0
  25. data/app/assets/javascripts/swaggard/application.js +0 -28
  26. data/app/assets/javascripts/swaggard/lang/ca.js +0 -53
  27. data/app/assets/javascripts/swaggard/lang/el.js +0 -56
  28. data/app/assets/javascripts/swaggard/lang/en.js +0 -56
  29. data/app/assets/javascripts/swaggard/lang/es.js +0 -53
  30. data/app/assets/javascripts/swaggard/lang/fr.js +0 -54
  31. data/app/assets/javascripts/swaggard/lang/geo.js +0 -56
  32. data/app/assets/javascripts/swaggard/lang/it.js +0 -52
  33. data/app/assets/javascripts/swaggard/lang/ja.js +0 -56
  34. data/app/assets/javascripts/swaggard/lang/ko-kr.js +0 -53
  35. data/app/assets/javascripts/swaggard/lang/pl.js +0 -53
  36. data/app/assets/javascripts/swaggard/lang/pt.js +0 -53
  37. data/app/assets/javascripts/swaggard/lang/ru.js +0 -56
  38. data/app/assets/javascripts/swaggard/lang/tr.js +0 -53
  39. data/app/assets/javascripts/swaggard/lang/zh-cn.js +0 -56
  40. data/app/assets/javascripts/swaggard/lib/backbone-min.js +0 -1
  41. data/app/assets/javascripts/swaggard/lib/handlebars-4.0.5.js +0 -3
  42. data/app/assets/javascripts/swaggard/lib/highlight.9.1.0.pack.js +0 -1
  43. data/app/assets/javascripts/swaggard/lib/highlight.9.1.0.pack_extended.js +0 -1
  44. data/app/assets/javascripts/swaggard/lib/jquery-1.8.0.min.js +0 -3
  45. data/app/assets/javascripts/swaggard/lib/jquery.ba-bbq.min.js +0 -1
  46. data/app/assets/javascripts/swaggard/lib/jquery.slideto.min.js +0 -1
  47. data/app/assets/javascripts/swaggard/lib/jquery.wiggle.min.js +0 -1
  48. data/app/assets/javascripts/swaggard/lib/jsoneditor.min.js +0 -5
  49. data/app/assets/javascripts/swaggard/lib/lodash.min.js +0 -2
  50. data/app/assets/javascripts/swaggard/lib/marked.js +0 -1
  51. data/app/assets/javascripts/swaggard/lib/object-assign-pollyfill.js +0 -1
  52. data/app/assets/javascripts/swaggard/lib/swagger-oauth.js +0 -1
  53. data/app/assets/javascripts/swaggard/swaggard.js +0 -72
  54. data/app/assets/javascripts/swaggard/swagger-ui.js +0 -25378
  55. data/app/assets/javascripts/swaggard/translator.js +0 -39
  56. data/app/assets/stylesheets/swaggard/application.css +0 -16
  57. data/app/assets/stylesheets/swaggard/application_print.css +0 -15
  58. data/app/assets/stylesheets/swaggard/print.css.scss +0 -4
  59. data/app/assets/stylesheets/swaggard/reset.css +0 -1
  60. data/app/assets/stylesheets/swaggard/screen.css.scss +0 -4
  61. 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: 21148d73c5de69058c02b8ea95a396ed2efee41b23ba4db664235a3cf7486cfa
4
- data.tar.gz: b40da15f195ec2c8be0b27cf0bce4aced8852c337bd31ab87ad654b5127c12b0
3
+ metadata.gz: c18dab011ccdb176dd6324a815a0138f051d85cb9383a60681a857c886d516a5
4
+ data.tar.gz: b8bd9f253e75c56c5308bae421f92cd12b54457edc40aa3d2857b1ac15d1764a
5
5
  SHA512:
6
- metadata.gz: 4f955faa13d67310fa58904511eabd01677d8927f911b993fc5c4b8674cbdc546d89a87c6f69040a988c772d896be54c20c779c61d7fb86d6eacb61dc286bea4
7
- data.tar.gz: be76ce911cf5c32c86ae7c44b3c57cee2aae4fed10d0de24d8ed9b5213cf42a3498e7f503dea5b898b7b80bccfd4b62ff6f8033cbfbd3a5dcd8a8593d260720d
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 can be used to document a REST api. It does this by generating a json that is compliant with [Swagger](http://swagger.io) and displaying it using [Swagger-ui](https://github.com/wordnik/swagger-ui).
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
- This table tracks the version of Swagger UI used on each Swaggard version and
10
- the supported rails version.
11
-
12
- Swaggard Version | Swagger UI Version | Supported Rails Versions
13
- ---------------- | ------------------- | ------------------------
14
- 2.0.x | 2.2.8 | 7 - 8
15
- 1.1.x | 2.2.8 | 4 - 6
16
- 1.0.x | 2.2.8 | 4 - 5
17
- 0.5.x | 2.2.8 | 4 - 5
18
- 0.4.x | 2.2.8 | 4
19
- 0.3.x | 2.1.3 | 4
20
- 0.2.x | 2.1.3 | 4
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
- First generate a Swaggard configuration initializer file.
36
+ Generate a Swaggard configuration initializer:
38
37
 
39
38
  rails g swaggard:install
40
39
 
41
- This will install the file `swaggard.rb` to your Rails `config/initializers` directory which you can then alter the config.
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
- require 'sprockets/railtie'
42
+ Mount the engine:
55
43
 
56
- Access your service documentation
44
+ # config/routes.rb
45
+ mount Swaggard::Engine, at: '/api_docs/swagger/'
57
46
 
58
- open http://localhost:3000/api_docs/swagger/
47
+ Access the documentation UI:
59
48
 
49
+ open http://localhost:3000/api_docs/swagger/
60
50
 
61
- Access the raw swagger json
51
+ Access the raw OpenAPI JSON:
62
52
 
63
- open http://localhost:3000/api_docs/swagger.json
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
- http method, path, path params. And grouping will be done based on the controller that holds
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
- Here is a example of how to use Swaggard
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
- ![Web UI](https://raw.githubusercontent.com/Moove-it/swaggard/master/example/web-ui.png)
152
135
 
153
-
154
- ## Available tags
136
+ ## Available Tags
155
137
 
156
138
  ### Controllers
157
139
 
158
- - `@tag name` This is used to indicate under what `name` tag this controller needs to be grouped. If not provided and `!ignore_untagged_controllers` it will use the full controller class name.
159
- - `@query_parameter [type] name` This is used to indicate that your action receives the `name` parameter of `type` on the query string.
160
- - `@body_parameter [type] name` This is used to indicate that your action receives the `name` parameter of `type` on the body.
161
- - `@response_class type` This is used to indicate that your action returns a response of `type`.
162
- - `@response_status 200` This is used to indicate the response code of your action when everything goes well.
163
- - `@response_root name` This is used to indicate that your action returns its response inside a root key element `name`. If not provided the root is omitted and the response its returned directly.
164
- - `@form_parameter`
165
- - `@parameter_list`
166
-
167
- If you want to generate documentation for all controllers even for those that don't have a tag do:
168
- # config/initializers/swaggard.rb
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` This is used to indicate that your models has an attribute `name` of `type`.
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 given Swaggard will handle them directly instead of searching for a definition:
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
- ## Authentication
199
-
200
- Swaggard supports two types of authentication: header and query.
187
+ ## Custom Types
201
188
 
202
- You can configure it as follows:
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.authentication_type = 'header' # Defaults to 'query'
207
- config.authentication_key = 'X-AUTH-TOKEN' # Defaults to 'api_key'
208
- config.authentication_value = 'your-secret-key' # Initial value for authentication. Defaults to ''
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
- ## Access authorization
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.access_username = 'admin'
223
- config.access_password = 'password'
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
- If you not set `access_username`, everyone will have access to Swagger documentation.
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.additional_parameters = [{ key: 'TOKEN', type: 'header', value: '234' }]
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
- ## Default content type
221
+ ## Access Authorization
246
222
 
247
- You can set default content type in Swaggard configuration as follows:
223
+ Protect the documentation UI with HTTP Basic auth:
248
224
 
249
- # config/initializers/swaggard.rb
250
225
  Swaggard.configure do |config|
251
- config.default_content_type = 'application/json'
226
+ config.access_username = 'admin'
227
+ config.access_password = 'password'
252
228
  end
253
229
 
254
- If you set `default_content_type`, Swagger will use it in example request.
230
+ If `access_username` is not set, the UI is publicly accessible.
255
231
 
256
232
 
257
- ## Language
233
+ ## Additional Parameters
258
234
 
259
- You can set the language for SwaggerUI as follows:
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.language = 'es'
238
+ config.additional_parameters = [{ key: 'STORE-CODE', type: 'header', value: '1' }]
264
239
  end
265
240
 
266
- The default value is: 'en'.
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
- You can improve Swagger performance by using caching. You can enable `use_cache` in Swaggard configuration as follows:
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
- If you set `use_cache` as `Rails.env.production?`, Swagger will use cache only in production mode.
252
+ Clear the cache with:
294
253
 
295
- Note. For cache clearing you can execute `rake swaggard:clear_cache`.
254
+ rake swaggard:clear_cache
296
255
 
297
256
 
298
257
  ## Documentation Scoping
299
258
 
300
- Its possible to only generate Swagger documentation for a subset of your application controllers
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
- The default value for `controllers_path` is `"#{Rails.root}/app/controllers/**/*.rb"`.
265
+ Default: `"#{Rails.root}/app/controllers/**/*.rb"`.
313
266
 
314
267
 
315
268
  ## More Information
316
269
 
317
- - [Swagger](http://swagger.io)
318
- - [Swagger-ui](https://github.com/wordnik/swagger-ui)
319
- - [Yard](https://github.com/lsegal/yard)
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) in which this gem is
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
- <body class='swagger-section' data-doc-path='<%= doc_path(format: :json)%>'>
22
- <div id='header'>
23
- <div class='swagger-ui-wrap'>
24
- <a id='logo' href='http://swagger.io'>
25
- <%= image_tag 'swaggard/logo_small.png', class: 'logo__img', alt: 'swagger', height: 30, width: 30 %>
26
- <span class='logo__title'>swagger</span>
27
- </a>
28
- <%= form_tag '', id: :api_selector do %>
29
-
30
- <div>
31
- <div class='input'><input placeholder='http://example.com/api_docs/swagger.json' id='input_baseUrl' name='baseUrl' type='text'/></div>
32
-
33
- <div class='input'>
34
- <input class='additional_parameter' data-parameter-key='<%= @authentication_key %>'
35
- data-parameter-type='<%= @authentication_type %>'
36
- placeholder='<%= @authentication_key %>'
37
- type='text'
38
- value='<%= @authentication_value %>'/>
39
- </div>
40
-
41
- <div class='input'><a id='explore' class='header__btn' href='#' data-sw-translate>Explore</a></div>
42
- </div>
43
- <% Swaggard.configuration.additional_parameters.each do |additional_parameter|%>
44
- <div class='input'>
45
- <input class='additional_parameter' data-parameter-key='<%= additional_parameter[:key] %>'
46
- data-parameter-type='<%= additional_parameter[:type] %>'
47
- placeholder='<%= additional_parameter[:key] %>'
48
- type='text'
49
- value='<%= additional_parameter[:value] %>'/>
50
- </div>
51
- <% end %>
52
- <div id='auth_container'></div>
53
- <% end %>
54
- <br>
55
- <br>
56
- </div>
57
- </div>
58
-
59
- <div id='message-bar' class='swagger-ui-wrap' data-sw-translate>&nbsp;</div>
60
- <div id='swagger-ui-container' class='swagger-ui-wrap'></div>
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
- 'swagger' => Swaggard.configuration.swagger_version,
39
- 'info' => {
40
- 'version' => Swaggard.configuration.api_version,
41
- 'title' => Swaggard.configuration.title,
42
- 'description' => Swaggard.configuration.description,
43
- 'termsOfService' => Swaggard.configuration.tos,
44
- 'contact' => contact,
45
- 'license' => license,
46
- },
47
- 'host' => Swaggard.configuration.host,
48
- 'basePath' => Swaggard.configuration.api_base_path,
49
- 'schemes' => Swaggard.configuration.schemes,
50
- 'consumes' => Swaggard.configuration.api_formats.map { |format| "application/#{format}" },
51
- 'produces' => Swaggard.configuration.api_formats.map { |format| "application/#{format}" },
52
- 'tags' => @tags.map { |_, tag| tag.to_doc },
53
- 'paths' => Hash[@paths.values.map { |path| [format_path(path.path), path.to_doc] }],
54
- 'definitions' => Hash[@definitions.merge(Swaggard.configuration.definitions).map { |id, definition| [id, definition.to_doc(@definitions)] }]
55
- }.merge(security_definitions)
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 security_definitions
67
- security_definitions = Swaggard.configuration.security_definitions
72
+ def build_components
73
+ custom_type_schemas = Swaggard.configuration.custom_types
74
+ .transform_keys { |k| Swaggard.ref_name(k) }
68
75
 
69
- return {} if security_definitions.empty? && Swaggard.configuration.security.empty?
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 security_definitions.key?(authentication_type)
86
+ next if security_schemes.key?(authentication_type)
73
87
 
74
- warn "#{authentication_type} not supported by securityDefinitions"
88
+ warn "#{authentication_type} not supported by components/securitySchemes"
75
89
  end
76
90
 
77
- {
78
- 'securityDefinitions' => security_definitions,
79
- 'security' => Swaggard.configuration.security,
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 :swagger_version, :api_base_path, :api_version, :api_formats, :title,
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
@@ -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