zero-rails_openapi 2.1.0 → 2.1.5

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: e1945a762cf400f52a4fbc222c7cd10e6fed4937e3d4afcb9357e4e030edf349
4
- data.tar.gz: f6b25115dd788832d34e5f83e4b216c49381367b80e0ae1c33a65fa964726b0d
3
+ metadata.gz: a8d4c7ad77acde6b60064c24b5e9526d8182ee3d9580dd720b4781b67d64b8a9
4
+ data.tar.gz: f0697e6dfe1ce02e4427676f7f604d937685ab1a26876a3d3b2093069d13dc6e
5
5
  SHA512:
6
- metadata.gz: 56e62cdd21432ee8394ca955ca63498a9e198da18c553f30fa35840fad8219afc599bccb25e71a1c6565e513be26c3a2422c4e08c51b1e51ab48edd31423d813
7
- data.tar.gz: ce16f8ad8b4f83cdf5c7cbc4106b0f81354790a8febdeea0bf19b598f594e77505921260e832b6bf40f807ce580c9bef8c494b95c54de6d6d788e52c5032ef93
6
+ metadata.gz: 0cc748c545feebc6d0888594b99068279e18a17e32cd67297300d1147799319741c7fc8c1bdbefaca73b466f9ecb51b4eec15c0c91b43262e27776393cda0245
7
+ data.tar.gz: f09fa8f370ca5d7a16baa8c9fc7525ba1e2ecb224f7fe97fbf4233813610242e3f74abc083d2c5a80dba08fa86ad5646ffc9ae08cc9035227ca2d8840deab976
@@ -1,8 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.0
5
- before_install: gem install bundler -v 1.16.0.pre.2
4
+ - 2.7.1
5
+ before_install: gem install bundler -v 2.1.4
6
6
  env:
7
7
  global:
8
8
  - CC_TEST_REPORTER_ID=fd0a238819079b92c19e99f5f4d6dcc8a5b5b2baf087fceb3723837604b5b0e9
