zero-rails_openapi 1.3.2 → 1.3.3

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
  SHA1:
3
- metadata.gz: 996bf583a71a6c1b34daa068d9fad89761fd8074
4
- data.tar.gz: 97858fcf27fdf3bf491e28d8fcba9b5061cebf7c
3
+ metadata.gz: 5b5be5f5f85b9f720f9fafaa70ba037879c336e0
4
+ data.tar.gz: fc93ab5059ff2ff594e080e51cb349a9a1ffd64c
5
5
  SHA512:
6
- metadata.gz: a46294ecd676e965ac1c4b0c3f7e0944751feae640882872d06f7ff52547b1c5b4bc4b71311d5a6b75fa98c66f18c2eb4832c7d2fc70b05c846cdae3456ec170
7
- data.tar.gz: 16d36540905bee8b7f242dfadab8cc6f5edeffb83f88b936fc4da8ee6d2941fe0c206030781c8ae8121eed9a6e459dc5a8387b691b19491716a995ca1b1788a8
6
+ metadata.gz: f0f37a9cb0e11cb4850819e6ed443c6f6b2386ec0f2b47878eb16b1a375e2c50fb8c6b0a2cea3446010eb3b07bc7d709f6aa74b0773d23e88962c3037222e734
7
+ data.tar.gz: 0db4a7fdc0f13cb55b654ff1362d39a67c399ab5f8ffa0e40eabad9c3f4776042a77c2ac189af281de0208d274d441276c10aeb7fc2b4e486753cc2f0780cae0
data/Gemfile CHANGED
@@ -4,5 +4,3 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in zero-rails_openapi.gemspec
6
6
  gemspec
7
-
8
- gem 'activesupport'
data/Gemfile.lock CHANGED
@@ -1,21 +1,98 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zero-rails_openapi (1.3.2)
4
+ zero-rails_openapi (1.3.3)
5
+ activesupport (>= 3)
6
+ rails (>= 3)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
8
10
  specs:
11
+ actioncable (5.1.4)
12
+ actionpack (= 5.1.4)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.1.4)
16
+ actionpack (= 5.1.4)
17
+ actionview (= 5.1.4)
18
+ activejob (= 5.1.4)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.1.4)
22
+ actionview (= 5.1.4)
23
+ activesupport (= 5.1.4)
24
+ rack (~> 2.0)
25
+ rack-test (>= 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.1.4)
29
+ activesupport (= 5.1.4)
30
+ builder (~> 3.1)
31
+ erubi (~> 1.4)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
+ activejob (5.1.4)
35
+ activesupport (= 5.1.4)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.1.4)
38
+ activesupport (= 5.1.4)
39
+ activerecord (5.1.4)
40
+ activemodel (= 5.1.4)
41
+ activesupport (= 5.1.4)
42
+ arel (~> 8.0)
9
43
  activesupport (5.1.4)
10
44
  concurrent-ruby (~> 1.0, >= 1.0.2)
11
45
  i18n (~> 0.7)
12
46
  minitest (~> 5.1)
13
47
  tzinfo (~> 1.1)
48
+ arel (8.0.0)
49
+ builder (3.2.3)
14
50
  concurrent-ruby (1.0.5)
51
+ crass (1.0.2)
15
52
  diff-lcs (1.3)
16
- i18n (0.9.0)
53
+ erubi (1.7.0)
54
+ globalid (0.4.1)
55
+ activesupport (>= 4.2.0)
56
+ i18n (0.9.1)
17
57
  concurrent-ruby (~> 1.0)
58
+ loofah (2.1.1)
59
+ crass (~> 1.0.2)
60
+ nokogiri (>= 1.5.9)
61
+ mail (2.7.0)
62
+ mini_mime (>= 0.1.1)
63
+ method_source (0.9.0)
64
+ mini_mime (0.1.4)
65
+ mini_portile2 (2.3.0)
18
66
  minitest (5.10.3)
67
+ nio4r (2.1.0)
68
+ nokogiri (1.8.1)
69
+ mini_portile2 (~> 2.3.0)
70
+ rack (2.0.3)
71
+ rack-test (0.7.0)
72
+ rack (>= 1.0, < 3)
73
+ rails (5.1.4)
74
+ actioncable (= 5.1.4)
75
+ actionmailer (= 5.1.4)
76
+ actionpack (= 5.1.4)
77
+ actionview (= 5.1.4)
78
+ activejob (= 5.1.4)
79
+ activemodel (= 5.1.4)
80
+ activerecord (= 5.1.4)
81
+ activesupport (= 5.1.4)
82
+ bundler (>= 1.3.0)
83
+ railties (= 5.1.4)
84
+ sprockets-rails (>= 2.0.0)
85
+ rails-dom-testing (2.0.3)
86
+ activesupport (>= 4.2.0)
87
+ nokogiri (>= 1.6)
88
+ rails-html-sanitizer (1.0.3)
89
+ loofah (~> 2.0)
90
+ railties (5.1.4)
91
+ actionpack (= 5.1.4)
92
+ activesupport (= 5.1.4)
93
+ method_source
94
+ rake (>= 0.8.7)
95
+ thor (>= 0.18.1, < 2.0)
19
96
  rake (10.5.0)
20
97
  rspec (3.6.0)
21
98
  rspec-core (~> 3.6.0)
@@ -30,15 +107,25 @@ GEM
30
107
  diff-lcs (>= 1.2.0, < 2.0)
31
108
  rspec-support (~> 3.6.0)
32
109
  rspec-support (3.6.0)
110
+ sprockets (3.7.1)
111
+ concurrent-ruby (~> 1.0)
112
+ rack (> 1, < 3)
113
+ sprockets-rails (3.2.1)
114
+ actionpack (>= 4.0)
115
+ activesupport (>= 4.0)
116
+ sprockets (>= 3.0.0)
117
+ thor (0.20.0)
33
118
  thread_safe (0.3.6)
34
119
  tzinfo (1.2.4)
35
120
  thread_safe (~> 0.1)
121
+ websocket-driver (0.6.5)
122
+ websocket-extensions (>= 0.1.0)
123
+ websocket-extensions (0.1.2)
36
124
 
