open_api_annotator 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/open_api_annotator/components_builder.rb +20 -5
- data/lib/open_api_annotator/config.rb +6 -0
- data/lib/open_api_annotator/paths_builder.rb +24 -7
- data/lib/open_api_annotator/version.rb +1 -1
- data/open_api_annotator.gemspec +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82d5be185e7a5b82a671e9aa01df93bec5019fb50c08d9f98726ab9b93ed006d
|
4
|
+
data.tar.gz: 01aad8fa87590fa903129b0a1463c21b7cb644c3bfa68a158bf29a01076bcb12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 188c9e6692583b26d1078cc850b4a236f9e8a2fac23ebd72b505978e28269a288d1348ae32a6eb0f16ec74464ab105caa1ca2207f6a8bed524c04622f64ce33d
|
7
|
+
data.tar.gz: a77a59eb416c77d93fcd18112889c583df63c5151ac5a33e3fcd617a26ef85dcc592df8fced40c8f597a578aec17ea7d1aa9e68f4aa19992d4ce76af585d7026
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -76,7 +76,7 @@ end
|
|
76
76
|
|
77
77
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
78
78
|
|
79
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number
|
79
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number using `bundle exec bump patch`(or minor, major), and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
80
80
|
|
81
81
|
## Contributing
|
82
82
|
|
@@ -21,6 +21,10 @@ module OpenApiAnnotator
|
|
21
21
|
schema.properties.merge!(build_attribute_properties(serializer))
|
22
22
|
schema.properties.merge!(build_has_many_association_properties(serializer))
|
23
23
|
schema.properties.merge!(build_has_one_and_belongs_to_association_properties(serializer))
|
24
|
+
required_fields = OpenApiAnnotator.config.always_required_fields
|
25
|
+
if required_fields.present?
|
26
|
+
schema.required = required_fields.select{|field| schema.properties[field] }
|
27
|
+
end
|
24
28
|
schema
|
25
29
|
end
|
26
30
|
|
@@ -28,11 +32,22 @@ module OpenApiAnnotator
|
|
28
32
|
properties = {}
|
29
33
|
serializer.open_api_attributes.each do |attribute|
|
30
34
|
next unless attribute.valid?
|
31
|
-
properties[attribute.name.to_sym] =
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
properties[attribute.name.to_sym] = if attribute.type.is_a?(Array)
|
36
|
+
OpenApi::Schema.new(
|
37
|
+
type: "array",
|
38
|
+
items: OpenApi::Schema.new(
|
39
|
+
type: attribute.type.first,
|
40
|
+
format: attribute.format,
|
41
|
+
nullable: attribute.nullable,
|
42
|
+
)
|
43
|
+
)
|
44
|
+
else
|
45
|
+
OpenApi::Schema.new(
|
46
|
+
type: attribute.type,
|
47
|
+
format: attribute.format,
|
48
|
+
nullable: attribute.nullable,
|
49
|
+
)
|
50
|
+
end
|
36
51
|
end
|
37
52
|
properties
|
38
53
|
end
|
@@ -5,6 +5,7 @@ module OpenApiAnnotator
|
|
5
5
|
:path_regexp,
|
6
6
|
:application_controller_class_name,
|
7
7
|
:application_serializer_class_name,
|
8
|
+
:always_required_fields,
|
8
9
|
)
|
9
10
|
def application_serializer_class
|
10
11
|
if application_serializer_class_name
|
@@ -50,6 +51,7 @@ module OpenApiAnnotator
|
|
50
51
|
validate_path_regexp!
|
51
52
|
validate_application_controller_class_name!
|
52
53
|
validate_application_serializer_class_name!
|
54
|
+
validate_always_required_fields!
|
53
55
|
end
|
54
56
|
|
55
57
|
def validate_info!
|
@@ -95,6 +97,10 @@ module OpenApiAnnotator
|
|
95
97
|
# Do nothing
|
96
98
|
end
|
97
99
|
|
100
|
+
def validate_always_required_fields!
|
101
|
+
# Do nothing
|
102
|
+
end
|
103
|
+
|
98
104
|
class InvalidError < StandardError; end
|
99
105
|
end
|
100
106
|
end
|
@@ -23,14 +23,26 @@ module OpenApiAnnotator
|
|
23
23
|
media_type = resolve_media_type(route.controller_name, route.action_name)
|
24
24
|
description = build_description(route.controller_name, route.action_name)
|
25
25
|
next unless media_type
|
26
|
+
operation = OpenApi::Operation.new(responses: OpenApi::Responses.new)
|
26
27
|
response = OpenApi::Response.new(
|
27
28
|
description: description,
|
28
29
|
content: {
|
29
30
|
"application/json" => media_type,
|
30
31
|
}
|
31
32
|
)
|
32
|
-
operation = OpenApi::Operation.new(responses: OpenApi::Responses.new)
|
33
33
|
operation.responses["200"] = response
|
34
|
+
route.parameters.each do |parameter|
|
35
|
+
parameter = OpenApi::Parameter.new(
|
36
|
+
name: parameter[:name],
|
37
|
+
in: :path,
|
38
|
+
required: true,
|
39
|
+
schema: OpenApi::Schema.new(
|
40
|
+
type: :string
|
41
|
+
)
|
42
|
+
)
|
43
|
+
operation.parameters = [] unless operation.parameters
|
44
|
+
operation.parameters.push(parameter)
|
45
|
+
end
|
34
46
|
path_item.operations[route.http_verb.underscore] = operation
|
35
47
|
end
|
36
48
|
path_item
|
@@ -81,38 +93,43 @@ module OpenApiAnnotator
|
|
81
93
|
end
|
82
94
|
end
|
83
95
|
|
84
|
-
Route = Struct.new(:http_verb, :path, :controller_name, :action_name) do
|
85
|
-
def initialize(http_verb:, path:, controller_name:, action_name:)
|
96
|
+
Route = Struct.new(:http_verb, :path, :controller_name, :action_name, :parameters) do
|
97
|
+
def initialize(http_verb:, path:, controller_name:, action_name:, parameters: [])
|
86
98
|
self.http_verb = http_verb
|
87
99
|
self.path = path
|
88
100
|
self.controller_name = controller_name
|
89
101
|
self.action_name = action_name
|
102
|
+
self.parameters = parameters
|
90
103
|
end
|
91
104
|
end
|
92
105
|
|
93
106
|
class RoutesFinder
|
94
107
|
def find_all
|
95
108
|
@routes ||= Rails.application.routes.routes.routes.map do |route|
|
96
|
-
|
109
|
+
parameters = []
|
110
|
+
path = PathResolver.new.resolve(route.path.ast, parameters)
|
97
111
|
controller = route.requirements[:controller]
|
98
112
|
action = route.requirements[:action]
|
99
|
-
Route.new(http_verb: route.verb, path: path, controller_name: controller, action_name: action)
|
113
|
+
Route.new(http_verb: route.verb, path: path, controller_name: controller, action_name: action, parameters: parameters)
|
100
114
|
end
|
101
115
|
end
|
102
116
|
end
|
103
117
|
|
104
118
|
class PathResolver
|
105
|
-
def resolve(ast)
|
119
|
+
def resolve(ast, parameters_context = [])
|
106
120
|
res = ""
|
107
121
|
if ast.type == :CAT
|
108
122
|
left = ast.left
|
109
123
|
res +=
|
110
124
|
if left.type == :SYMBOL
|
125
|
+
parameters_context.push({
|
126
|
+
name: left.name,
|
127
|
+
})
|
111
128
|
"{#{left.name}}"
|
112
129
|
else
|
113
130
|
left.to_s
|
114
131
|
end
|
115
|
-
res += resolve(ast.right)
|
132
|
+
res += resolve(ast.right, parameters_context)
|
116
133
|
end
|
117
134
|
res
|
118
135
|
end
|
data/open_api_annotator.gemspec
CHANGED
@@ -21,7 +21,7 @@ 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.add_dependency "open_api", ">= 0.
|
24
|
+
spec.add_dependency "open_api", ">= 0.4.0"
|
25
25
|
spec.add_dependency "active_model_serializers", "~> 0.10.0"
|
26
26
|
|
27
27
|
rails_versions = ['>= 4.1', '< 6']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_api_annotator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kent Nagata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: open_api
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.4.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.4.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: active_model_serializers
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,7 +220,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
220
|
- !ruby/object:Gem::Version
|
221
221
|
version: '0'
|
222
222
|
requirements: []
|
223
|
-
|
223
|
+
rubyforge_project:
|
224
|
+
rubygems_version: 2.7.6
|
224
225
|
signing_key:
|
225
226
|
specification_version: 4
|
226
227
|
summary: OpenApi spec generation by bottom-up.
|