zero-rails_openapi 1.3.2 → 1.3.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/Gemfile +0 -2
- data/Gemfile.lock +90 -3
- data/README.md +409 -357
- data/documentation/examples/examples_controller.rb +2 -2
- data/documentation/examples/goods_doc.rb +14 -12
- data/documentation/examples/open_api.rb +14 -4
- data/documentation/examples/{example_output_doc.json → output_example.json} +0 -0
- data/documentation/parameter.md +17 -12
- data/lib/oas_objs/schema_obj.rb +1 -1
- data/lib/open_api/config.rb +18 -18
- data/lib/open_api/config_dsl.rb +21 -2
- data/lib/open_api/dsl.rb +12 -13
- data/lib/open_api/dsl/api_info_obj.rb +27 -2
- data/lib/open_api/dsl/common_dsl.rb +1 -0
- data/lib/open_api/dsl/ctrl_info_obj.rb +1 -1
- data/lib/open_api/dsl/helpers.rb +4 -4
- data/lib/open_api/generator.rb +16 -5
- data/lib/open_api/version.rb +1 -1
- data/zero-rails_openapi.gemspec +3 -9
- metadata +31 -3
data/lib/open_api/generator.rb
CHANGED
@@ -21,6 +21,7 @@ module OpenApi
|
|
21
21
|
def generate_doc(api_name)
|
22
22
|
settings = Config.docs[api_name]
|
23
23
|
doc = { openapi: '3.0.0' }.merge(settings.slice :info, :servers).merge(
|
24
|
+
# TODO: rename to just `security`
|
24
25
|
security: settings[:global_security], tags: [ ], paths: { },
|
25
26
|
components: {
|
26
27
|
securitySchemes: settings[:global_security_schemes],
|
@@ -34,6 +35,7 @@ module OpenApi
|
|
34
35
|
doc[:paths].merge! ctrl.instance_variable_get('@_api_infos') || { }
|
35
36
|
doc[:tags] << ctrl_infos[:tag]
|
36
37
|
doc[:components].merge! ctrl_infos[:components] || { }
|
38
|
+
($api_paths_index ||= { })[ctrl.instance_variable_get('@_ctrl_path')] = api_name
|
37
39
|
end
|
38
40
|
doc[:components].delete_if { |_, v| v.blank? }
|
39
41
|
doc[:tags] = doc[:tags].sort { |a, b| a[:name] <=> b[:name] }
|
@@ -67,19 +69,20 @@ module OpenApi
|
|
67
69
|
FileUtils.mkdir_p dir_path
|
68
70
|
file_path = "#{dir_path}/#{action}.json.jbuilder"
|
69
71
|
|
70
|
-
|
72
|
+
if Config.overwrite_jbuilder_file || !File.exists?(file_path)
|
71
73
|
File.open(file_path, 'w') { |file| file.write Config.jbuilder_templates[builder] }
|
72
74
|
puts "[ZRO] JBuilder file has been generated: #{path}/#{action}"
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
|
-
def self.
|
78
|
+
def self.routes_list
|
77
79
|
# ref https://github.com/rails/rails/blob/master/railties/lib/rails/tasks/routes.rake
|
78
80
|
require './config/routes'
|
79
81
|
all_routes = Rails.application.routes.routes
|
80
82
|
require 'action_dispatch/routing/inspector'
|
81
83
|
inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
|
82
84
|
|
85
|
+
@routes_list ||=
|
83
86
|
inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, nil).split("\n").drop(1).map do |line|
|
84
87
|
infos = line.match(/[A-Z].*/).to_s.split(' ') # => [GET, /api/v1/examples/:id, api/v1/examples#index]
|
85
88
|
{
|
@@ -92,11 +95,19 @@ module OpenApi
|
|
92
95
|
end.compact.group_by {|api| api[:action_path].split('#').first } # => { "api/v1/examples" => [..] }, group by paths
|
93
96
|
end
|
94
97
|
|
95
|
-
def self.get_actions_by_ctrl_path(
|
96
|
-
|
97
|
-
@routes_list[path]&.map do |action_info|
|
98
|
+
def self.get_actions_by_ctrl_path(ctrl_path)
|
99
|
+
routes_list[ctrl_path]&.map do |action_info|
|
98
100
|
action_info[:action_path].split('#').last
|
99
101
|
end
|
100
102
|
end
|
103
|
+
|
104
|
+
def self.find_path_httpverb_by(ctrl_path, action)
|
105
|
+
routes_list[ctrl_path]&.map do |action_info|
|
106
|
+
if action_info[:action_path].split('#').last == action.to_s
|
107
|
+
return [ action_info[:path], action_info[:http_verb] ]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
nil
|
111
|
+
end
|
101
112
|
end
|
102
113
|
end
|
data/lib/open_api/version.rb
CHANGED
data/zero-rails_openapi.gemspec
CHANGED
@@ -16,15 +16,6 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.homepage = "https://github.com/zhandao/zero-rails_openapi"
|
17
17
|
spec.license = "MIT"
|
18
18
|
|
19
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
20
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
21
|
-
# if spec.respond_to?(:metadata)
|
22
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
23
|
-
# else
|
24
|
-
# raise "RubyGems 2.0 or newer is required to protect against " \
|
25
|
-
# "public gem pushes."
|
26
|
-
# end
|
27
|
-
|
28
19
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
29
20
|
f.match(%r{^(test|spec|features)/})
|
30
21
|
end
|
@@ -35,4 +26,7 @@ Gem::Specification.new do |spec|
|
|
35
26
|
spec.add_development_dependency "bundler", "~> 1.16.a"
|
36
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
37
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
|
30
|
+
spec.add_runtime_dependency "rails", ">= 3"
|
31
|
+
spec.add_runtime_dependency "activesupport", ">= 3"
|
38
32
|
end
|
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.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhandao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3'
|
55
83
|
description: |-
|
56
84
|
Provide concise DSL for generating the OpenAPI Specification 3 (OAS3)
|
57
85
|
documentation JSON file for Rails application,
|
@@ -76,10 +104,10 @@ files:
|
|
76
104
|
- bin/setup
|
77
105
|
- documentation/examples/auto_gen_desc.rb
|
78
106
|
- documentation/examples/auto_gen_doc.rb
|
79
|
-
- documentation/examples/example_output_doc.json
|
80
107
|
- documentation/examples/examples_controller.rb
|
81
108
|
- documentation/examples/goods_doc.rb
|
82
109
|
- documentation/examples/open_api.rb
|
110
|
+
- documentation/examples/output_example.json
|
83
111
|
- documentation/parameter.md
|
84
112
|
- lib/oas_objs/example_obj.rb
|
85
113
|
- lib/oas_objs/helpers.rb
|