37
125
  PLATFORMS
38
126
  ruby
39
127
 
40
128
  DEPENDENCIES
41
- activesupport
42
129
  bundler (~> 1.16.a)
43
130
  rake (~> 10.0)
44
131
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,30 +1,29 @@
1
- # ZRO: OpenApi 3 DocGenerator for Rails
1
+ # ZRO: OpenApi 3 JSON-Doc Generator for Rails
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/zero-rails_openapi.svg)](https://badge.fury.io/rb/zero-rails_openapi)
4
- [![Build Status](https://travis-ci.org/zhandao/zero-rails_openapi.svg?branch=master)](https://travis-ci.org/zhandao/zero-rails_openapi)
5
-
6
- Provide concise DSL for generating the OpenAPI Specification 3 (**OAS3**, formerly Swagger3) documentation JSON file for Rails application,
7
- then you can use Swagger UI 3.2.0+ to show the documentation.
3
+ [![Gem Version](https://badge.fury.io/rb/zero-rails_openapi.svg)](https://badge.fury.io/rb/zero-rails_openapi)
4
+ [![Build Status](https://travis-ci.org/zhandao/zero-rails_openapi.svg?branch=master)](https://travis-ci.org/zhandao/zero-rails_openapi)
5
+
6
+ Provide concise DSL for generating the OpenAPI Specification 3 (**OAS3**, formerly Swagger3) documentation JSON file for Rails application,
7
+ then you can use Swagger UI 3.2.0+ to show the documentation.
8
8
 
9
9
  ## Contributing
10
10
 
11
- **Hi, here is ZhanDao. This gem was completed when I learned Ruby less than three months,
12
- I'm not sure if it has problem, but it may have a lot to improve.
13
- I'm looking forward to your issues and PRs, thanks!**
14
-
15
- Currently, I think the most important TODO is the Unit Test (RSpec, I want is),
16
- but I dont have enough time now = ▽ =
11
+ **Hi, here is ZhanDao. This gem was completed when I learned Ruby less than three months,
12
+ I'm not sure if it has problem, but it may have a lot to improve.
13
+ I'm looking forward to your issues and PRs, thanks!**
14
+
15
+ Currently, I think the most important TODO is the Unit Test (RSpec, I want is),
16
+ but I dont have enough time now = ▽ =
17
17
 
18
18
  ## Table of Contents
19
19
 
20
20
  - [About OAS](#about-oas) (OpenAPI Specification)
21
21
  - [Installation](#installation)
22
22
  - [Configure](#configure)
23
- - [Usage](#usage)
24
- - [DSL for documenting your controller](#dsl-for-documenting-your-controller)
25
- - [Generate JSON documentation file](#generate-json-documentation-file)
26
- - [Use Swagger UI(very beautiful web page) to show your Documentation](#use-swagger-uivery-beautiful-web-page-to-show-your-documentation)
27
- - [Tricks](#tricks)
23
+ - [Usage - DSL](#usage---dsl)
24
+ - [Usage - Generate JSON documentation file](#usage---generate-json-documentation-file)
25
+ - [Usage - Use Swagger UI(very beautiful web page) to show your Documentation](#usage---use-swagger-uivery-beautiful-web-page-to-show-your-documentation)
26
+ - [Tricks](#tricks)
28
27
  - [Write DSL somewhere else](#trick1---write-the-dsl-somewhere-else)
29
28
  - [Global DRYing](#trick2---global-drying)
30
29
  - [Auto generate description](#trick3---auto-generate-description)
@@ -34,310 +33,352 @@ but I dont have enough time now = ▽ =
34
33
 
35
34
  ## About OAS
36
35
 
37
- Everything about OAS3 is on [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md)
38
-
39
- You can getting started from [swagger.io](https://swagger.io/docs/specification/basic-structure/)
40
-
41
- **I suggest you should understand OAS3's basic structure at least.**
42
- such as component (can help you reuse DSL code, when your apis are used with the
43
- same data structure).
36
+ Everything about OAS3 is on [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md)
37
+
38
+ You can getting started from [swagger.io](https://swagger.io/docs/specification/basic-structure/)
39
+
40
+ **I suggest you should understand OAS3's basic structure at least.**
41
+ such as component (can help you reuse DSL code, when your apis are used with the
42
+ same data structure).
44
43
 
45
44
  ## Installation
46
45
 
47
- Add this line to your Rails's Gemfile:
48
-
49
- ```ruby
50
- gem 'zero-rails_openapi'
51
- ```
52
-
53
- And then execute:
54
-
55
- $ bundle
56
-
57
- Or install it yourself as:
58
-
59
- $ gem install zero-rails_openapi
46
+ Add this line to your Rails's Gemfile:
47
+
48
+ ```ruby
49
+ gem 'zero-rails_openapi'
50
+ # or
51
+ gem 'zero-rails_openapi', github: 'zhandao/zero-rails_openapi'
52
+ ```
53
+
54
+ And then execute:
55
+
56
+ $ bundle
57
+
58
+ Or install it yourself as:
59
+
60
+ $ gem install zero-rails_openapi
60
61
 
61
62
  ## Configure
62
63
 
63
- Create an initializer, configure ZRO and define your APIs.
64
-
65
- This is the simplest configuration example:
66
-
67
- ```ruby
68
- # config/initializers/open_api.rb
69
- require 'open_api'
70
-
71
- OpenApi::Config.tap do |c|
72
- # [REQUIRED] The output location where .json doc file will be written to.
73
- c.file_output_path = 'public/open_api'
74
-
75
- c.register_docs = {
76
- homepage_api: {
77
- # [REQUIRED] ZRO will scan all the descendants of root_controller, then generate their docs.
78
- root_controller: Api::V1::BaseController,
79
-
80
- # [REQUIRED] OAS Info Object: The section contains API information.
81
- info: {
82
- # [REQUIRED] The title of the application.
83
- title: 'Rails APIs',
84
- # Description of the application.
85
- description: 'API documentation of Rails Application. <br/>' \
86
- 'Optional multiline or single-line Markdown-formatted description ' \
87
- 'in [CommonMark](http://spec.commonmark.org/) or `HTML`.',
88
- # [REQUIRED] The version of the OpenAPI document
89
- # (which is distinct from the OAS version or the API implementation version).
90
- version: '1.0.0'
91
- }
92
- }
93
- }
94
- end
95
- ```
96
- You can also set the *global configuration(/component)* of OAS:
97
- Server Object / Security Scheme Object / Security Requirement Object ...
98
-
99
- For more detailed configuration: [open_api.rb](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/open_api.rb)
100
-
101
- ## Usage
102
-
103
- ### DSL for documenting your controller
104
-
105
- #### \> First of all, extend DSL for your base controller, for example:
106
-
107
- ```ruby
108
- # application_controller.rb
109
- class ApplicationController < ActionController::API
110
- include OpenApi::DSL
111
- end
112
- ```
113
-
114
- #### \> [DSL Usage Example](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/examples_controller.rb)
115
-
116
- (TODO: I consider that, here should be put in a the simplest case.)
117
- ```ruby
118
- class Api::V1::ExamplesController < Api::V1::BaseController
119
- apis_tag name: 'ExampleTagName', desc: 'ExamplesController\'s APIs'
64
+ Create an initializer, configure ZRO and define your APIs.
120
65
 
121
- components do
122
- schema :Dog => [ String, must_be: 'doge' ]
123
- query! :QueryCompUuid => [ :product_uuid, String, desc: 'product uuid' ]
124
- path! :PathCompId => [ :id, Integer, desc: 'user id' ]
125
- resp :RespComp => [ 'bad request', :json ]
126
- body! :RqBodyComp => [ :form ]
66
+ This is the simplest configuration example:
67
+
68
+ ```ruby
69
+ # config/initializers/open_api.rb
70
+ require 'open_api'
71
+
72
+ OpenApi::Config.tap do |c|
73
+ # [REQUIRED] The output location where .json doc file will be written to.
74
+ c.file_output_path = 'public/open_api'
75
+
76
+ c.register_docs = {
77
+ homepage_api: {
78
+ # [REQUIRED] ZRO will scan all the descendants of root_controller, then generate their docs.
79
+ root_controller: Api::V1::BaseController,
80
+
81
+ # [REQUIRED] OAS Info Object: The section contains API information.
82
+ info: {
83
+ # [REQUIRED] The title of the application.
84
+ title: 'Homepage APIs',
85
+ # Description of the application.
86
+ description: 'API documentation of Rails Application. <br/>' \
87
+ 'Optional multiline or single-line Markdown-formatted description ' \
88
+ 'in [CommonMark](http://spec.commonmark.org/) or `HTML`.',
89
+ # [REQUIRED] The version of the OpenAPI document
90
+ # (which is distinct from the OAS version or the API implementation version).
91
+ version: '1.0.0'
92
+ }
93
+ }
94
+ }
127
95
  end
128
-
129
- api_dry %i[index show], 'common response' do
130
- response '567', 'query result export', :pdf, type: File
96
+ ```
97
+ The following global configuration and component of OAS are allow to be set in the initializer:
98
+ Server Object / Security Scheme Object / Security Requirement Object ...
99
+
100
+ In addition to direct use of Hash, you can also use Config DSL to configure:
101
+
102
+ ```ruby
103
+ # config/initializers/open_api.rb
104
+ require 'open_api'
105
+
106
+ OpenApi::Config.tap do |c|
107
+ c.instance_eval do
108
+ api :homepage_api, root_controller: ApiDoc
109
+ info version: '1.0.0', title: 'Homepage APIs'
110
+ end
131
111
  end
112
+ ```
113
+
114
+ For more detailed configuration: [open_api.rb](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/open_api.rb)
115
+ See all the settings you can configure: [config.rb](https://github.com/zhandao/zero-rails_openapi/blob/master/lib/open_api/config.rb)
132
116
 
133
- open_api :index, '(SUMMARY) this api blah blah ...', :builder_template1 do
134
- this_api_is_invalid! 'this api is expired!'
135
- desc 'Optional multiline or single-line Markdown-formatted description',
136
- id: 'user id',
137
- email_addr: 'email_addr\'s desc'
138
- email = 'git@github.com'
139
-
140
- query! :id, Integer, enum: 0..5, length: [1, 2], pattern: /^[0-9]$/, range: {gt:0, le:5}
141
- query! :done, Boolean, must_be: false, default: true, desc: 'must be false'
142
- query :email_addr, String, lth: :ge_3, default: email # is_a: :email
143
- # form! 'form', type: { id!: Integer, name: String }
144
- file :pdf, 'desc: the media type is application/pdf'
145
-
146
- response :success, 'success response', :json, type: :Dog
147
-
148
- security :ApiKeyAuth
149
- end
117
+ ## Usage - DSL
150
118
 
151
- open_api :show do
152
- param_ref :PathCompId, :QueryCompUuid
153
- response_ref '123' => :RespComp, '223' => :RespComp
119
+ ### First of all, include DSL to your base controller (which is for writing docs), for example:
120
+
121
+ ```ruby
122
+ # app/controllers/api/api_controller.rb
123
+ class ApiController < ActionController::API
124
+ include OpenApi::DSL
154
125
  end
155
- end
126
+ ```
156
127
 
157
- ```
128
+ ### DSL Usage Example
158
129
 
159
- #### \> Explanation
130
+ Here is the simplest usage:
131
+
132
+ ```ruby
133
+ class Api::V1::ExamplesController < Api::V1::BaseController
134
+ open_api :index, 'GET list' do
135
+ query :page, Integer#, desc: 'page, greater than 1', range: { ge: 1 }, dft: 1
136
+ query :rows, Integer#, desc: 'per page', range: { ge: 1 }, default: 10
137
+ end
138
+ end
139
+ ```
140
+
141
+ For more example, see [goods_doc.rb](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/goods_doc.rb), and
142
+ [examples_controller.rb](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/examples_controller.rb)
160
143
 
161
- #### \>\> controller class methods ([source code](https://github.com/zhandao/zero-rails_openapi/blob/master/lib/open_api/dsl.rb))
144
+ ### DSL methods of controller ([source code](https://github.com/zhandao/zero-rails_openapi/blob/master/lib/open_api/dsl.rb))
162
145
 
163
- - `ctrl_path` (controller path) [Optional]
146
+ #### (1) `ctrl_path` (controller path) [optional]
164
147
 
165
148
  ```ruby
166
149
  # method signature
167
- ctrl_path path
150
+ ctrl_path(path)
168
151
  # usage
169
152
  ctrl_path 'api/v1/examples'
170
153
  ```
171
- This option allows you to set the Tag* (which is a node of [OpenApi Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#openapi-object)).
154
+ It is optional because `ctrl_path` defaults to `controller_path`.
155
+
172
156
  [Here's a trick](#trick1---write-the-dsl-somewhere-else): Using `ctrl_path`, you can write the DSL somewhere else
173
157
  to simplify the current controller.
174
- \* take the tag from `path.split('/').last`
175
158
 
176
- - `apis_tag` [Optional]
159
+ #### (2) `apis_tag` [optional]
177
160
 
178
161
  ```ruby
179
162
  # method signature
180
- apis_tag name: nil, desc: '', external_doc_url: ''
163
+ apis_tag(name: nil, desc: '', external_doc_url: '')
181
164
  # usage
182
165
  apis_tag name: 'ExampleTagName', desc: 'ExamplesController\'s APIs'
183
166
  ```
184
- desc and external_doc_url will be output to the tags[the current tag] (tag defaults to controller_name ), but are optional.
167
+ This method allows you to set the Tag (which is a node of [OpenApi Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#openapi-object)).
168
+
169
+ desc and external_doc_url will be output to the tags[the current tag] (tag defaults to controller_name), but are optional.
185
170
 
186
- - `components` [Optional]
171
+ #### (3) `components` [optional]
187
172
 
188
173
  ```ruby
189
174
  # method signature
190
- components &block
175
+ components(&block)
191
176
  # usage
192
177
  components do
193
178
  # DSL for defining components
194
- schema :Dog => [ String, dft: { id: 1, name: 'pet' } ]
179
+ schema :DogSchema => [ { id: Integer, name: String }, dft: { id: 1, name: 'pet' } ]
180
+ query! :UidQuery => [ :uid, String, desc: 'uid' ]
181
+ resp :BadRqResp => [ 'bad request', :json ]
182
+ end
183
+
184
+ # to use component
185
+ open_api :action, 'summary' do
186
+ query :doge, :DogSchema # to use a Schema component
187
+ param_ref :UidQuery # to use a Parameter component
188
+ response_ref :BadRqResp # to use a Response component
195
189
  end
196
190
  ```
197
- Component can be used to simplify your DSL code in `*_ref` methods.
198
- Each RefObj you define is associated with components through component key.
191
+ Component can be used to simplify your DSL code (by using `*_ref` methods).
192
+
193
+ Each RefObj you defined is associated with components through component key.
194
+ We suggest that component keys should be camelized symbol.
199
195
 
200
- - `api_dry` [Optional]
196
+ #### (4) `api_dry` [optional]
201
197
 
202
- this method is for DRYing.
198
+ This method is for DRYing.
203
199
 
204
200
  ```ruby
205
201
  # method signature
206
- api_dry method = :all, desc = '', &block
202
+ api_dry(action = :all, desc = '', &block)
207
203
  # usage
208
- api_dry :all, 'common response' do; end
209
- api_dry :index do; end
210
- api_dry [:index, :show] do; end
204
+ api_dry :all, 'common response' # block ...
205
+ api_dry :index # block ...
206
+ api_dry [:index, :show] do
207
+ query! #...
208
+ end
211
209
  ```
212
210
 
213
- As you think, the DSL methods in the block will be executed to each API that you set by method.
211
+ As you think, the block will be executed to each specified API(action) **firstly**.
214
212
 
215
- - `open_api` [Required]
213
+ #### (5) `open_api` [required]
216
214
 
217
- Define the specified API (in the following example is index).
215
+ Define the specified API (controller action, in the following example is index).
218
216
 
219
217
  ```ruby
220
218
  # method signature
221
- open_api method, summary = '', builder: nil, skip: [ ], use: [ ], &block
219
+ open_api(action, summary = '', builder: nil, skip: [ ], use: [ ], &block)
222
220
  # usage
223
- open_api :index, '(SUMMARY) this api blah blah ...', builder: :template1 do end
221
+ open_api :index, '(SUMMARY) this api blah blah ...', builder: :index # block ...
222
+ ```
223
+ If you pass `builder`, and `generate_jbuilder_file` is set to `true` (in your initializer),
224
+ ZRO will generate JBuilder file by using specified template called `index`.
225
+ About template settings, see: [open_api.rb](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/open_api.rb)
226
+
227
+ `use` and `skip` options: to use or skip the parameters defined in `api_dry`.
228
+
229
+ ```ruby
230
+ open_api :show, 'summary', use: [:id] # => it will only take :id from DRYed result.
224
231
  ```
225
- If pass `builder` to the third parameter,
226
- and `generate_jbuilder_file` is set `true` in your initializer file,
227
- ZRO will generate JBuilder file by using specified template that you set
228
- `template1` in your setting file.
229
- You can see: [open_api.rb](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/open_api.rb)
230
-
231
-
232
- #### \>\> DSL methods inside *open_api* and *api_dry*'s block ([source code](https://github.com/zhandao/zero-rails_openapi/blob/master/lib/open_api/dsl_inside_block.rb):: ApiInfoObj)
233
232
 
234
- These methods in the block describe the specified API(s): description, valid?,
235
- parameters, request body, responses, securities, servers.
233
+ ### DSL methods inside [open_api]() and [api_dry]()'s block
236
234
 
237
- (Here corresponds to OAS [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#operationObject))
235
+ [source code](https://github.com/zhandao/zero-rails_openapi/blob/master/lib/open_api/dsl_inside_block.rb), ApiInfoObj
236
+
237
+ These following methods in the block describe the specified API action: description, valid?,
238
+ parameters, request body, responses, securities, servers.
239
+
240
+ (Here corresponds to OAS [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#operationObject))
238
241
 
239
- - `this_api_is_invalid!`, its aliases are:
240
- - `this_api_is_expired!`
241
- - `this_api_is_unused!`
242
- - `this_api_is_under_repair!`
242
+ #### (1) `this_api_is_invalid!`, its aliases:
243
+ ```
244
+ this_api_is_expired!
245
+ this_api_is_unused!
246
+ this_api_is_under_repair!
247
+ ```
243
248
 
244
249
  ```ruby
245
250
  # method signature
246
- this_api_is_invalid! explain = ''
251
+ this_api_is_invalid!(explain = '')
247
252
  # usage
248
253
  this_api_is_invalid! 'this api is expired!'
249
254
  ```
255
+
256
+ Then `deprecated` of this API will be set to true.
250
257
 
251
- - `desc`: description for current API and its inputs (parameters and request body)
258
+ #### (2) `desc`: description for the current API and its inputs (parameters and request body)
252
259
 
253
260
  ```ruby
254
261
  # method signature
255
- desc desc, param_descs = { }
262
+ desc(desc, param_descs = { })
256
263
  # usage
257
264
  desc 'current API\'s description',
258
- id: 'user id',
259
- email_addr: 'email_addr\'s desc'
265
+ id: 'desc of the parameter :id',
266
+ email: 'desc of the parameter :email'
260
267
  ```
261
268
 
262
- You can of course describe the input in it's DSL method (like `query! :done` [this line](https://github.com/zhandao/zero-rails_openapi#-dsl-usage-example)),
269
+ You can of course describe the input in it's DSL method (like `query! :done ...`, [this line](https://github.com/zhandao/zero-rails_openapi#-dsl-usage-example)),
263
270
  but that will make it long and ugly. We recommend that unite descriptions in this place.
264
271
 
265
272
  In addition, when you want to dry the same parameters (each with a different description), it will be of great use.
266
273
 
267
- - param family methods (OAS - [Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#parameterObject))
268
- - `param`
269
- - `param_ref`
270
- - `header`, `path`, `query`, `cookie` and bang methods: `header!`, `path!`, `query!`, `cookie!`
271
- - `do_* by: { }`
272
- **The bang method(`!`) means it is required, so without `!` means it is optional. the same below.**
274
+ #### (3) `param` family methods (OAS - [Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#parameterObject))
273
275
 
274
- Define the parameters for the API(operation).
275
- You can use the Reference Object to link to parameters that are defined at the components/parameters by method param_ref().
276
+ Define the parameters for the API (action).
277
+ ```
278
+ param
279
+ param_ref # for reuse component,
280
+ # it links sepcified RefObjs (by component keys) to current parameters.
281
+ header, path, query, cookie # will pass specified parameter location to `param`
282
+ header!, path!, query!, cookie! # bang method of above methods
283
+ do_* by: { parameter_definations } # batch definition parameters, such as do_path, do_query
284
+ order # order parameters by names array you passed
285
+ examples # define examples of parameters
286
+ ```
287
+ **The bang method (which's name is end of a exclamation point `!`) means this param is required, so without `!` means optional.**
288
+ **THE SAME BELOW.**
276
289
 
277
290
  ```ruby
291
+ # `param_type` just is the location of parameter, like: query, path
292
+ # `schema_type` is the type of parameter, like: String, Integer (must be a constant)
293
+ # For more explanation, please click the link below ↓↓↓
278
294
  # method signature
279
- param param_type, name, type, required, schema_hash = { }
295
+ param(param_type, param_name, schema_type, is_required, schema_hash = { })
280
296
  # usage
281
- param :query, :page, Integer, :req, range: { gt: 0, le: 5 }, desc: 'page',
282
- examples: { :example => 5 }
297
+ param :query, :page, Integer, :req, range: { gt: 0, le: 5 }, desc: 'page'
298
+
283
299
 
284
300
  # method signature
285
- param_ref component_key, *component_keys
301
+ param_ref(component_key, *component_keys) # should pass at least 1 key
286
302
  # usage
287
- param_ref :PathCompId
288
- param_ref :PathCompId, :QueryComp#, ...
303
+ param_ref :IdPath
304
+ param_ref :IdPath, :NameQuery, :TokenHeader
305
+
289
306
 
290
307
  # method signature
291
- header name, type, schema_hash = { }
292
- header! name, type, schema_hash = { }
293
- query! name, type, schema_hash = { }
308
+ header(param_name, schema_type, schema_hash = { })
309
+ header!(param_name, schema_type, schema_hash = { })
310
+ query!(param_name, schema_type, schema_hash = { })
294
311
  # usage
295
312
  header! 'Token', String
296
- query! :read, Boolean, must_be: true, default: false
313
+ query! :readed, Boolean, must_be: true, default: false
314
+ # The same effect as above, but not simple
315
+ param :query, :readed, Boolean, :req, must_be: true, default: false
316
+
297
317
 
298
318
  # method signature
299
- do_query by:
319
+ do_query(by:)
300
320
  # usage
301
321
  do_query by: {
302
- :search_type => { type: String },
303
- :export! => { type: Boolean }
322
+ search_type: String,
323
+ search_val: String,
324
+ export!: Boolean
304
325
  }
305
- # Same as below, but a little more succinctly
326
+ # The same effect as above, but a little bit repetitive
306
327
  query :search_type, String
328
+ query :search_val, String
307
329
  query! :export, Boolean
330
+
331
+
332
+ # method signature
333
+ # `exp_by` (select_example_by): choose the example fields.
334
+ examples(exp_by = :all, examples_hash)
335
+ # usage
336
+ # it defines 2 examples by using parameter :id and :name
337
+ # if pass :all to `exp_by`, keys will be all the parameter's names.
338
+ examples [:id, :name], {
339
+ :right_input => [ 1, 'user'], # == { id: 1, name: 'user' }
340
+ :wrong_input => [ -1, '' ]
341
+ }
308
342
  ```
309
343
 
310
- [**>> More About Param DSL <<**](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/parameter.md)
344
+ [**>> More About `param` DSL <<**](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/parameter.md)
311
345
 
312
- - request_body family methods (OAS - [Request Body Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#requestBodyObject))
313
- - `request_body`
314
- - `body_ref`
315
- - `body` and bang `body!`
316
- - `form`, `form!`; `file`, `file!`
317
-
318
- OpenAPI 3.0 uses the requestBody keyword to distinguish the payload from parameters.
319
- Define the request body for the API(operation).
320
- You can use the Reference Object to link to request body that is defined at the components/requestBodies by method body_ref().
346
+ #### (4) `request_body` family methods (OAS - [Request Body Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#requestBodyObject))
347
+
348
+ OpenAPI 3.0 uses the requestBody keyword to distinguish the payload from parameters.
349
+ ```
350
+ request_body
351
+ body_ref # for reuse component,
352
+ # it links sepcified RefObjs (by component keys) to current body.
353
+ body, body! # alias of request_body
354
+ form, form! # define a multipart/form-data body
355
+ file, file! # define a File media-type body
356
+ ```
321
357
 
322
358
  ```ruby
323
359
  # method signature
324
- request_body required, media_type, desc = '', hash = { }
360
+ request_body(is_required, media_type, desc = '', schema_hash = { })
325
361
  # usage
326
- request_body :opt, :form, type: { id!: Integer, name: String }
362
+ request_body :opt, :form, '', type: { id!: Integer, name: String }
363
+ # or
364
+ request_body :opt, :form, '', data: { id!: Integer, name: String }
365
+
327
366
 
328
367
  # method signature
329
- body_ref component_key
368
+ body_ref(component_key)
330
369
  # usage
331
- body_ref :Body
370
+ body_ref :UpdateDogeBody
371
+
332
372
 
333
373
  # method signature
334
- body! media_type, desc = '', hash = { }
374
+ body!(media_type, desc = '', schema_hash = { })
335
375
  # usage
336
376
  body :json
337
377
 
378
+
338
379
  # method implement
339
- def form desc = '', hash = { }
340
- body :form, desc, hash
380
+ def form desc = '', schema_hash = { }
381
+ body :form, desc, schema_hash
341
382
  end
342
383
  # usage
343
384
  form! 'register', data: {
@@ -347,197 +388,208 @@ parameters, request body, responses, securities, servers.
347
388
  }
348
389
  # advance usage
349
390
  form 'for creating a user', data: {
350
- :name! => { type: String, desc: 'user name' },
391
+ :name! => { type: String, desc: 'user name' },
351
392
  :password! => { type: String, pattern: /[0-9]{6,10}/, desc: 'password' },
352
393
  # optional
353
- :remarks => { type: String, desc: 'remarks' },
354
- }
394
+ :remarks => { type: String, desc: 'remarks' },
395
+ }, exp_by: %i[ name password ],
396
+ examples: { # ↓ ↓
397
+ :right_input => [ 'user1', '123456' ],
398
+ :wrong_input => [ 'user2', 'abc' ]
399
+ }
355
400
 
356
- # method implement
357
- def file! media_type, desc = '', hash = { type: File }
358
- body! media_type, desc, hash
401
+
402
+ # about `file`
403
+ def file! media_type, desc = '', schema_hash = { type: File }
404
+ body! media_type, desc, schema_hash
359
405
  end
360
406
  ```
361
407
 
362
- (1) **Notice:** Each API can only declare a request body.
363
- That is, all of the above methods you can only choose one of them.
364
- (2) Media Type: We provide some [mapping](https://github.com/zhandao/zero-rails_openapi/blob/master/lib/oas_objs/media_type_obj.rb) from symbols to real media-types.
365
- (3) schema_hash: As above (see param), it's just one more a `type` (schema type).
366
- (4) `examples` usage see [goods_doc](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/goods_doc.rb)
408
+ 1. **Notice:** Each API should only declare a request body
409
+ That is, all of the above methods you can only choose one of them.
410
+ (But **multiple media types** will be supported in the future).
411
+ 2. `media_type`: we provide some [mapping](https://github.com/zhandao/zero-rails_openapi/blob/master/lib/oas_objs/media_type_obj.rb) from symbols to real media-types.
412
+ 3. `schema_hash`: as above (see param).
413
+ **One thing that should be noted is: when use Hash writing, `scham_type` is writed in schema_hash using key :type.**
414
+ 4. `exp_by` and `examples`: for the above example, the following has the same effect:
415
+ ```
416
+ examples: {
417
+ :right_input => { name: 'user1', password: '123456' },
418
+ :wrong_input => { name: 'user2', password: 'abc' }
419
+ }
420
+ ```
367
421
 
368
- - response family methods (OAS - [Response Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#response-object))
369
- - `response` (`resp`)
370
- - `response_ref`
371
- - `default_response` (`dft_resp`)
372
- - `error_response` (`other_response`, `oth_resp`, `error`, `err_resp`): Are `response`'s aliases, should be used in the error response context.
373
- - `override_response` # TODO
422
+ #### (5) `response` family methods (OAS - [Response Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#response-object))
374
423
 
375
- Define the responses for the API(operation).
376
- You can use the Response Object to link to request body that is defined at the components/responses by method response_ref().
424
+ Define the responses for the API (action).
425
+ ```
426
+ response or resp
427
+ response_ref
428
+ default_response or dft_resp
429
+ error_response, other_response, oth_resp, error, err_resp # response's aliases, should be used in the error response context.
430
+ ```
377
431
 
378
432
  ```ruby
379
433
  # method signature
380
- response code, desc, media_type = nil, hash = { }
434
+ response(response_code, desc, media_type = nil, schema_hash = { })
381
435
  # usage
382
- response 200, 'query result export', :pdf, type: File
436
+ response 200, 'query result', :pdf, type: File
383
437
 
384
438
  # method signature
385
- response_ref code_compkey_hash
439
+ response_ref(code_compkey_hash)
386
440
  # usage
387
- response_ref 700 => :RespComp, 800 => :RespComp
441
+ response_ref 700 => :AResp, 800 => :BResp
388
442
  ```
389
443
 
390
- (1) **practice:** Combined with wrong class, automatically generate error responses. TODO
391
- (2) `examples` usage see [goods_doc](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/goods_doc.rb)
444
+ **practice:** Combined with wrong class, automatically generate error responses. [AutoGenDoc](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/auto_gen_doc.rb#L63)
392
445
 
393
- - security: TODO
446
+ #### (6) `security`: TODO
394
447
 
395
- - server: TODO
448
+ #### (7) `server`: TODO
396
449
 
397
- #### \>\> DSL methods inside components'block ([code source](https://github.com/zhandao/zero-rails_openapi/blob/master/lib/open_api/dsl_inside_block.rb):: CtrlInfoObj )
450
+ ### DSL methods inside [components]()'block ([code source](https://github.com/zhandao/zero-rails_openapi/blob/master/lib/open_api/dsl_inside_block.rb):: CtrlInfoObj )
398
451
 
399
- (Here corresponds to OAS [Components Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#componentsObject))
400
-
401
- These methods in the block describe the current controller,
402
- in other words, these methods eventually produce reusable components.
403
-
404
- So, the following methods are used as above, except that you need to
405
- name the key of the component, and pass it as the first of argument list, like:
406
-
407
- ```ruby
408
- query! :QueryCompUuid, :product_uuid, Integer, ...
409
- ```
410
- This writing is feasible but not recommended,
411
- because component's key and parameter's name looks like the same level.
412
- The recommended writing is:
452
+ (Here corresponds to OAS [Components Object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#componentsObject))
453
+
454
+ These methods in the block describe reusable components that you wanna use to define
455
+ parameter, response, request body and schema.
413
456
 
414
- ```ruby
415
- query! :QueryCompUuid => [:product_uuid, Integer, ...]
416
- ```
417
- The DSL methods used to generate the components in this block are:
457
+ ```ruby
458
+ query! :UidQuery, :uid, String
459
+ ```
460
+ This writing is feasible but not recommended,
461
+ because component's key and parameter's name looks like the same level.
462
+ The recommended writing is:
418
463
 
419
- - param family methods (except `param_ref`) (explained above)
420
- - request_body family methods (except `body_ref`) (explained above)
421
- - schema: define Schema Object component.
464
+ ```ruby
465
+ query! :UidQuery => [:uid, String]
466
+ ```
422
467
 
423
468
  ```ruby
424
469
  # method signature
425
- schema component_key, type, schema_hash
470
+ schema(component_key, type, schema_hash)
426
471
  # usage
427
- schema :Dog => [ { id!: Integer, name: String }, dft: { id: 1, name: 'pet' } ]
472
+ schema :Dog => [ String, desc: 'dogee' ]
428
473
  # advance usage
429
474
  schema :Dog => [{
430
475
  id!: Integer,
431
- name: { type: String, must_be: 'zhandao', desc: 'name' }
432
- }, # this is schema type*
433
- dft: { id: 1, name: 'pet' }]
476
+ name: { type: String, must_be: 'name', desc: 'name' }
477
+ }, # <= this hash is schema type[1]
478
+ dft: { id: 1, name: 'pet' },
479
+ desc: 'dogee']
434
480
  # or (unrecommended)
435
- schema :Dog, { id!: Integer, name: String }, dft: { id: 1, name: 'pet' }
481
+ schema :Dog, { id!: Integer, name: String }, dft: { id: 1, name: 'pet' }, desc: 'dogee'
436
482
  ```
437
- *: see: [Type](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/parameter.md#type)
438
-
439
- ### Generate JSON Documentation File
440
-
441
- Initializer or Console, run:
483
+ [1] see: [Type](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/parameter.md#type)
442
484
 
443
- ```ruby
444
- OpenApi.write_docs
445
- ```
485
+ ## Usage - Generate JSON Documentation File
446
486
 
447
- Then the JSON files will be written to the directory you set. (Each API a file.)
448
-
449
- ### Use Swagger UI(very beautiful web page) to show your Documentation
450
-
451
- Download [Swagger UI](https://github.com/swagger-api/swagger-ui) (version >= 2.3.0 support the OAS3)
452
- to your project,
453
- modify the default JSON file path(url) in the index.html
454
- (window.onload >> SwaggerUIBundle >> url).
455
- In order to use it, you may have to enable CORS, [see](https://github.com/swagger-api/swagger-ui#cors-support)
456
-
457
- ### Tricks
458
-
459
- #### Trick1 - Write the DSL Somewhere Else
487
+ Use `OpenApi.write_docs`:
488
+
489
+ ```ruby
490
+ # initializer
491
+ OpenApi.write_docs generate_files: !Rails.env.production?
492
+
493
+ # or run directly in console
494
+ OpenApi.write_docs
495
+ ```
496
+
497
+ Then the JSON files will be written to the directories you set. (Each API a file.)
460
498
 
461
- Does your documentation take too many lines?
462
- Do you want to separate documentation from business controller to simplify both?
463
- Very easy! Just use `ctrl_path`.
499
+ ## Usage - Use Swagger UI(very beautiful web page) to show your Documentation
464
500
 
465
- ```ruby
466
- # config/initializers/open_api.rb
467
- # in your configure
468
- root_controller: BaseDoc
501
+ Download [Swagger UI](https://github.com/swagger-api/swagger-ui) (version >= 2.3.0 support the OAS3)
502
+ to your project,
503
+ modify the default JSON file path(url) in the index.html
504
+ (window.onload >> SwaggerUIBundle >> url).
505
+ In order to use it, you may have to enable CORS, [see](https://github.com/swagger-api/swagger-ui#cors-support)
469
506
 
470
- # app/api_doc/base_doc.rb
471
- require 'open_api/dsl'
507
+ ## Tricks
472
508
 
473
- class BaseDoc < Object
474
- include OpenApi::DSL
475
- end
509
+ ### Trick1 - Write the DSL Somewhere Else
476
510
 
477
- # app/api_doc/v1/examples_doc.rb
478
- class V1::ExamplesDoc < BaseDoc
479
- ctrl_path 'api/v1/examples'
511
+ Does your documentation take too many lines?
512
+ Do you want to separate documentation from business controller to simplify both?
513
+ Very easy! Just follow
514
+
515
+ ```ruby
516
+ # config/initializers/open_api.rb
517
+ # in your configuration
518
+ root_controller: ApiDoc
480
519
 
481
- open_api :index do
482
- # ...
520
+ # app/api_doc/api_doc.rb
521
+ require 'open_api/dsl'
522
+
523
+ class ApiDoc < Object
524
+ include OpenApi::DSL
483
525
  end
484
- end
485
- ```
486
-
487
- Notes: convention is the file name ends with `_doc.rb`
488
-
489
- #### Trick2 - Global DRYing
490
-
491
- Method `api_dry` is for DRY but its scope is limited to the current controller.
492
-
493
- I have no idea of best practices, But you can look at this [file](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/auto_gen_doc.rb).
494
- The implementation of the file is: do `api_dry` when inherits the base controller inside `inherited` method.
495
-
496
- #### Trick3 - Auto Generate Description
497
-
498
- ```ruby
499
- desc 'api desc',
500
- search_type!: 'search field, allows:<br/>'
501
- query :search_type, String, enum: %w[name creator category price]
502
-
503
- # or
504
-
505
- query :search_type, String, desc!: 'search field, allows:<br/>',
506
- enum: %w[name creator category price]
507
- ```
508
-
509
- Notice `!` use (`search_type!`, `desc!`), it tells ZRO to append
510
- information that analyzed from definitions (enum, must_be ..) to description automatically.
526
+
527
+ # app/api_doc/v1/examples_doc.rb
528
+ class V1::ExamplesDoc < ApiDoc
529
+ ctrl_path 'api/v1/examples'
530
+
531
+ open_api :index do
532
+ # ...
533
+ end
534
+ end
535
+ ```
536
+
537
+ Notes: convention is the file name ends with `_doc.rb`
511
538
 
512
- Any one of above will generate:
513
- > search field, allows:<br/>1/ name<br/>2/ creator,<br/>3/ category<br/>4/ price<br/>
539
+ ### Trick2 - Global DRYing
514
540
 
515
- ZRO also allows you use Hash to define `enum`:
516
- ```ruby
517
- query :view, String, enum: {
518
- 'all goods (default)': :all,
519
- 'only online': :online,
520
- 'only offline': :offline,
521
- 'expensive goods': :get,
522
- 'cheap goods': :borrow,
523
- }
524
- ```
525
- Read this [file](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/auto_gen_desc.rb) to learn more.
541
+ Method `api_dry` is for DRY but its scope is limited to the current controller.
542
+
543
+ I have no idea of best practices, But you can look at this [file](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/auto_gen_doc.rb).
544
+ The implementation of the file is: do `api_dry` when inherits the base controller inside `inherited` method.
545
+
546
+ You can use `sort` to specify the order of parameters.
526
547
 
527
- #### Trick4 - Skip or Use parameters define in api_dry
548
+ ### Trick3 - Auto Generate Description
528
549
 
529
- Pass `skip: []` and `use: []` to `open_api` like following code:
530
- ```ruby
531
- open_api :index, 'desc', builder: :index, skip: [ :Token ]
532
- ```
550
+ ```ruby
551
+ desc 'api desc',
552
+ search_type!: 'search field, allows:<br/>'
553
+ query :search_type, String, enum: %w[name creator category price]
554
+
555
+ # or
556
+
557
+ query :search_type, String, desc!: 'search field, allows:<br/>',
558
+ enum: %w[name creator category price]
559
+ ```
560
+
561
+ Notice `!` use (`search_type!`, `desc!`), it tells ZRO to append
562
+ information that analyzed from definitions (enum, must_be ..) to description automatically.
563
+
564
+ Any one of above will generate:
565
+ > search field, allows:<br/>1/ name<br/>2/ creator,<br/>3/ category<br/>4/ price<br/>
566
+
567
+ You can also use Hash to define `enum`:
568
+ ```ruby
569
+ query :view, String, desc: 'allows values<br/>', enum: {
570
+ 'all goods (default)': :all,
571
+ 'only online': :online,
572
+ 'only offline': :offline,
573
+ 'expensive goods': :get,
574
+ 'cheap goods': :borrow,
575
+ }
576
+ ```
577
+ Read this [file](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/auto_gen_desc.rb) to learn more.
533
578
 
534
- Look at this [file](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/goods_doc.rb) to learn more.
579
+ ### Trick4 - Skip or Use parameters define in api_dry
535
580
 
536
- #### Trick5 - Auto Generate index/show Actions's Response-Types Based on DB Schema
581
+ Pass `skip: []` and `use: []` to `open_api` like following code:
582
+ ```ruby
583
+ open_api :index, 'desc', builder: :index, skip: [ :Token ]
584
+ ```
585
+
586
+ Look at this [file](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/goods_doc.rb) to learn more.
537
587
 
538
- Use method `load_schema` in `api_dry`.
588
+ ### Trick5 - Auto Generate index/show Actions's Response-Types Based on DB Schema
539
589
 
540
- See this [file](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/auto_gen_doc.rb#L51) for uasge information.
590
+ Use method `load_schema` in `api_dry`.
591
+
592
+ See this [file](https://github.com/zhandao/zero-rails_openapi/blob/master/documentation/examples/auto_gen_doc.rb#L51) for uasge information.
541
593
 
542
594
 
543
595
  ## Troubleshooting
@@ -547,14 +599,14 @@ See this [file](https://github.com/zhandao/zero-rails_openapi/blob/master/docume
547
599
 
548
600
  ## Development
549
601
 
550
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
551
-
552
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
602
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
603
+
604
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
553
605
 
554
606
  ## License
555
607
 
556
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
608
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
557
609
 
558
610
  ## Code of Conduct
559
611
 
560
- Everyone interacting in the Zero-OpenApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/zhandao/zero-rails_openapi/blob/master/CODE_OF_CONDUCT.md).
612
+ Everyone interacting in the Zero-OpenApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/zhandao/zero-rails_openapi/blob/master/CODE_OF_CONDUCT.md).