@@ -30,40 +30,35 @@ def components &block
30
30
current_ctrl . _process_objs
31
31
end
32
32
33
- def open_api action , summary = '' , builder : nil , skip : [ ] , use : [ ] , &block
33
+ def open_api action , summary = '' , http : nil , builder : nil , skip : [ ] , use : [ ] , &block
34
34
apis_tag if @_ctrl_infos . nil?
35
-
36
35
# select the routing info (corresponding to the current method) from routing list.
37
36
action_path = "#{ @_ctrl_path ||= controller_path } ##{ action } "
38
- routes_info = ctrl_routes_list &.select { |api | api [ :action_path ] . match? /^#{ action_path } $/ } &.first
37
+ routes_info = ctrl_routes_list &.select { |api | api [ :action_path ] . match? ( /^#{ action_path } $/ ) } &.first
39
38
pp "[ZRO Warning] Routing mapping failed: #{ @_ctrl_path } ##{ action } " and return if routes_info . nil?
40
- Generator . generate_builder_file ( action_path , builder ) if builder . present?
39
+ Generator . generate_builder_file ( action_path , builder )
41
40
42
- # structural { #path: { #http_method:{ } } }, for pushing into Paths Object.
43
- path = ( @_api_infos ||= { } ) [ routes_info [ :path ] ] ||= { }
44
- current_api = path [ routes_info [ :http_verb ] ] =
45
- ApiInfoObj . new ( action_path , skip : Array ( skip ) , use : Array ( use ) )
46
- . merge! description : '' , summary : summary , operationId : action , tags : [ @_apis_tag ] ,
47
- parameters : [ ] , requestBody : '' , responses : { } , security : [ ] , servers : [ ]
41
+ api = ApiInfoObj . new ( action_path , skip : Array ( skip ) , use : Array ( use ) )
42
+ . merge! description : '' , summary : summary , operationId : action , tags : [ @_apis_tag ] ,
43
+ parameters : [ ] , requestBody : '' , responses : { } , security : [ ] , servers : [ ]
44
+ [ action , :all ] . each { |blk_key | @_api_dry_blocks &.[]( blk_key ) &.each { |blk | api . instance_eval ( &blk ) } }
45
+ api . param_use = [ ] # `skip` and `use` only affect `api_dry`'s blocks
46
+ api . instance_eval ( &block ) if block_given?
47
+ api . _process_objs
48
+ api . delete_if { |_ , v | v . blank? }
48
49
49
- current_api . tap do |api |
50
- [ action , :all ] . each do |key | # blocks_store_key
51
- @_apis_blocks &.[]( key ) &.each { |blk | api . instance_eval ( &blk ) }
52
- end
53
- api . param_use = [ ] # skip 和 use 是对 dry 块而言的
54
- api . instance_eval ( &block ) if block_given?
55
- api . _process_objs
56
- api . delete_if { |_ , v | v . blank? }
57
- end
50
+ path = ( @_api_infos ||= { } ) [ routes_info [ :path ] ] ||= { }
51
+ http_verbs = ( http || routes_info [ :http_verb ] ) . split ( '|' )
52
+ http_verbs . each { |verb | path [ verb ] = api }
58
53
end
59
54
60
55
# method could be symbol array, like: %i[ .. ]
61
56
def api_dry action = :all , desc = '' , &block
62
- @_apis_blocks ||= { }
57
+ @_api_dry_blocks ||= { }
63
58
if action . is_a? Array
64
- action . each { |m | ( @_apis_blocks [ m . to_sym ] ||= [ ] ) << block }
59
+ action . each { |m | ( @_api_dry_blocks [ m . to_sym ] ||= [ ] ) << block }
65
60
else
66
- ( @_apis_blocks [ action . to_sym ] ||= [ ] ) << block
61
+ ( @_api_dry_blocks [ action . to_sym ] ||= [ ] ) << block
67
62
end
68
63
end
69
64
0 commit comments