jbuilder-schema 1.0.3 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 417f0269fa5ffbf0abc6f290e0d58195f6edcf6962b3b61b1df8f5776b4b11e3
4
- data.tar.gz: f24925cd0c83dc407c40e8fd51a2168128957921f9487350f3bd9131442218ee
3
+ metadata.gz: a69e9ffd441f2e46592aa2e7a533157e8ce1d166a72d331176e98d577311b66c
4
+ data.tar.gz: e0162e1fee77c8288006683f883b2d1b7340781fd3c509f2f24a893de69b1db7
5
5
  SHA512:
6
- metadata.gz: 61a6de749d11754e7997ee0a9162b4228d31d71acf43927fb5001797d563e0cc8b18434df09e419f19501a158f45d22c8f2b86727f1d0b47d79fcd4a7eea80c3
7
- data.tar.gz: 11858924440856da7aa339f3cdb9e7ac8b4b4dfe9342939d202f0048982462c1a83a5c9b62ada301fe09f139c608d88ba9bcabe4635709c9499bfa05a3908246
6
+ metadata.gz: 96dbb87d9ddb9884726787caf2de42d0038c5e55b5b5c1b31859b0b7fa9cc4412e514a9fb4e658126ece93d2f6dfdc9532be6ce6a5b14bdd57148cb74e74951c
7
+ data.tar.gz: 856dd6cd617cc5739960d7afb29184e3a34c84b50b761d1620e1df24d57bc147dd69bfbfd1a8533ae0aa52e05fbf101e4fce810080cdde8a1690fcaccdb7815e
data/Gemfile CHANGED
@@ -7,8 +7,7 @@ gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
9
9
 
10
- gem "factory_bot"
11
- gem "faker"
10
+ gem "sqlite3"
12
11
 
13
12
  gem "standard", "~> 1.3"
14
13
 
data/Gemfile.lock CHANGED
@@ -1,75 +1,74 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jbuilder-schema (1.0.3)
4
+ jbuilder-schema (2.0.1)
5
5
  jbuilder
6
6
  rails (>= 5.0.0)
7
- safe_parser
8
7
 
9
8
  GEM
10
9
  remote: https://rubygems.org/
11
10
  specs:
12
- actioncable (7.0.3.1)
13
- actionpack (= 7.0.3.1)
14
- activesupport (= 7.0.3.1)
11
+ actioncable (7.0.4)
12
+ actionpack (= 7.0.4)
13
+ activesupport (= 7.0.4)
15
14
  nio4r (~> 2.0)
16
15
  websocket-driver (>= 0.6.1)
17
- actionmailbox (7.0.3.1)
18
- actionpack (= 7.0.3.1)
19
- activejob (= 7.0.3.1)
20
- activerecord (= 7.0.3.1)
21
- activestorage (= 7.0.3.1)
22
- activesupport (= 7.0.3.1)
16
+ actionmailbox (7.0.4)
17
+ actionpack (= 7.0.4)
18
+ activejob (= 7.0.4)
19
+ activerecord (= 7.0.4)
20
+ activestorage (= 7.0.4)
21
+ activesupport (= 7.0.4)
23
22
  mail (>= 2.7.1)
24
23
  net-imap
25
24
  net-pop
26
25
  net-smtp
27
- actionmailer (7.0.3.1)
28
- actionpack (= 7.0.3.1)
29
- actionview (= 7.0.3.1)
30
- activejob (= 7.0.3.1)
31
- activesupport (= 7.0.3.1)
26
+ actionmailer (7.0.4)
27
+ actionpack (= 7.0.4)
28
+ actionview (= 7.0.4)
29
+ activejob (= 7.0.4)
30
+ activesupport (= 7.0.4)
32
31
  mail (~> 2.5, >= 2.5.4)
33
32
  net-imap
34
33
  net-pop
35
34
  net-smtp
36
35
  rails-dom-testing (~> 2.0)
37
- actionpack (7.0.3.1)
38
- actionview (= 7.0.3.1)
39
- activesupport (= 7.0.3.1)
36
+ actionpack (7.0.4)
37
+ actionview (= 7.0.4)
38
+ activesupport (= 7.0.4)
40
39
  rack (~> 2.0, >= 2.2.0)
41
40
  rack-test (>= 0.6.3)
42
41
  rails-dom-testing (~> 2.0)
