Skip to content

Commit 0578f60

Browse files
committed
1.3.2 release!
1. Fix some bugs. 2. Sort the output.
1 parent 0654931 commit 0578f60

File tree

9 files changed

+32
-36
lines changed

9 files changed

+32
-36
lines changed

CODE_OF_CONDUCT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
5555
## Enforcement
5656

5757
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58-
reported by contacting the project team at [email protected]. All
58+
reported by contacting the project team at zhandao. All
5959
complaints will be reviewed and investigated and will result in a response that
6060
is deemed necessary and appropriate to the circumstances. The project team is
6161
obligated to maintain confidentiality with regard to the reporter of an incident.

Gemfile

-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
55
# Specify your gem's dependencies in zero-rails_openapi.gemspec
66
gemspec
77

8-
ruby '>= 2.3.0'
9-
108
gem 'activesupport'

Gemfile.lock

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
zero-rails_openapi (1.3.1)
4+
zero-rails_openapi (1.3.2)
55

66
GEM
77
remote: https://rubygems.org/
@@ -44,8 +44,5 @@ DEPENDENCIES
4444
rspec (~> 3.0)
4545
zero-rails_openapi!
4646

47-
RUBY VERSION
48-
ruby 2.4.1p111
49-
5047
BUNDLED WITH
51-
1.16.0.pre.2
48+
1.16.0

documentation/examples/goods_doc.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class V2::GoodsDoc < BaseDoc
3434
:is_online => { type: Boolean, desc: 'it\'s online?' },
3535
:remarks => { type: String, desc: 'remarks' },
3636
:pic_path => { type: String, desc: 'picture url', is: :url },
37-
}, exp_by: %i[ name category_id price ],
37+
},
38+
exp_by: %i[ name category_id price ],
3839
examples: {
3940
:right_input => [ 'good1', 6, 5.7 ],
4041
:wrong_input => [ 'good2', 0, -1 ]

lib/oas_objs/helpers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def assign(value)
1717
end
1818

1919
# reduceee.then_merge! => for Hash
20-
def reduceee(*values)
20+
def reducx(*values)
2121
@assign = values.compact.reduce({ }, :merge).keep_if &value_present
2222
self
2323
end

lib/oas_objs/schema_obj.rb

+18-21
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,19 @@ def process_for(param_name = nil, options = { desc_inside: false })
2828
return processed if @preprocessed
2929

3030
processed.merge! processed_type
31-
reduceee processed_enum_and_length,
32-
processed_range,
33-
processed_is_and_format(param_name),
34-
{
35-
pattern: _pattern&.inspect&.delete('/'),
36-
default: _default,
37-
as: _as,
38-
permit: _permit,
39-
not_permit: _npermit,
40-
examples: self[:examples].present? ? ExampleObj.new(self[:examples]).process : nil
41-
}
31+
reducx processed_enum_and_length,
32+
processed_range,
33+
processed_is_and_format(param_name),
34+
{
35+
pattern: _pattern&.inspect&.delete('/'),
36+
default: '_default',
37+
examples: self[:examples].present? ? ExampleObj.new(self[:examples], self[:exp_by]).process : nil,
38+
},
39+
{ as: _as, permit: _permit, not_permit: _npermit, req_if: _req_if, opt_if: _opt_if }
4240
then_merge!
41+
processed[:default] = _default unless _default.nil?
4342

44-
reduceee(processed_desc options).then_merge!
43+
reducx(processed_desc options).then_merge!
4544
end
4645

4746
alias process process_for
@@ -154,16 +153,12 @@ def processed_enum_and_length
154153

155154
# generate length range fields by _lth array
156155
lth = _length || [ ]
157-
if self[:type] == 'array'
158-
{
159-
minItems: lth.is_a?(Array) ? lth.first : nil,
160-
maxItems: lth.is_a?(Array) ? lth.last : nil
161-
}
156+
max = lth.is_a?(Array) ? lth.first : ("#{lth}".match?('ge') ? "#{lth}".split('_').last.to_i : nil)
157+
min = lth.is_a?(Array) ? lth.last : ("#{lth}".match?('le') ? "#{lth}".split('_').last.to_i : nil)
158+
if processed[:type] == 'array'
159+
{ minItems: max, maxItems: min }
162160
else
163-
{
164-
minLength: lth.is_a?(Array) ? lth.first : ("#{lth}".match?('ge') ? "#{lth}".split('_').last.to_i : nil),
165-
maxLength: lth.is_a?(Array) ? lth.last : ("#{lth}".match?('le') ? "#{lth}".split('_').last.to_i : nil)
166-
}
161+
{ minLength: max, maxLength: min }
167162
end.merge!(enum: _enum).keep_if &value_present
168163
end
169164

@@ -209,6 +204,8 @@ def recognize_is_options_in(name)
209204
_as: %i[ as to for map mapping ], # NOT OAS Spec, it's for zero-params_processor
210205
_permit: %i[ permit pmt ], # NOT OAS Spec, it's for zero-params_processor
211206
_npermit: %i[ npmt not_permit unpermit ], # NOT OAS Spec, it's for zero-params_processor
207+
_req_if: %i[ req_if req_when ], # NOT OAS Spec, it's for zero-params_processor
208+
_opt_if: %i[ opt_if opt_when ], # NOT OAS Spec, it's for zero-params_processor
212209
}.each do |key, aliases|
213210
define_method key do
214211
aliases.each do |alias_name|

