Skip to content

Commit

Permalink
[feature #18] define multiple components blocks in one class
Browse files Browse the repository at this point in the history
  • Loading branch information
hikari-desu committed Jun 19, 2018
1 parent 20c20b7 commit 57d12c3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 39 deletions.
74 changes: 37 additions & 37 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
PATH
remote: .
specs:
zero-rails_openapi (1.5.7)
zero-rails_openapi (1.5.8)
activesupport (>= 3)
colorize
rails (>= 3)

GEM
remote: https://rubygems.org/
specs:
actioncable (5.1.5)
actionpack (= 5.1.5)
actioncable (5.1.6)
actionpack (= 5.1.6)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.5)
actionpack (= 5.1.5)
actionview (= 5.1.5)
activejob (= 5.1.5)
actionmailer (5.1.6)
actionpack (= 5.1.6)
actionview (= 5.1.6)
activejob (= 5.1.6)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.1.5)
actionview (= 5.1.5)
activesupport (= 5.1.5)
actionpack (5.1.6)
actionview (= 5.1.6)
activesupport (= 5.1.6)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.5)
activesupport (= 5.1.5)
actionview (5.1.6)
activesupport (= 5.1.6)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.5)
activesupport (= 5.1.5)
activejob (5.1.6)
activesupport (= 5.1.6)
globalid (>= 0.3.6)
activemodel (5.1.5)
activesupport (= 5.1.5)
activerecord (5.1.5)
activemodel (= 5.1.5)
activesupport (= 5.1.5)
activemodel (5.1.6)
activesupport (= 5.1.6)
activerecord (5.1.6)
activemodel (= 5.1.6)
activesupport (= 5.1.6)
arel (~> 8.0)
activesupport (5.1.5)
activesupport (5.1.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (8.0.0)
builder (3.2.3)
colorize (0.8.1)
concurrent-ruby (1.0.5)
crass (1.0.3)
crass (1.0.4)
diff-lcs (1.3)
docile (1.3.0)
erubi (1.7.1)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (0.9.5)
i18n (1.0.0)
concurrent-ruby (~> 1.0)
json (2.1.0)
loofah (2.2.2)
Expand All @@ -72,28 +72,28 @@ GEM
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
rack (2.0.4)
rack-test (0.8.3)
rack-test (1.0.0)
rack (>= 1.0, < 3)
rails (5.1.5)
actioncable (= 5.1.5)
actionmailer (= 5.1.5)
actionpack (= 5.1.5)
actionview (= 5.1.5)
activejob (= 5.1.5)
activemodel (= 5.1.5)
activerecord (= 5.1.5)
activesupport (= 5.1.5)
rails (5.1.6)
actioncable (= 5.1.6)
actionmailer (= 5.1.6)
actionpack (= 5.1.6)
actionview (= 5.1.6)
activejob (= 5.1.6)
activemodel (= 5.1.6)
activerecord (= 5.1.6)
activesupport (= 5.1.6)
bundler (>= 1.3.0)
railties (= 5.1.5)
railties (= 5.1.6)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.1.5)
actionpack (= 5.1.5)
activesupport (= 5.1.5)
railties (5.1.6)
actionpack (= 5.1.6)
activesupport (= 5.1.6)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
Expand Down
4 changes: 3 additions & 1 deletion lib/open_api/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def doc_tag name: nil, desc: '', external_doc_url: nil
def components &block
doc_tag if @doc_info.nil?
structure = %i[ schemas responses parameters examples requestBodies securitySchemes ].map { |k| [k, { }] }.to_h
current_doc = @doc_info[:components] = Components.new.merge!(structure)
current_doc = Components.new.merge!(structure)
current_doc.instance_exec(&block)
current_doc.process_objs

(@doc_info[:components] ||= { }).deep_merge!(current_doc)
end

def api action, summary = '', http: http_method = nil, skip: [ ], use: [ ], &block
Expand Down
2 changes: 1 addition & 1 deletion lib/open_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module OpenApi
VERSION = '1.5.7'
VERSION = '1.5.8'
end
7 changes: 7 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@
expect_its(:responses) { be_nil }
end
end

desc :components, subject: :components do
make -> do
components { response :RespA, 'invalid token' }
components { response :RespZ, 'parameter validation failed' }
end, has_keys!: { responses: %i[ RespA RespZ ] }
end
end

0 comments on commit 57d12c3

Please sign in to comment.