43
42
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
44
- actiontext (7.0.3.1)
45
- actionpack (= 7.0.3.1)
46
- activerecord (= 7.0.3.1)
47
- activestorage (= 7.0.3.1)
48
- activesupport (= 7.0.3.1)
43
+ actiontext (7.0.4)
44
+ actionpack (= 7.0.4)
45
+ activerecord (= 7.0.4)
46
+ activestorage (= 7.0.4)
47
+ activesupport (= 7.0.4)
49
48
  globalid (>= 0.6.0)
50
49
  nokogiri (>= 1.8.5)
51
- actionview (7.0.3.1)
52
- activesupport (= 7.0.3.1)
50
+ actionview (7.0.4)
51
+ activesupport (= 7.0.4)
53
52
  builder (~> 3.1)
54
53
  erubi (~> 1.4)
55
54
  rails-dom-testing (~> 2.0)
56
55
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
57
- activejob (7.0.3.1)
58
- activesupport (= 7.0.3.1)
56
+ activejob (7.0.4)
57
+ activesupport (= 7.0.4)
59
58
  globalid (>= 0.3.6)
60
- activemodel (7.0.3.1)
61
- activesupport (= 7.0.3.1)
62
- activerecord (7.0.3.1)
63
- activemodel (= 7.0.3.1)
64
- activesupport (= 7.0.3.1)
65
- activestorage (7.0.3.1)
66
- actionpack (= 7.0.3.1)
67
- activejob (= 7.0.3.1)
68
- activerecord (= 7.0.3.1)
69
- activesupport (= 7.0.3.1)
59
+ activemodel (7.0.4)
60
+ activesupport (= 7.0.4)
61
+ activerecord (7.0.4)
62
+ activemodel (= 7.0.4)
63
+ activesupport (= 7.0.4)
64
+ activestorage (7.0.4)
65
+ actionpack (= 7.0.4)
66
+ activejob (= 7.0.4)
67
+ activerecord (= 7.0.4)
68
+ activesupport (= 7.0.4)
70
69
  marcel (~> 1.0)
71
70
  mini_mime (>= 1.1.0)
72
- activesupport (7.0.3.1)
71
+ activesupport (7.0.4)
73
72
  concurrent-ruby (~> 1.0, >= 1.0.2)
74
73
  i18n (>= 1.6, < 2)
75
74
  minitest (>= 5.1)
@@ -79,10 +78,6 @@ GEM
79
78
  concurrent-ruby (1.1.10)
80
79
  crass (1.0.6)
81
80
  erubi (1.11.0)
82
- factory_bot (6.2.1)
83
- activesupport (>= 5.0.0)
84
- faker (2.22.0)
85
- i18n (>= 1.8.11, < 2)
86
81
  globalid (1.0.0)
87
82
  activesupport (>= 5.0)
88
83
  i18n (1.12.0)
@@ -100,7 +95,7 @@ GEM
100
95
  method_source (1.0.0)
101
96
  mini_mime (1.1.2)
102
97
  mini_portile2 (2.8.0)
103
- minitest (5.16.2)
98
+ minitest (5.16.3)
104
99
  mocha (1.14.0)
105
100
  net-imap (0.3.1)
106
101
  net-protocol
@@ -108,10 +103,10 @@ GEM
108
103
  net-protocol
109
104
  net-protocol (0.1.3)
110
105
  timeout
111
- net-smtp (0.3.2)
106
+ net-smtp (0.3.3)
112
107
  net-protocol
113
108
  nio4r (2.5.8)
114
- nokogiri (1.13.8)
109
+ nokogiri (1.13.9)
115
110
  mini_portile2 (~> 2.8.0)
116
111
  racc (~> 1.4)
117
112
  parallel (1.22.1)
@@ -121,28 +116,28 @@ GEM
121
116
  rack (2.2.4)
122
117
  rack-test (2.0.2)
123
118
  rack (>= 1.3)