lib/open_api/dsl.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ def open_api method, summary = '', builder: nil, skip: [ ], use: [ ], &block
3636
# select the routing info (corresponding to the current method) from the routing list.
3737
action_path = "#{@_ctrl_path ||= controller_path}##{method}"
3838
routes_info = ctrl_routes_list&.select { |api| api[:action_path].match? /^#{action_path}$/ }&.first
39-
pp "[ZRO Warnning] Routing mapping failed: #{@_ctrl_path}##{method}" and return if routes_info.nil?
39+
pp "[ZRO Warning] Routing mapping failed: #{@_ctrl_path}##{method}" and return if routes_info.nil?
4040
Generator.generate_builder_file(action_path, builder) if builder.present?
4141

4242
# structural { #path: { #http_method:{ } } }, for pushing into Paths Object.
4343
path = (@_api_infos ||= { })[routes_info[:path]] ||= { }
4444
current_api = path[routes_info[:http_verb]] =
45-
ApiInfoObj.new(action_path, skip: skip, use: use)
45+
ApiInfoObj.new(action_path, skip: Array(skip), use: Array(use))
4646
.merge! description: '', summary: summary, operationId: method, tags: [@_apis_tag],
4747
parameters: [ ], requestBody: '', responses: { }, security: [ ], servers: [ ]
4848

4949
current_api.tap do |api|
5050
[method, :all].each do |key| # blocks_store_key
51-
@_apis_blocks&.[](key)&.each { |blk| api.instance_eval &blk }
51+
@_apis_blocks&.[](key)&.each { |blk| api.instance_eval(&blk) }
5252
end
5353
api.param_use = [ ] # skip 和 use 是对 dry 块而言的
54-
api.instance_eval &block if block_given?
54+
api.instance_eval(&block) if block_given?
5555
api._process_objs
5656
api.delete_if { |_, v| v.blank? }
5757
end

lib/open_api/generator.rb

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def generate_doc(api_name)
3636
doc[:components].merge! ctrl_infos[:components] || { }
3737
end
3838
doc[:components].delete_if { |_, v| v.blank? }
39+
doc[:tags] = doc[:tags].sort { |a, b| a[:name] <=> b[:name] }
40+
doc[:paths] = doc[:paths].sort.to_h
41+
3942
($open_apis ||= { })[api_name] ||=
4043
ActiveSupport::HashWithIndifferentAccess.new(doc.delete_if { |_, v| v.blank? })
4144
end

lib/open_api/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module OpenApi
2-
VERSION = '1.3.1'
2+
VERSION = '1.3.2'
33
end

0 commit comments

Comments
 (0)