Skip to content

Commit f8e07d5

Browse files
authored
Merge pull request #35 from zhandao/v2
2 parents fea981b + 2e60868 commit f8e07d5

38 files changed

+894
-1359
lines changed

README.md

Lines changed: 404 additions & 434 deletions
Large diffs are not rendered by default.

README_zh.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,11 @@
359359

360360

361361
# method signature
362-
# `exp_by` (select_example_by): choose the example fields.
363-
examples(exp_by = :all, examples_hash)
362+
# `exp_params` (select_example_by): choose the example fields.
363+
examples(exp_params = :all, examples_hash)
364364
# usage
365365
# it defines 2 examples by using parameter :id and :name
366-
# if pass :all to `exp_by`, keys will be all the parameter's names.
366+
# if pass :all to `exp_params`, keys will be all the parameter's names.
367367
examples [:id, :name], {
368368
:right_input => [ 1, 'user'], # == { id: 1, name: 'user' }
369369
:wrong_input => [ -1, '' ]
@@ -425,7 +425,7 @@
425425
:password! => { type: String, pattern: /[0-9]{6,10}/, desc: 'password' },
426426
# optional
427427
:remarks => { type: String, desc: 'remarks' },
428-
}, exp_by: %i[ name password ],
428+
}, exp_params: %i[ name password ],
429429
examples: { # ↓ ↓
430430
:right_input => [ 'user1', '123456' ],
431431
:wrong_input => [ 'user2', 'abc' ]
@@ -448,7 +448,7 @@
448448

449449
1. `media_type`: we provide some [mapping](lib/oas_objs/media_type_obj.rb) from symbols to real media-types.
450450
2. `schema_info`: as above (see param).
451-
3. `exp_by` and `examples`: for the above example, the following has the same effect:
451+
3. `exp_params` and `examples`: for the above example, the following has the same effect:
452452
```
453453
examples: {
454454
:right_input => { name: 'user1', password: '123456' },

documentation/examples/auto_gen_desc.rb

Lines changed: 0 additions & 29 deletions
This file was deleted.

documentation/examples/examples_controller.rb

Lines changed: 0 additions & 60 deletions
This file was deleted.

documentation/examples/goods_doc.rb

Lines changed: 0 additions & 52 deletions
This file was deleted.

documentation/parameter.md

Lines changed: 0 additions & 69 deletions
This file was deleted.
File renamed without changes.

documentation/examples/open_api.rb renamed to examples/open_api.rb

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
require 'open_api'
22

3-
OpenApi::Config.tap do |c|
3+
OpenApi::Config.class_eval do
44
# Config DSL
5-
c.instance_eval do
6-
open_api :zero_rails, base_doc_classes: [ApiDoc]
7-
info version: '0.0.1', title: 'Zero Rails APIs', description: 'API documentation of Zero-Rails Application.'
8-
server 'http://localhost:3000', desc: 'Main (production) server'
9-
server 'http://localhost:3000', desc: 'Internal staging server for testing'
10-
bearer_auth :Token
11-
global_auth :Token
12-
end
5+
open_api :zero_rails, base_doc_classes: [ApiDoc]
6+
info version: '0.0.1', title: 'Zero Rails APIs', description: 'API documentation of Zero-Rails Application.'
7+
server 'http://localhost:3000', desc: 'Main (production) server'
8+
server 'http://localhost:3000', desc: 'Internal staging server for testing'
9+
bearer_auth :Token
10+
global_auth :Token
1311

1412
# [REQUIRED] The location where .json doc file will be output.
15-
c.file_output_path = 'public/open_api'
13+
self.file_output_path = 'public/open_api'
1614

1715
# [Optional] Use this txt instead of running `rails routes`.
18-
# c.rails_routes_file = 'config/routes.txt'
16+
# self.rails_routes_file = 'config/routes.txt'
1917

2018
# Everything about OAS3 is on https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md
2119
# Getting started: https://swagger.io/docs/specification/basic-structure/
22-
c.open_api_docs = {
20+
self.open_api_docs = {
2321
blog_api: {
2422
# [REQUIRED] ZRO will scan all the descendants of the base_doc_classes, then generate their docs.
2523
base_doc_classes: [ApiController],
@@ -96,9 +94,7 @@
9694

9795
end
9896

99-
Object.const_set('Boolean', 'boolean') # Support `Boolean` writing in DSL
100-
101-
OpenApi.write_docs generate_files: !Rails.env.production?
97+
OpenApi.write_docs if: !Rails.env.production?
10298

10399

104100
__END__

lib/oas_objs/callback_obj.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,22 @@ def initialize(event_name, http_method, callback_url, &block)
1919

2020
def process
2121
{
22-
self.event_name => {
22+
event_name => {
2323
processed_url => {
24-
self.http_method.downcase.to_sym => processed_block
24+
http_method.downcase.to_sym => Api.new.run_dsl(&(self.block || -> { }))
2525
}
2626
}
2727
}
2828
end
2929

3030
def processed_url
31-
self.callback_url.gsub(/{[^{}]*}/) do |exp|
31+
callback_url.gsub(/{[^{}]*}/) do |exp|
3232
key_location, key_name = exp[1..-2].split
3333
connector = key_location == 'body' ? '#/' : '.'
3434
key_location = '$request.' + key_location
3535
['{', key_location, connector, key_name, '}'].join
3636
end
3737
end
38-
39-
def processed_block
40-
api = Api.new.merge! parameters: [ ], requestBody: '', responses: { }
41-
api.instance_exec(&(self.block || -> { }))
42-
api.process_objs
43-
api.delete_if { |_, v| v.blank? }
44-
end
4538
end
4639
end
4740
end

0 commit comments

Comments
 (0)