124
- rails (7.0.3.1)
125
- actioncable (= 7.0.3.1)
126
- actionmailbox (= 7.0.3.1)
127
- actionmailer (= 7.0.3.1)
128
- actionpack (= 7.0.3.1)
129
- actiontext (= 7.0.3.1)
130
- actionview (= 7.0.3.1)
131
- activejob (= 7.0.3.1)
132
- activemodel (= 7.0.3.1)
133
- activerecord (= 7.0.3.1)
134
- activestorage (= 7.0.3.1)
135
- activesupport (= 7.0.3.1)
119
+ rails (7.0.4)
120
+ actioncable (= 7.0.4)
121
+ actionmailbox (= 7.0.4)
122
+ actionmailer (= 7.0.4)
123
+ actionpack (= 7.0.4)
124
+ actiontext (= 7.0.4)
125
+ actionview (= 7.0.4)
126
+ activejob (= 7.0.4)
127
+ activemodel (= 7.0.4)
128
+ activerecord (= 7.0.4)
129
+ activestorage (= 7.0.4)
130
+ activesupport (= 7.0.4)
136
131
  bundler (>= 1.15.0)
137
- railties (= 7.0.3.1)
132
+ railties (= 7.0.4)
138
133
  rails-dom-testing (2.0.3)
139
134
  activesupport (>= 4.2.0)
140
135
  nokogiri (>= 1.6)
141
136
  rails-html-sanitizer (1.4.3)
142
137
  loofah (~> 2.3)
143
- railties (7.0.3.1)
144
- actionpack (= 7.0.3.1)
145
- activesupport (= 7.0.3.1)
138
+ railties (7.0.4)
139
+ actionpack (= 7.0.4)
140
+ activesupport (= 7.0.4)
146
141
  method_source
147
142
  rake (>= 12.2)
148
143
  thor (~> 1.0)
@@ -167,11 +162,8 @@ GEM
167
162
  rubocop (>= 1.7.0, < 2.0)
168
163
  rubocop-ast (>= 0.4.0)
169
164
  ruby-progressbar (1.11.0)
170
- ruby_parser (3.8.4)
171
- sexp_processor (~> 4.1)
172
- safe_parser (1.0.0)
173
- ruby_parser (~> 3.8.4)
174
- sexp_processor (4.16.1)
165
+ sqlite3 (1.5.3)
166
+ mini_portile2 (~> 2.8.0)
175
167
  standard (1.14.0)
176
168
  rubocop (= 1.32.0)
177
169
  rubocop-performance (= 1.14.3)
@@ -183,17 +175,16 @@ GEM
183
175
  websocket-driver (0.7.5)
184
176
  websocket-extensions (>= 0.1.0)
185
177
  websocket-extensions (0.1.5)
186
- zeitwerk (2.6.1)
178
+ zeitwerk (2.6.6)
187
179
 
188
180
  PLATFORMS
189
181
  ruby
190
182
 
191
183
  DEPENDENCIES
192
- factory_bot
193
- faker
194
184
  jbuilder-schema!
195
185
  mocha
196
186
  rake (~> 13.0)
187
+ sqlite3
197
188
  standard (~> 1.3)
198
189
 
199
190
  BUNDLED WITH
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # JbuilderSchema
1
+ # Jbuilder::Schema
2
2
 
3
3
  Generate JSON Schema compatible with OpenAPI 3 specs from Jbuilder files
4
4
 
@@ -7,12 +7,12 @@ Generate JSON Schema compatible with OpenAPI 3 specs from Jbuilder files
7
7
 
8
8
  ## Installation
9
9
 
10
- In Gemfile put `gem "jbuilder-schema"` **before** `gem "jbuilder"`:
10
+ In your Gemfile, put `gem "jbuilder-schema"` after Jbuilder:
11
11
 
12
- gem "jbuilder-schema", require: "jbuilder/schema"
13
12
  gem "jbuilder"
13
+ gem "jbuilder-schema"
14
14
 
15
- And then execute:
15
+ And run:
16
16
 
17
17
  $ bundle
18
18
 
@@ -22,114 +22,142 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- Wherever you want to generate schemas, you should extend `JbuilderSchema`:
25
+ Wherever you want to generate schemas, call `Jbuilder::Schema.yaml` or `Jbuilder::Schema.json`:
26
26
 
27
- extend JbuilderSchema
27
+ ```ruby
28
+ Jbuilder::Schema.yaml(@article, title: 'Article', description: 'Article in the blog', locals: { current_user: @user })
29
+ ```
28
30
 
29
- Then you can use `jbuilder_schema` helper:
31
+ Under the hood `Jbuilder::Schema.yaml`/`json` will use Action View's `render` method and support the same arguments.
30
32
 
