open_api_annotator 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c25f0d206c6a39ed21f7dd1a15fb886aaad9e6ed05db73aeda5ffa7e852a1ed
4
- data.tar.gz: ce7c5a930ec200636792afee7e4545ac13e8ebcc703281dd0da9da431d1857d6
3
+ metadata.gz: 1bb9e46a88ce7e7634106d19d12c7df63d2f5760456c0419bf90607e49e5f10b
4
+ data.tar.gz: 0f6d152a177721e6b753a2867cc7670d93d63c78734b38da6119ba57f273f9bb
5
5
  SHA512:
6
- metadata.gz: 5a7ac62a5ce7fddc89b62b8694f5e0c364a18d963b162f6b7479229d7e5ad1571fda1d64690eef4f1cd833c6bd661e4956788469e6357cf6b2769a3844b26610
7
- data.tar.gz: 5ba222eb03b1a1496ef8ce300cf5eaef0b179ee4e5b365348351c71a4eb78da607f8d3b2a1093013e3ad925e09b751b82f7db4b72b2ae62fe2983535aba06472
6
+ metadata.gz: 5ffe01f6857c993dad939e5e0ae61091bc2536223ac6705c06d2f50d7646a53c8db746a7b76db88f24406e295dc2bf5f10b38cd9862175d3a8410afe65113da2
7
+ data.tar.gz: 65d7dd45c64987f61bcaee80fa44c2a1b33215ccce83e5e7119a66cd61b96ead87682ab94858b952e3714806f3753beb648cfb6b9c59c22feac36775acea9410
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # OpenApiAnnotator [![Build Status](https://travis-ci.org/ngtk/open_api_annotator.svg?branch=master)](https://travis-ci.org/ngtk/open_api_annotator) [![Maintainability](https://api.codeclimate.com/v1/badges/8be7a273496459c62190/maintainability)](https://codeclimate.com/github/ngtk/open_api_annotator/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/8be7a273496459c62190/test_coverage)](https://codeclimate.com/github/ngtk/open_api_annotator/test_coverage)
1
+ # OpenApiAnnotator [![Gem Version](https://badge.fury.io/rb/open_api_annotator.svg)](https://badge.fury.io/rb/open_api_annotator) [![Build Status](https://travis-ci.org/ngtk/open_api_annotator.svg?branch=master)](https://travis-ci.org/ngtk/open_api_annotator) [![Maintainability](https://api.codeclimate.com/v1/badges/8be7a273496459c62190/maintainability)](https://codeclimate.com/github/ngtk/open_api_annotator/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/8be7a273496459c62190/test_coverage)](https://codeclimate.com/github/ngtk/open_api_annotator/test_coverage)
2
2
 
3
- OpenApiAnnotator realizes to generate OpenApi spec by annotating to controllers and serializers.
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
 
@@ -6,6 +6,7 @@ require 'rails'
6
6
 
7
7
  require 'open_api'
8
8
 
9
+ require 'open_api_annotator/endpoint'
9
10
  require 'open_api_annotator/field'
10
11
  require 'open_api_annotator/attribute'
11
12
  require 'open_api_annotator/association'
@@ -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
- properties[association.name.to_sym] = OpenApi::Reference.new(ref: "#/components/schemas/#{content_name}")
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 type_hash
4
- @type_hash ||= {}
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
- @last_type = type
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 @last_type
35
+ return unless @last_endpoint
36
36
 
37
- type = @last_type
38
- @last_type = nil
37
+ endpoint = @last_endpoint
38
+ @last_endpoint = nil
39
39
 
40
40
  return if private_method_defined?(name)
41
41
 
42
- type_hash[name] = type
42
+ endpoint_hash[name] = endpoint
43
43
  end
44
44
  end
45
45
  end
@@ -0,0 +1,4 @@
1
+ module OpenApiAnnotator
2
+ class Endpoint < Struct.new(:type)
3
+ end
4
+ 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
- if OpenApiAnnotator.config.path_regexp
7
- routes.select! { |route| route.path.match(OpenApiAnnotator.config.path_regexp) }
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.type_hash[action_name.to_sym]
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 ? [serializer_class.open_api_resource_name] : reflection.options[:type]
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
@@ -1,3 +1,3 @@
1
1
  module OpenApiAnnotator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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.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.1.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: 2018-06-03 00:00:00.000000000 Z
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.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.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
- rubyforge_project:
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.