@@ -2,6 +2,30 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [2.1.5] - 2020/9/20 - [view diff](https://github.com/zhandao/zero-rails_openapi/compare/v2.1.4...v2.1.5)
6
+
7
+ ### Fixed
8
+
9
+ 1. Keyword arguments in Ruby 2.7 [issued by @dandunckelman](https://github.com/zhandao/zero-rails_openapi/issues/66)
10
+
11
+ ## [2.1.3 - 2.1.4] - 2020/2/10 - [view diff](https://github.com/zhandao/zero-rails_openapi/compare/v2.1.2...v2.1.4)
12
+
13
+ ### Fixed
14
+
15
+ 1. Fix response HTTP Status Code's type, restrict to String [issued by @am17torres](https://github.com/zhandao/zero-rails_openapi/issues/60)
16
+
17
+ ### Added
18
+
19
+ 1. Configurable additionalProperties's default value of Object type [issued by @remuspoienar](https://github.com/zhandao/zero-rails_openapi/issues/61)
20
+
21
+ ## [2.1.1 - 2.1.2] - 2019/2/12 - [view diff](https://github.com/zhandao/zero-rails_openapi/compare/v2.1.0...v2.1.2)
22
+
23
+ ### Fixed
24
+
25
+ 1. Fix response header schema output [PR #49 by @drjonnicholson](https://github.com/zhandao/zero-rails_openapi/pull/49)
26
+ 2. Fix router formatter in Rails 6 [PR #53 by @rjayroach](https://github.com/zhandao/zero-rails_openapi/pull/53)
27
+ 3. Support for generating `additional_properties: true` [issued by @bopm](https://github.com/zhandao/zero-rails_openapi/issues/55)
28
+
5
29
  ## [2.1.0] - 2019/2/16 - [view diff](https://github.com/zhandao/zero-rails_openapi/compare/v2.0.3...v2.1.0)
6
30
 
7
31
  See: [PR #43](https://github.com/zhandao/zero-rails_openapi/pull/43)
data/README.md CHANGED
@@ -121,6 +121,20 @@
121
121
 
122
122
  ### Part 2: config (DSL) for generating OpenApi info
123
123
 
124
+ ```ruby
125
+ # 1. open_api
126
+ # base_doc_classes should be an array of base classes of the classes you write the OpenApi spec in,
127
+ # like [ActionController::Base] (if you write spec in controllers).
128
+ open_api doc_name, base_doc_classes: []
129
+
130
+ # 2. info
131
+ info version:, title:, desc: '', **addition
132
+
133
+ # 3. server
134
+ # 4. security_scheme / base_auth / bearer_auth / api_key
135
+ # 5. global_security_require
136
+ ```
137
+
124
138
  See all the DSLs: [config_dsl.rb](lib/open_api/config_dsl.rb)
125
139
 
126
140
  ## DSL Usage
@@ -132,12 +146,12 @@
132
146
  ### First of all, `include OpenApi::DSL` in your base class (which is for writing spec):
133
147
 
134
148
  For example:
135
- ```ruby
136
- # in app/controllers/api/api_controller.rb
137
- class ApiController < ActionController::API
138
- include OpenApi::DSL
139
- end
140
- ```
149
+ ```ruby
150
+ # in app/controllers/api/api_controller.rb
151
+ class ApiController < ActionController::API
152
+ include OpenApi::DSL
153
+ end
154
+ ```
141
155
 
142
156
  ### DSL Usage Example
143
157
 
@@ -238,7 +252,7 @@
238
252
  end
239
253
  ```
240
254
 
241
- And then you should call `dry` method ([detailed info]()) for executing the declared dry blocks:
255
+ And then you should call `dry` method ([detailed info](#9-dry)) for executing the declared dry blocks:
242
256
  ```ruby
243
257
  api :index do
244
258
  dry
@@ -452,10 +466,11 @@
452
466
 
453
467
  ```ruby
454
468
  # ** Method Signature
455
- response code, desc, media_type = nil, data: { }, **options
469
+ response code, desc, media_type = nil, headers: { }, data: { }, **options
456
470
  # ** Usage
457
471
  resp 200, 'success', :json, data: { name: 'test' }
458
472
  response 200, 'query result', :pdf, data: File
473
+ response :success, 'succ', :json, headers: { 'X-Request-Start': String }, data: { }
459
474
 
460
475
  # ** Method Signature
461
476
  response_ref code_and_compkey_hash
@@ -16,8 +16,7 @@ module OpenApi
16
16
  end
17
17
 
18
18
  def process
19
- schema.process
20
- processed.merge!(schema: schema)
19
+ processed.merge!(schema: schema.process)
21
20
  end
22
21
  end
23
22
  end
@@ -7,21 +7,22 @@ module OpenApi
7
7
  module DSL
8
8
  # https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.0.md#media-type-object
9
9
  class MediaTypeObj < Hash
10
- attr_accessor :media_type, :schema, :examples
10
+ attr_accessor :media_type, :schema, :examples, :example
11
11
 
12
- def initialize(media_type, hash)
13
- examples_hash = hash.delete(:examples)
14
- exp_params = schema_type.keys if (exp_params = hash.delete(:exp_params)) == :all
15
- self.examples = ExampleObj.new(examples_hash, exp_params, multiple: true) if examples_hash.present?
12
+ def initialize(media_type, example: nil, examples: nil, exp_params: nil, **media_hash)
13
+ schema_type = media_hash.values_at(:type, :data).compact.first
14
+ exp_params = schema_type.keys if exp_params == :all
15
+ self.examples = ExampleObj.new(examples, exp_params, multiple: true) if examples.present?
16
+ self.example = ExampleObj.new(example) if example.present?
16
17
  self.media_type = media_type_mapping(media_type)
17
- self.schema = SchemaObj.new(hash.values_at(:type, :data).compact.first,
18
- hash.except(:type, :data))
18
+ self.schema = SchemaObj.new(schema_type, media_hash.except(:type, :data))
19
19
  end
20
20
 
21
21
  def process
22
22
  return { } if media_type.nil?
23
23
  schema_processed = schema.process
24
24
  result = schema_processed.values.join.blank? ? { } : { schema: schema_processed }
25
+ result[:example] = example.process unless example.nil?
25
26
  result[:examples] = examples.process unless examples.nil?
26
27
  { media_type => result }
27
28
  end
@@ -18,7 +18,7 @@ module OpenApi
18
18
  end
19
19
 
20
20
  def absorb(media_type, hash)
21
- media_types << MediaTypeObj.new(media_type, hash)
21
+ media_types << MediaTypeObj.new(media_type, **hash)
22
22
  self
23
23
  end
24
24
 
@@ -20,7 +20,7 @@ module OpenApi
20
20
  def absorb(desc, media_type, headers: { }, **media_hash)
21
21
  self.processed[:description] = desc if desc.present?
22
22
  self.headers.merge!(headers)
23
- media_types << MediaTypeObj.new(media_type, media_hash)
23
+ media_types << MediaTypeObj.new(media_type, **media_hash)
24
24
  self
25
25
  end
26
26
 
@@ -46,7 +46,7 @@ module OpenApi
46
46
  { type: 'string', format: Config.file_format }
47
47
  elsif t == 'datetime'
48
48
  { type: 'string', format: 'date-time' }
49
- elsif t[/\{=>.*\}/]
49
+ elsif t[/{=>.*}/]
50
50
  self[:values_type] = t[3..-2]
51
51
  { type: 'object' }
52
52
  else # other string
@@ -55,10 +55,12 @@ module OpenApi
55
55
  end
56
56
 
57
57
  def additional_properties
58
- return if processed[:type] != 'object' || _addProp.nil?
59
- {
60
- additionalProperties: SchemaObj.new(_addProp, { }).process
61
- }
58
+ return if processed[:type] != 'object'
59
+ default = Config.additional_properties_default_value_of_type_object
60
+ return { additionalProperties: default } if _addProp.nil? && !default.nil?
61
+
62
+ value = _addProp.in?([true, false]) ? _addProp : SchemaObj.new(_addProp, { }).process
63
+ { additionalProperties: value }
62
64
  end
63
65
 
64
66
  def enum
@@ -50,7 +50,7 @@ module OpenApi
50
50
  def init_hash(doc_name)
51
51
  settings = Config.docs[doc_name]
52
52
  doc = { openapi: '3.0.0', **settings.slice(:info, :servers) }.merge!(
53
- security: settings[:global_security], tags: [ ], paths: { },
53
+ security: settings[:global_security] || [], tags: [ ], paths: { },
54
54
  components: {
55
55
  securitySchemes: settings[:securitySchemes] || { },
56
56
  schemas: { }, parameters: { }, requestBodies: { }
@@ -24,6 +24,8 @@ module OpenApi
24
24
 
25
25
  cattr_accessor(:file_format) { 'binary' }
26
26
 
27
+ cattr_accessor(:additional_properties_default_value_of_type_object) { nil }
28
+
27
29
  def self.docs
28
30
  open_api_docs
29
31
  end
@@ -96,14 +96,14 @@ module OpenApi
96
96
  end
97
97
 
98
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)
99
+ (self[:responses][code.to_s] ||= ResponseObj.new(desc)).absorb(desc, media_type, headers: headers, data: data, **options)
100
100
  end
101
101
 
102
102
  alias_method :resp, :response
103
103
  alias_method :error, :response
104
104
 
105
105
  def response_ref code_and_compkey # = { }
106
- code_and_compkey.each { |code, component_key| self[:responses][code] = RefObj.new(:response, component_key) }
106
+ code_and_compkey.each { |code, component_key| self[:responses][code.to_s] = RefObj.new(:response, component_key) }
107
107
  end
108
108
 
109
109
  def security_require scheme_name, scopes: [ ]
@@ -31,7 +31,7 @@ module OpenApi
31
31
 
32
32
  def process_schema_input(schema_type, schema, name, model: nil)
33
33
  schema = { type: schema } unless schema.is_a?(Hash)
34
- combined_schema = _combined_schema(schema)
34
+ combined_schema = _combined_schema(**schema)
35
35
  type = schema[:type] ||= schema_type
36
36
  return Tip.param_no_type(name) if type.nil? && combined_schema.nil?
37
37
  combined_schema || SchemaObj.new(type, load_schema(model) || schema)
@@ -46,7 +46,12 @@ module OpenApi
46
46
  def arrow_writing_support
47
47
  proc do |args, executor|
48
48
  args = (args.size == 1 && args.first.is_a?(Hash)) ? args[0].to_a.flatten : args
49
- send(executor, *args)
49
+
50
+ if !executor.in?(%w[ _example _security_scheme _base_auth _bearer_auth ]) && args.last.is_a?(Hash)
51
+ send(executor, *args[0..-2], **args[-1])
52
+ else
53
+ send(executor, *args)
54
+ end
50
55
  end
51
56
  end
52
57
 
@@ -15,7 +15,11 @@ module OpenApi
15
15
  all_routes = Rails.application.routes.routes
16
16
  require 'action_dispatch/routing/inspector'
17
17
  inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
18
- inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, nil)
18
+ if Rails::VERSION::MAJOR < 6
19
+ inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, nil)
20
+ else
21
+ inspector.format(ActionDispatch::Routing::ConsoleFormatter::Sheet.new)
22
+ end
19
23
  # :nocov:
20
24
  end
21
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenApi
4
- VERSION = '2.1.0'
4
+ VERSION = '2.1.5'
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.1.0
4
+ version: 2.1.5
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-16 00:00:00.000000000 Z
11
+ date: 2020-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -188,8 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
190
  requirements: []
191
- rubyforge_project:
192
- rubygems_version: 2.7.3
191
+ rubygems_version: 3.1.2
193
192
  signing_key:
194
193
  specification_version: 4
195
194
  summary: Concise DSL for generating OpenAPI3 documentation.