open_api_annotator 0.1.0 → 0.2.0
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/README.md +3 -3
- data/lib/open_api_annotator.rb +1 -0
- data/lib/open_api_annotator/components_builder.rb +9 -1
- data/lib/open_api_annotator/controller_annotatable.rb +7 -7
- data/lib/open_api_annotator/endpoint.rb +4 -0
- data/lib/open_api_annotator/paths_builder.rb +6 -5
- data/lib/open_api_annotator/serializer_annotatable.rb +1 -1
- data/lib/open_api_annotator/version.rb +1 -1
- data/open_api_annotator.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bb9e46a88ce7e7634106d19d12c7df63d2f5760456c0419bf90607e49e5f10b
|
4
|
+
data.tar.gz: 0f6d152a177721e6b753a2867cc7670d93d63c78734b38da6119ba57f273f9bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ffe01f6857c993dad939e5e0ae61091bc2536223ac6705c06d2f50d7646a53c8db746a7b76db88f24406e295dc2bf5f10b38cd9862175d3a8410afe65113da2
|
7
|
+
data.tar.gz: 65d7dd45c64987f61bcaee80fa44c2a1b33215ccce83e5e7119a66cd61b96ead87682ab94858b952e3714806f3753beb648cfb6b9c59c22feac36775acea9410
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# OpenApiAnnotator [](https://travis-ci.org/ngtk/open_api_annotator) [](https://codeclimate.com/github/ngtk/open_api_annotator/maintainability) [](https://codeclimate.com/github/ngtk/open_api_annotator/test_coverage)
|
1
|
+
# OpenApiAnnotator [](https://badge.fury.io/rb/open_api_annotator) [](https://travis-ci.org/ngtk/open_api_annotator) [](https://codeclimate.com/github/ngtk/open_api_annotator/maintainability) [](https://codeclimate.com/github/ngtk/open_api_annotator/test_coverage)
|
2
2
|
|
3
|
-
OpenApiAnnotator realizes to generate
|
4
|
-
If you use ActiveModelSerializer, this is the best to generate OpenAPI spec.
|
3
|
+
OpenApiAnnotator realizes to generate OpenAPI spec by annotating to controllers and serializers.
|
4
|
+
If you use ActiveModelSerializer, this is the best way to generate OpenAPI spec.
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
data/lib/open_api_annotator.rb
CHANGED
@@ -59,7 +59,15 @@ module OpenApiAnnotator
|
|
59
59
|
associations.each do |association|
|
60
60
|
next unless association.valid?
|
61
61
|
content_name = association.type.try(:name) || association.type.to_s
|
62
|
-
|
62
|
+
reference = OpenApi::Reference.new(ref: "#/components/schemas/#{content_name}")
|
63
|
+
properties[association.name.to_sym] = if association.nullable
|
64
|
+
OpenApi::Schema.new(
|
65
|
+
nullable: true,
|
66
|
+
allOf: [reference]
|
67
|
+
)
|
68
|
+
else
|
69
|
+
reference
|
70
|
+
end
|
63
71
|
end
|
64
72
|
properties
|
65
73
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module OpenApiAnnotator
|
2
2
|
module ControllerAnnotatable
|
3
|
-
def
|
4
|
-
@
|
3
|
+
def endpoint_hash
|
4
|
+
@endpoint_hash ||= {}
|
5
5
|
end
|
6
6
|
|
7
7
|
def validate_open_api_type!(type)
|
@@ -11,7 +11,7 @@ module OpenApiAnnotator
|
|
11
11
|
|
12
12
|
def endpoint(type)
|
13
13
|
validate_open_api_type!(type)
|
14
|
-
@
|
14
|
+
@last_endpoint = Endpoint.new(type)
|
15
15
|
|
16
16
|
rescue ValidationError => e
|
17
17
|
raise TypeError, <<~EOL
|
@@ -32,14 +32,14 @@ module OpenApiAnnotator
|
|
32
32
|
|
33
33
|
def method_added(name)
|
34
34
|
super
|
35
|
-
return unless @
|
35
|
+
return unless @last_endpoint
|
36
36
|
|
37
|
-
|
38
|
-
@
|
37
|
+
endpoint = @last_endpoint
|
38
|
+
@last_endpoint = nil
|
39
39
|
|
40
40
|
return if private_method_defined?(name)
|
41
41
|
|
42
|
-
|
42
|
+
endpoint_hash[name] = endpoint
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -3,8 +3,9 @@ module OpenApiAnnotator
|
|
3
3
|
def build
|
4
4
|
paths = OpenApi::Paths.new
|
5
5
|
routes = RoutesFinder.new.find_all
|
6
|
-
|
7
|
-
|
6
|
+
path_regexp = OpenApiAnnotator.config.path_regexp
|
7
|
+
if path_regexp
|
8
|
+
routes.select! { |route| route.path.match(path_regexp) }
|
8
9
|
end
|
9
10
|
routes.group_by(&:path).each do |path_name, routes|
|
10
11
|
paths[path_name] = build_path_item(routes)
|
@@ -41,9 +42,9 @@ module OpenApiAnnotator
|
|
41
42
|
|
42
43
|
case type
|
43
44
|
when Array
|
44
|
-
"Returns array of #{type.first.name}"
|
45
|
+
"Returns an array of #{type.first.name}"
|
45
46
|
when Class
|
46
|
-
"Returns #{type.name}"
|
47
|
+
"Returns a #{type.name}"
|
47
48
|
else
|
48
49
|
raise "not supported class #{type.class}"
|
49
50
|
end
|
@@ -76,7 +77,7 @@ module OpenApiAnnotator
|
|
76
77
|
end
|
77
78
|
return unless controller_class < OpenApiAnnotator.config.application_controller_class
|
78
79
|
|
79
|
-
controller_class.
|
80
|
+
controller_class.endpoint_hash[action_name.to_sym]&.type
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
@@ -67,7 +67,7 @@ module OpenApiAnnotator
|
|
67
67
|
reflection.is_a?(ActiveModel::Serializer::HasOneReflection)
|
68
68
|
}.map do |reflection|
|
69
69
|
serializer_class = reflection.options[:serializer]
|
70
|
-
type = serializer_class ?
|
70
|
+
type = serializer_class ? serializer_class.open_api_resource_name : reflection.options[:type]
|
71
71
|
Association.new(reflection.name.to_sym, type, reflection.options[:nullable])
|
72
72
|
end
|
73
73
|
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.3.
|
24
|
+
spec.add_dependency "open_api", ">= 0.3.4"
|
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.2.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:
|
11
|
+
date: 2019-02-01 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.3.
|
19
|
+
version: 0.3.4
|
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.3.
|
26
|
+
version: 0.3.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: active_model_serializers
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- lib/open_api_annotator/config.rb
|
190
190
|
- lib/open_api_annotator/configurable.rb
|
191
191
|
- lib/open_api_annotator/controller_annotatable.rb
|
192
|
+
- lib/open_api_annotator/endpoint.rb
|
192
193
|
- lib/open_api_annotator/errors.rb
|
193
194
|
- lib/open_api_annotator/field.rb
|
194
195
|
- lib/open_api_annotator/format_validator.rb
|
@@ -219,8 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
220
|
- !ruby/object:Gem::Version
|
220
221
|
version: '0'
|
221
222
|
requirements: []
|
222
|
-
|
223
|
-
rubygems_version: 2.7.6
|
223
|
+
rubygems_version: 3.0.1
|
224
224
|
signing_key:
|
225
225
|
specification_version: 4
|
226
226
|
summary: OpenApi spec generation by bottom-up.
|