jbuilder-schema 1.0.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -2
- data/Gemfile.lock +61 -70
- data/README.md +164 -138
- data/lib/jbuilder/schema/renderer.rb +36 -55
- data/lib/jbuilder/schema/template.rb +113 -155
- data/lib/jbuilder/schema/version.rb +4 -5
- data/lib/jbuilder/schema.rb +26 -8
- metadata +3 -22
- data/lib/jbuilder/jbuilder.rb +0 -23
- data/lib/jbuilder/schema/builder.rb +0 -79
- data/lib/jbuilder/schema/configuration.rb +0 -29
- data/lib/jbuilder/schema/resolver.rb +0 -39
- data/sig/jbuilder/schema.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59f54a84c849a2b5575b89b9cfd959976d2fdd61224ccb12aad01a1bb2acfa2c
|
4
|
+
data.tar.gz: a927e3272a2dee69f3ead47da2d47470e99ff911a54cbde13f807f9ba32036ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 035745d04230e753d8df7a1811c139b9ab5b49eb7c3d7606485a086208c0150c9b4123ecc52d3f69a41432af497dc3973cd70db3f0b722e5162c0147f84a3289
|
7
|
+
data.tar.gz: 20f2caceef04841ce35529b00bfac43a7aa29518102626a76f5d61763a72b0dffa04756f80fe2167592a7e91534c0e65efb17e315bd57aa117d43f80751eb018
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,75 +1,74 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
jbuilder-schema (
|
4
|
+
jbuilder-schema (2.0.0)
|
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.
|
13
|
-
actionpack (= 7.0.
|
14
|
-
activesupport (= 7.0.
|
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.
|
18
|
-
actionpack (= 7.0.
|
19
|
-
activejob (= 7.0.
|
20
|
-
activerecord (= 7.0.
|
21
|
-
activestorage (= 7.0.
|
22
|
-
activesupport (= 7.0.
|
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.
|
28
|
-
actionpack (= 7.0.
|
29
|
-
actionview (= 7.0.
|
30
|
-
activejob (= 7.0.
|
31
|
-
activesupport (= 7.0.
|
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.
|
38
|
-
actionview (= 7.0.
|
39
|
-
activesupport (= 7.0.
|
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.
|
45
|
-
actionpack (= 7.0.
|
46
|
-
activerecord (= 7.0.
|
47
|
-
activestorage (= 7.0.
|
48
|
-
activesupport (= 7.0.
|
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.
|
52
|
-
activesupport (= 7.0.
|
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.
|
58
|
-
activesupport (= 7.0.
|
56
|
+
activejob (7.0.4)
|
57
|
+
activesupport (= 7.0.4)
|
59
58
|
globalid (>= 0.3.6)
|
60
|
-
activemodel (7.0.
|
61
|
-
activesupport (= 7.0.
|
62
|
-
activerecord (7.0.
|
63
|
-
activemodel (= 7.0.
|
64
|
-
activesupport (= 7.0.
|
65
|
-
activestorage (7.0.
|
66
|
-
actionpack (= 7.0.
|
67
|
-
activejob (= 7.0.
|
68
|
-
activerecord (= 7.0.
|
69
|
-
activesupport (= 7.0.
|
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.
|
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.
|
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.
|
106
|
+
net-smtp (0.3.3)
|
112
107
|
net-protocol
|
113
108
|
nio4r (2.5.8)
|
114
|
-
nokogiri (1.13.
|
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.
|
125
|
-
actioncable (= 7.0.
|
126
|
-
actionmailbox (= 7.0.
|
127
|
-
actionmailer (= 7.0.
|
128
|
-
actionpack (= 7.0.
|
129
|
-
actiontext (= 7.0.
|
130
|
-
actionview (= 7.0.
|
131
|
-
activejob (= 7.0.
|
132
|
-
activemodel (= 7.0.
|
133
|
-
activerecord (= 7.0.
|
134
|
-
activestorage (= 7.0.
|
135
|
-
activesupport (= 7.0.
|
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.
|
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.
|
144
|
-
actionpack (= 7.0.
|
145
|
-
activesupport (= 7.0.
|
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
|
-
|
171
|
-
|
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.
|
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
|
-
#
|
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"`
|
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
|
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,
|
25
|
+
Wherever you want to generate schemas, call `Jbuilder::Schema.yaml` or `Jbuilder::Schema.json`:
|
26
26
|
|
27
|
-
|
27
|
+
```ruby
|
28
|
+
Jbuilder::Schema.yaml(@article, title: 'Article', description: 'Article in the blog', locals: { current_user: @user })
|
29
|
+
```
|
28
30
|
|
29
|
-
|
31
|
+
Under the hood `Jbuilder::Schema.yaml`/`json` will use Action View's `render` method and support the same arguments.
|
30
32
|
|
31
|
-
|
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
|
-
|
35
|
+
Additionally, we can pass any needed `locals:`.
|
43
36
|
|
44
|
-
|
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
|
-
|
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
|
-
|
70
|
+
Jbuilder::Schema automatically sets `description`, `type`, and `required` options in JSON-Schema.
|
55
71
|
|
56
|
-
For example, if we have `
|
72
|
+
For example, if we have a `_article.json.jbuilder` file:
|
57
73
|
|
58
|
-
|
74
|
+
```ruby
|
75
|
+
json.extract! article, :id, :title, :body, :created_at
|
76
|
+
```
|
59
77
|
|
60
|
-
|
78
|
+
This will produce the following:
|
61
79
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
108
|
+
To set your own data in the generated JSON-Schema pass a `schema:` hash:
|
89
109
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
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
|
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
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
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
|
-
|
141
|
-
|
142
|
-
|
168
|
+
```ruby
|
169
|
+
json.user do
|
170
|
+
json.partial! 'api/v1/users/user', user: user
|
171
|
+
end
|
143
172
|
|
144
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
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
|
219
|
+
You can configure some variables that Jbuilder::Schema uses (for example, in `config/initializers/jbuilder_schema.rb`):
|
184
220
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
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
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
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
|
|