31
- jbuilder_schema('api/v1/articles/_article',
32
- title: 'Article',
33
- description: 'Article in the blog',
34
- format: :yaml,
35
- paths: view_paths.map(&:path),
36
- model: Article,
37
- locals: {
38
- article: @article,
39
- current_user: @user
40
- })
33
+ So in the above example, the `@article`'s `to_partial_path` path is used to find and render a `articles/_article.json.jbuilder` template, and `article` is available in the partial.
41
34
 
42
- `jbuilder_schema` helper takes `path` to Jbuilder template as a first argument and several optional arguments:
35
+ Additionally, we can pass any needed `locals:`.
43
36
 
44
- - `title` and `description`: Title and description of schema, if not passed then they will be grabbed from locale files (see *[Titles & Descriptions](#titles--descriptions)*);
45
- - `format`: Desired output format, can be either `:yaml` or `:json`. If no `format` option is passed, the output will be the Ruby Hash object;
46
- - `paths`: If you need to scope any other paths than `app/views`, pass them as an array here;
47
- - `model`: Model described in template, this is needed to populate `required` field in schema;
48
- - `locals`: Here you should pass all the locals which are met in the jbuilder template. Those could be any objects as long as they respond to methods called on them in template.
37
+ The `title` and `description` set the title and description of the schema though they can also come from locale files (see *[Titles & Descriptions](#titles--descriptions)*);
49
38
 
50
- Notice that partial templates should be prepended with an underscore just like in the name of the file (i.e. `_article` but not `article` an when using Jbuilder).
39
+ ### Use with a directory within app/views
40
+
41
+ If you have a directory within app/views where your Jbuilder templates are, you can use `renderer` to capture that along with any `locals:` common to the templates you'll render:
42
+
43
+ ```ruby
44
+ jbuilder = Jbuilder::Schema.renderer('app/views/api/v1', locals: { current_user: @user })
45
+ jbuilder.yaml @article, title: 'Article', description: 'Article in the blog'
46
+ ```
47
+
48
+ This means you don't have to write out the partial path, which gets tedious with multiple schema renders:
49
+
50
+ ```ruby
51
+ Jbuilder::Schema.yaml(partial: 'api/v1/articles/article', locals: { article: @article, current_user: @user }, title: 'Article', description: 'Article in the blog')
52
+ ```
53
+
54
+ ### Rendering a template
55
+
56
+ If you're rendering a template like `app/views/articles/index.jbuilder`:
57
+
58
+ ```ruby
59
+ json.articles @articles, :id, :title
60
+ ```
61
+
62
+ You'll need to pass the relative template path in `template:` and any needed instance variables in `assigns:` like so:
63
+
64
+ ```ruby
65
+ Jbuilder::Schema.yaml(template: "articles/index", assigns: { articles: Article.first(3) })
66
+ ```
51
67
 
52
68
  ### Output
53
69
 
54
- JbuilderSchema automatically sets `description`, `type`, and `required` options in JSON-Schema.
70
+ Jbuilder::Schema automatically sets `description`, `type`, and `required` options in JSON-Schema.
55
71
 
56
- For example, if we have `_articles.json.jbilder` file:
72
+ For example, if we have a `_article.json.jbuilder` file:
57
73
 
58
- json.extract! article, :id, :title, :body, :created_at
74
+ ```ruby
75
+ json.extract! article, :id, :title, :body, :created_at
76
+ ```
59
77
 
60
- The output for it will be:
78
+ This will produce the following:
61
79
 
62
- type: object
63
- title: Article
64
- description: Article in the blog
65
- required:
66
- - id
67
- - title
68
- - body
69
- properties:
70
- id:
71
- description: ID of an article
72
- type: integer
73
- title:
74
- description: Title of an article
75
- type: string
76
- body:
77
- description: Contents of an article
78
- type: string
79
- created_at:
80
- description: Timestamp when article was created
81
- type: string
82
- format: date-time
80
+ ```yaml
81
+ type: object
82
+ title: Article
83
+ description: Article in the blog
84
+ required:
85
+ - id
86
+ - title
87
+ - body
88
+ properties:
89
+ id:
90
+ description: ID of an article
91
+ type: integer
92
+ title:
93
+ description: Title of an article
94
+ type: string
95
+ body:
96
+ description: Contents of an article
97
+ type: string
98
+ created_at:
99
+ description: Timestamp when article was created
100
+ type: string
101
+ format: date-time
102
+ ```
83
103
 
84
104
  ### Customization
85
105
 
86
106
  #### Simple
87
107
 
88
- Sometimes you would want to set you own data in generated JSON-Schema. All you need to do is just pass hash with it under `schema` keyword in your jbuilder template:
108
+ To set your own data in the generated JSON-Schema pass a `schema:` hash:
89
109
 
90
- json.id article.id, schema: { type: :number, description: "Custom ID description" }
91
- json.title article.title, schema: { minLength: 5, maxLength: 20 }
92
- json.body article.body, schema: { type: :text, maxLength: 500 }
93
- json.created_at article.created_at.strftime('%d/%m/%Y'), schema: { format: :date, pattern: /^(3[01]|[12][0-9]|0[1-9])\/(1[0-2]|0[1-9])\/[0-9]{4}$/ }
110
+ ```ruby
111
+ json.id article.id, schema: { type: :number, description: "Custom ID description" }
112
+ json.title article.title, schema: { minLength: 5, maxLength: 20 }
113
+ json.body article.body, schema: { type: :text, maxLength: 500 }
114
+ json.created_at article.created_at.strftime('%d/%m/%Y'), schema: { format: :date, pattern: /^(3[01]|[12][0-9]|0[1-9])\/(1[0-2]|0[1-9])\/[0-9]{4}$/ }
115
+ ```
94
116
 
95
117
  This will produce the following:
96
118
 
97
- ...
98
- properties:
99
- id:
100
- description: Custom ID description
101
- type: number
102
- title:
103
- description: Title of an article
104
- type: string
105
- minLength: 5
106
- maxLength: 20
107
- body:
108
- description: Contents of an article
109
- type: string
110
- maxLength: 500
111
- created_at:
112
- description: Timestamp when article was created
113
- type: string
114
- format: date
115
- pattern: "^(3[01]|[12][0-9]|0[1-9])\/(1[0-2]|0[1-9])\/[0-9]{4}$"
119
+ ```yaml
120
+ ...
121
+ properties:
122
+ id:
123
+ description: Custom ID description
124
+ type: number
125
+ title:
126
+ description: Title of an article
127
+ type: string
128
+ minLength: 5
129
+ maxLength: 20
130
+ body:
131
+ description: Contents of an article
132
+ type: string
133
+ maxLength: 500
134
+ created_at:
135
+ description: Timestamp when article was created
136
+ type: string
137
+ format: date
138
+ pattern: "^(3[01]|[12][0-9]|0[1-9])\/(1[0-2]|0[1-9])\/[0-9]{4}$"
139
+ ```
116
140
 
117
141
  #### Bulk
118
142
 
119
143
  You can customize output for multiple fields at once:
120
144
 
121
- json.extract! user, :id, :name, :email, schema: {id: {type: :string}, email: {type: :email, pattern: /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/}}
145
+ ```ruby
146
+ json.extract! user, :id, :name, :email, schema: {id: {type: :string}, email: {type: :email, pattern: /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/}}
147
+ ```
122
148
 
123
149
  ### Nested objects
124
150
 
125
- When you have nested objects in jbuilder template, you have to pass it to `schema: {object: <nested_object>}` when the block starts:
151
+ When you have nested objects in your Jbuilder template, you have to pass it to `schema: {object: <nested_object>}` when the block starts:
126
152
 
127
- json.extract! article
128
- json.author schema: {object: article.user, object_title: "Author", object_description: "Authors are users who write articles"} do
129
- json.extract! article.user
130
- end
153
+ ```ruby
154
+ json.extract! article
155
+ json.author schema: {object: article.user, object_title: "Author", object_description: "Authors are users who write articles"} do
156
+ json.extract! article.user
157
+ end
158
+ ```
131
159
 
132
- This will help JbuilderSchema to process those fields right.
160
+ This will help Jbuilder::Schema to process those fields right.
133
161
 
134
162
  ### Collections
135
163
 
@@ -137,24 +165,28 @@ If an object or an array of objects is generated in template, either in root or
137
165
 
138
166
  For example, if we have:
139
167
 
140
- json.user do
141
- json.partial! 'api/v1/users/user', user: user
142
- end
168
+ ```ruby
169
+ json.user do
170
+ json.partial! 'api/v1/users/user', user: user
171
+ end
143
172
 
144
- json.articles do
145
- json.array! user.articles, partial: "api/v1/articles/article", as: :article
146
- end
173
+ json.articles do
174
+ json.array! user.articles, partial: "api/v1/articles/article", as: :article
175
+ end
176
+ ```
147
177
 
148
178
  The result would be:
149
179
 
150
- user:
151
- type: object
152
- $ref: #/components/schemas/user
153
- articles:
154
- type: array
155
- items:
156
- $ref: #/components/schemas/article
157
-
180
+ ```yaml
181
+ user:
182
+ type: object
183
+ $ref: #/components/schemas/user
184
+ articles:
185
+ type: array
186
+ items:
187
+ $ref: #/components/schemas/article
188
+ ```
189
+
158
190
  The path to component schemas can be configured with `components_path` variable, which defaults to `components/schemas`. See *[Configuration](#configuration)* for more info.
159
191
 
160
192
  ### Titles & Descriptions
@@ -163,63 +195,57 @@ Custom titles and descriptions for objects can be specified when calling `jbuild
163
195
 
164
196
  Titles and descriptions for the models are supposed to be found in locale files under `<underscored_plural_model_name>.<title_name>` and `<underscored_plural_model_name>.<description_name>`, for example:
165
197
 
166
- en:
167
- articles:
168
- title: Article
169
- description: The main object on the blog
198
+ ```yaml
199
+ en:
200
+ articles:
201
+ title: Article
202
+ description: The main object on the blog
203
+ ```
170
204
 
171
205
  Descriptions for the fields are supposed to be found in locale files under `<underscored_plural_model_name>.fields.<field_name>.<description_name>`, for example:
172
206
 
173
- en:
174
- articles:
175
- fields:
176
- title:
177
- description: The title of an article
207
+ ```yaml
208
+ en:
209
+ articles:
210
+ fields:
211
+ title:
212
+ description: The title of an article
213
+ ```
178
214
 
179
215
  `<title_name>` and `<description_name>` can be configured (see *[Configuration](#configuration)*), it defaults to `title` and `description`.
180
216
 
181
217
  ### Configuration
182
218
 
183
- You can configure some variables that JbuilderSchema uses (for example, in `config/initializers/jbuilder_schema.rb`):
219
+ You can configure some variables that Jbuilder::Schema uses (for example, in `config/initializers/jbuilder_schema.rb`):
184
220
 
185
- JbuilderSchema.configure do |config|
186
- config.components_path = "components/schemas" # could be "definitions/schemas"
187
- config.title_name = "title" # could be "label"
188
- config.description_name = "description" # could be "heading"
189
- end
221
+ ```ruby
222
+ Jbuilder::Schema.configure do |config|
223
+ config.components_path = "components/schemas" # could be "definitions/schemas"
224
+ config.title_name = "title" # could be "label"
225
+ config.description_name = "description" # could be "heading"
226
+ end
227
+ ```
190
228
 
191
229
  ### RSwag
192
230
 
193
- It's super easy to use JbuilderSchema with RSwag: just add `jbuilder_schema` helper in `swagger_helper.rb` like this:
194
-
195
- RSpec.configure do |config|
196
- extend JbuilderSchema
197
-
198
- ...
199
-
200
- config.swagger_docs = {
201
-
202
- ...
203
-
204
- components: {
205
- schemas: {
206
- article: jbuilder_schema('api/v1/articles/_article',
207
- format: :yaml,
208
- model: Article,
209
- title: 'Article',
210
- description: 'Article in the blog',
211
- locals: {
212
- article: FactoryBot.build(:article, id: 1),
213
- current_user: FactoryBot.build(:user, admin: true)
214
- })
215
- }
216
- }
217
-
218
- ...
219
-
231
+ You can use the `yaml`/`json` methods in your `swagger_helper.rb` like this:
232
+
233
+ ```ruby
234
+ RSpec.configure do |config|
235
+ config.swagger_docs = {
236
+ components: {
237
+ schemas: {
238
+ article: Jbuilder::Schema.yaml(FactoryBot.build(:article, id: 1),
239
+ title: 'Article',
240
+ description: 'Article in the blog',
241
+ locals: {
242
+ current_user: FactoryBot.build(:user, admin: true)
243
+ })
220
244
  }
221
-
222
- ...
245
+ }
246
+ }
247
+ end
248
+ ```
223
249
 
224
250
  ## Contributing
225
251