zero-rails_openapi 2.0.3 → 2.1.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: 99c7a0aeaedb2ff14dc929912f7aa734122c7ab76bea448c68186ab512ef79e1
4
- data.tar.gz: a2c95b2bf0856dee961183bb10f8f76f7a9031902199fc5874ac195b04eb4691
3
+ metadata.gz: e1945a762cf400f52a4fbc222c7cd10e6fed4937e3d4afcb9357e4e030edf349
4
+ data.tar.gz: f6b25115dd788832d34e5f83e4b216c49381367b80e0ae1c33a65fa964726b0d
5
5
  SHA512:
6
- metadata.gz: 7f868f8ccc21c52f10391dd9153814fa0cad1378fb1044455d07754639ad9e2951b331013d38accc28006e3ddf20944fa3179c1f34f5b460c3dff0072758de3b
7
- data.tar.gz: 18b5a70b962887ba16a79e58cd11ae3e16cd8460f4c9e3d2f96812e9effdf482203a7f8bb92697ddd6046b1e7e9f9e9d184eed2624cf601eb905aa909aab4145
6
+ metadata.gz: 56e62cdd21432ee8394ca955ca63498a9e198da18c553f30fa35840fad8219afc599bccb25e71a1c6565e513be26c3a2422c4e08c51b1e51ab48edd31423d813
7
+ data.tar.gz: ce16f8ad8b4f83cdf5c7cbc4106b0f81354790a8febdeea0bf19b598f594e77505921260e832b6bf40f807ce580c9bef8c494b95c54de6d6d788e52c5032ef93
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [2.1.0] - 2019/2/16 - [view diff](https://github.com/zhandao/zero-rails_openapi/compare/v2.0.3...v2.1.0)
6
+
7
+ See: [PR #43](https://github.com/zhandao/zero-rails_openapi/pull/43)
8
+
9
+ ### Added
10
+
11
+ Headers in Response Object ([issued by @drjonnicholson](https://github.com/zhandao/zero-rails_openapi/issues/42))
12
+
13
+ ## [2.0.0 - 2.0.3] - 2019/2/12 - [view diff](https://github.com/zhandao/zero-rails_openapi/compare/v1.7.0...v2.0.3)
14
+
15
+ See: [PR #35](https://github.com/zhandao/zero-rails_openapi/pull/35)
16
+
17
+ 1. Totally refactoring
18
+ 2. README rewritten
19
+ 3. Removed Or Changed uncommonly used features
20
+
5
21
  ## [1.7.0] - 2018/12/17 - [view diff](https://github.com/zhandao/zero-rails_openapi/compare/v1.6.1...v1.7.0)
6
22
 
7
23
  ### Added
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oas_objs/helpers'
4
+
5
+ module OpenApi
6
+ module DSL
7
+ # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#header-object
8
+ class HeaderObj < Hash
9
+ include Helpers
10
+
11
+ attr_accessor :processed, :schema
12
+
13
+ def initialize(desc = '', schema)
14
+ self.schema = SchemaObj.new(schema)
15
+ self.processed = { description: desc }
16
+ end
17
+
18
+ def process
19
+ schema.process
20
+ processed.merge!(schema: schema)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+
27
+ __END__
28
+
29
+ Header Object Example
30
+
31
+ {
32
+ "description": "The number of allowed requests in the current period",
33
+ "schema": {
34
+ "type": "integer"
35
+ }
36
+ }
@@ -9,21 +9,29 @@ module OpenApi
9
9
  class ResponseObj < Hash
10
10
  include Helpers
11
11
 
12
- attr_accessor :processed, :media_types
12
+ attr_accessor :processed, :media_types, :headers
13
+
13
14
  def initialize(desc)
14
15
  self.media_types = [ ]
16
+ self.headers = { }
15
17
  self.processed = { description: desc }
16
18
  end
17
19
 
18
- def absorb(desc, media_type, hash)
20
+ def absorb(desc, media_type, headers: { }, **media_hash)
19
21
  self.processed[:description] = desc if desc.present?
20
- media_types << MediaTypeObj.new(media_type, hash)
22
+ self.headers.merge!(headers)
23
+ media_types << MediaTypeObj.new(media_type, media_hash)
21
24
  self
22
25
  end
23
26
 
24
27
  def process
25
28
  content = media_types.map(&:process).reduce({ }, &fusion)
26
29
  processed[:content] = content if content.present?
30
+ _headers = headers.map do |name, schema|
31
+ schema = schema.is_a?(Hash) ? schema : { type: schema }
32
+ [ name, HeaderObj.new(schema.delete(:desc), schema).process ]
33
+ end.to_h
34
+ processed[:headers] = _headers if _headers.present?
27
35
  processed
28
36
  end
29
37
  end
@@ -49,4 +57,4 @@ Response of an array of a complex type:
49
57
  }
50
58
  }
51
59
  }
52
- }
60
+ }
@@ -95,8 +95,8 @@ module OpenApi
95
95
  form data: { name => schema }
96
96
  end
97
97
 
98
- def response code, desc, media_type = nil, data: { }, **options
99
- (self[:responses][code] ||= ResponseObj.new(desc)).absorb(desc, media_type, { data: data, **options })
98
+ def response code, desc, media_type = nil, headers: { }, data: { }, **options
99
+ (self[:responses][code] ||= ResponseObj.new(desc)).absorb(desc, media_type, headers: headers, data: data, **options)
100
100
  end
101
101
 
102
102
  alias_method :resp, :response
@@ -49,8 +49,8 @@ module OpenApi
49
49
  arrow_enable :body
50
50
  arrow_enable :body!
51
51
 
52
- def response component_key, desc, media_type = nil, data: { }, **options
53
- (self[:responses][component_key] ||= ResponseObj.new(desc)).absorb(desc, media_type, { data: data, **options })
52
+ def response component_key, desc, media_type = nil, headers: { }, data: { }, **options
53
+ (self[:responses][component_key] ||= ResponseObj.new(desc)).absorb(desc, media_type, headers: headers, data: data, **options)
54
54
  end
55
55
 
56
56
  alias_method :resp, :response
@@ -8,6 +8,7 @@ require 'oas_objs/request_body_obj'
8
8
  require 'oas_objs/ref_obj'
9
9
  require 'oas_objs/example_obj'
10
10
  require 'oas_objs/callback_obj'
11
+ require 'oas_objs/header_obj'
11
12
 
12
13
  module OpenApi
13
14
  module DSL
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenApi
4
- VERSION = '2.0.3'
4
+ VERSION = '2.1.0'
5
5
  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: 2.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zhandao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-12 00:00:00.000000000 Z
11
+ date: 2019-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -149,6 +149,7 @@ files:
149
149
  - lib/oas_objs/callback_obj.rb
150
150
  - lib/oas_objs/combined_schema.rb
151
151
  - lib/oas_objs/example_obj.rb
152
+ - lib/oas_objs/header_obj.rb
152
153
  - lib/oas_objs/helpers.rb
153
154
  - lib/oas_objs/media_type_obj.rb
154
155
  - lib/oas_objs/param_obj.rb