zero-rails_openapi 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile.lock +5 -3
- data/README.md +149 -149
- data/README_zh.md +183 -167
- data/documentation/examples/examples_controller.rb +1 -1
- data/documentation/parameter.md +3 -3
- data/lib/oas_objs/param_obj.rb +7 -18
- data/lib/oas_objs/ref_obj.rb +2 -1
- data/lib/oas_objs/schema_obj.rb +26 -62
- data/lib/oas_objs/schema_obj_helpers.rb +37 -21
- data/lib/open_api/dsl/api_info.rb +24 -41
- data/lib/open_api/dsl/common_dsl.rb +3 -2
- data/lib/open_api/dsl/components.rb +25 -33
- data/lib/open_api/dsl/helpers.rb +24 -8
- data/lib/open_api/dsl.rb +3 -2
- data/lib/open_api/generator.rb +7 -7
- data/lib/open_api/version.rb +1 -1
- data/zero-rails_openapi.gemspec +3 -0
- metadata +16 -2
data/lib/open_api/dsl.rb
CHANGED
@@ -25,7 +25,8 @@ module OpenApi
|
|
25
25
|
|
26
26
|
def components &block
|
27
27
|
doc_tag if @doc_info.nil?
|
28
|
-
|
28
|
+
structure = %i[ schemas responses parameters examples requestBodies securitySchemes ].map { |k| [k, { }] }.to_h
|
29
|
+
current_doc = @doc_info[:components] = Components.new.merge!(structure)
|
29
30
|
current_doc.instance_exec(&block)
|
30
31
|
current_doc.process_objs
|
31
32
|
end
|
@@ -35,7 +36,7 @@ module OpenApi
|
|
35
36
|
# select the routing info (corresponding to the current method) from routing list.
|
36
37
|
action_path = "#{@route_base ||= controller_path}##{action}"
|
37
38
|
routes = ctrl_routes_list&.select { |api| api[:action_path].match?(/^#{action_path}$/) }
|
38
|
-
|
39
|
+
return puts ' ZRO'.red + " Route mapping failed: #{@route_base}##{action}" if routes.blank?
|
39
40
|
|
40
41
|
api = ApiInfo.new(action_path, skip: Array(skip), use: Array(use))
|
41
42
|
.merge! description: '', summary: summary, operationId: action, tags: [@doc_tag],
|
data/lib/open_api/generator.rb
CHANGED
@@ -11,15 +11,13 @@ module OpenApi
|
|
11
11
|
|
12
12
|
module ClassMethods
|
13
13
|
def generate_docs(doc_name = nil)
|
14
|
-
|
14
|
+
return puts ' ZRO'.red + ' No documents have been configured!' if Config.docs.keys.blank?
|
15
15
|
|
16
|
+
# :nocov:
|
16
17
|
Dir['./app/controllers/**/*_controller.rb'].each do |file|
|
17
|
-
# Do Not `require`!
|
18
|
-
# It causes problems, such as making `skip_before_action` not working.
|
19
|
-
# :nocov:
|
20
18
|
file.sub('./app/controllers/', '').sub('.rb', '').camelize.constantize
|
21
|
-
# :nocov:
|
22
19
|
end
|
20
|
+
# :nocov:
|
23
21
|
Dir[*Array(Config.doc_location)].each { |file| require file }
|
24
22
|
(doc_name || Config.docs.keys).map { |name| { name => generate_doc(name) } }.reduce({ }, :merge!)
|
25
23
|
end
|
@@ -52,18 +50,20 @@ module OpenApi
|
|
52
50
|
|
53
51
|
def write_docs(generate_files: true)
|
54
52
|
docs = generate_docs
|
53
|
+
puts ' ZRO loaded.'.green if ENV['RAILS_ENV']
|
55
54
|
return unless generate_files
|
56
55
|
# :nocov:
|
57
56
|
output_path = Config.file_output_path
|
58
57
|
FileUtils.mkdir_p output_path
|
59
58
|
max_length = docs.keys.map(&:size).sort.last
|
60
59
|
docs.each do |doc_name, doc|
|
61
|
-
puts
|
60
|
+
puts ' ZRO'.green + " `#{doc_name.to_s.rjust(max_length)}.json` has been generated."
|
62
61
|
File.open("#{output_path}/#{doc_name}.json", 'w') { |file| file.write JSON.pretty_generate doc }
|
63
62
|
end
|
64
63
|
# :nocov:
|
65
64
|
end
|
66
|
-
end
|
65
|
+
end
|
66
|
+
# end of module
|
67
67
|
|
68
68
|
def routes
|
69
69
|
@routes ||=
|
data/lib/open_api/version.rb
CHANGED
data/zero-rails_openapi.gemspec
CHANGED
@@ -21,10 +21,13 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
+
# spec.required_ruby_version = ">= 2.2.2"
|
25
|
+
|
24
26
|
spec.add_development_dependency 'bundler', '~> 1.16.a'
|
25
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
29
|
spec.add_development_dependency 'simplecov'
|
30
|
+
spec.add_development_dependency 'colorize'
|
28
31
|
|
29
32
|
spec.add_runtime_dependency 'rails', '>= 3'
|
30
33
|
spec.add_runtime_dependency 'activesupport', '>= 3'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zero-rails_openapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhandao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colorize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rails
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|