open_api_annotator 0.3.0 → 0.4.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: 82d5be185e7a5b82a671e9aa01df93bec5019fb50c08d9f98726ab9b93ed006d
4
- data.tar.gz: 01aad8fa87590fa903129b0a1463c21b7cb644c3bfa68a158bf29a01076bcb12
3
+ metadata.gz: 3783c346bf9c75e17861f54e485de4296630782ada42af36aa409383883bf711
4
+ data.tar.gz: b1c2120fa5db9eb13e8d07aefdc84ab4c38cc41d5dd3d6f32b1cf3e13599e432
5
5
  SHA512:
6
- metadata.gz: 188c9e6692583b26d1078cc850b4a236f9e8a2fac23ebd72b505978e28269a288d1348ae32a6eb0f16ec74464ab105caa1ca2207f6a8bed524c04622f64ce33d
7
- data.tar.gz: a77a59eb416c77d93fcd18112889c583df63c5151ac5a33e3fcd617a26ef85dcc592df8fced40c8f597a578aec17ea7d1aa9e68f4aa19992d4ce76af585d7026
6
+ metadata.gz: 2a867ddd7f65ac82c63038a3832751d384e26b6c7d4dfd039780fd39738e913b751f6fab2ab1933dd4acc635356e3ba07c40647daa045b923283cf9b9e24c505
7
+ data.tar.gz: 8edcad36fcef036a465fee95f15e138b40b99372e0722416300ba4e97c07a3d761ce006baa0b18fd31ac31ec37c954b8d9655cbb1619b62aef347118fd068b78
data/.travis.yml CHANGED
@@ -6,7 +6,9 @@ language: ruby
6
6
  rvm:
7
7
  - 2.4.4
8
8
  - 2.5.1
9
- before_install: gem install bundler -v 1.16.1
9
+ before_install:
10
+ - gem install -v 1.17.3 bundler --no-rdoc --no-ri
11
+ - bundle _1.17.3_ install
10
12
  before_script:
11
13
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12
14
  - chmod +x ./cc-test-reporter
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## Not released yet
2
+
3
+ ## 0.4.0
4
+ - Enable to annotate primitive types to endpoint #11
5
+
1
6
  ## 0.3.0
2
7
  - Add path parameters to parameters #8
3
8
  - Enable add always requried fields #9
@@ -54,9 +54,21 @@ module OpenApiAnnotator
54
54
 
55
55
  case type
56
56
  when Array
57
- "Returns an array of #{type.first.name}"
57
+ name = build_type_name(type.first)
58
+ "Returns an array of #{name}"
59
+ else
60
+ name = build_type_name(type)
61
+ "Returns a #{name}"
62
+ end
63
+ end
64
+
65
+ def build_type_name(type)
66
+ type = convert_primitive_class_to_data_type(type)
67
+ case type
68
+ when OpenApi::DataType
69
+ "#{type.name}"
58
70
  when Class
59
- "Returns a #{type.name}"
71
+ "#{type.name}"
60
72
  else
61
73
  raise "not supported class #{type.class}"
62
74
  end
@@ -68,18 +80,39 @@ module OpenApiAnnotator
68
80
 
69
81
  case type
70
82
  when Array
71
- content_class = type.first
72
- reference = OpenApi::Reference.new(ref: "#/components/schemas/#{content_class.name}")
73
- schema = OpenApi::Schema.new(type: "array", items: reference)
83
+ schema_of_array = resolve_media_type_schema(type.first)
84
+ schema = OpenApi::Schema.new(type: "array", items: schema_of_array)
85
+ OpenApi::MediaType.new(schema: schema)
86
+ else
87
+ schema = resolve_media_type_schema(type)
74
88
  OpenApi::MediaType.new(schema: schema)
89
+ end
90
+ end
91
+
92
+ def resolve_media_type_schema(type)
93
+ type = convert_primitive_class_to_data_type(type)
94
+ case type
95
+ when OpenApi::DataType
96
+ OpenApi::Schema.new(type: type.name, format: type.format)
75
97
  when Class
76
- reference = OpenApi::Reference.new(ref: "#/components/schemas/#{type.name}")
77
- OpenApi::MediaType.new(schema: reference)
98
+ OpenApi::Reference.new(ref: "#/components/schemas/#{type.name}")
78
99
  else
79
100
  raise "not supported class #{type.class}"
80
101
  end
81
102
  end
82
103
 
104
+ def convert_primitive_class_to_data_type(type)
105
+ if type == String
106
+ OpenApi::DataType.new(:string, :string, :string)
107
+ elsif type == Integer
108
+ OpenApi::DataType.new(:integer, :integer, :int32)
109
+ elsif type == Float
110
+ OpenApi::DataType.new(:float, :number, :float)
111
+ else
112
+ type
113
+ end
114
+ end
115
+
83
116
  def resolve_type(controller_name, action_name)
84
117
  controller_class_name = "#{controller_name}_controller".classify
85
118
  begin
@@ -1,3 +1,3 @@
1
1
  module OpenApiAnnotator
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.0
4
+ version: 0.4.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-04-09 00:00:00.000000000 Z
11
+ date: 2019-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: open_api