Commit bf153373 by andrew morton Committed by GitHub

Merge pull request #29 from drewish/tags

Accept tags for operations from parent contexts
parents fe947519 88083617
......@@ -42,13 +42,16 @@ module RSpec
attributes.symbolize_keys!
raise ArgumentError, "Path must start with a /" unless template.starts_with?('/')
#TODO template might be a $ref
meta = {
swagger_object: :path_item,
swagger_document: attributes[:swagger_document] || RSpec.configuration.swagger_docs.keys.first,
swagger_path_item: {path: template}
swagger_path_item: {path: template},
}
# Merge tags passed into the path with those from parent contexts.
if attributes[:tags]
meta[:tags] = (metadata.try(:[], :tags) || []) + attributes[:tags]
end
describe(template, meta, &block)
end
end
......@@ -58,6 +61,12 @@ module RSpec
def operation method, attributes = {}, &block
attributes.symbolize_keys!
# Include tags from parent contexts so you can tag all the paths
# in a controller at once.
if metadata.try(:[], :tags).present?
attributes[:tags] ||= []
attributes[:tags] += metadata[:tags]
end
method = method.to_s.downcase
validate_method! method
......@@ -175,7 +184,8 @@ module RSpec
end
def tags *tags
metadata[:swagger_operation][:tags] = tags
metadata[:swagger_operation][:tags] ||= []
metadata[:swagger_operation][:tags] += tags
end
def response status_code, attributes = {}, &block
......
......@@ -28,3 +28,5 @@ fi
cd -
bundle exec rspec
# Duplicating the body of the rake task. Need to figure out how to call it directly.
bundle exec rspec -f RSpec::Rails::Swagger::Formatter --order defined -t swagger_object
require 'swagger_helper'
RSpec.describe "Requestsing", type: :request do
# path "/ping" do
# operation :put do
# response(200, {description: 'OK'})
# puts "in here"
# end
# end
path '/posts' do
operation "GET", summary:"fetch list" do
RSpec.describe "Sample Requests", type: :request, tags: [:context_tag] do
path '/posts', tags: ['path_tag'] do
operation "GET", summary: "fetch list" do
produces 'application/json'
tags 'operation_tag'
response(200, {description: "successful"})
end
......
......@@ -34,6 +34,17 @@ RSpec.describe RSpec::Rails::Swagger::Helpers::Paths do
subject.path('/ping', swagger_document: 'hello_swagger.json')
end
it "passes tags through to the metadata" do
expect(subject).to receive(:describe).with("/ping", {
swagger_object: :path_item,
swagger_document: RSpec.configuration.swagger_docs.keys.first,
swagger_path_item: {path: '/ping'},
tags: ['tag1']
})
subject.path('/ping', tags: ['tag1'])
end
end
RSpec.describe RSpec::Rails::Swagger::Helpers::PathItem do
......@@ -81,6 +92,18 @@ RSpec.describe RSpec::Rails::Swagger::Helpers::PathItem do
operationId: 'updatePetWithForm'
)
end
it 'includes tags from metadata of parent contexts' do
subject.metadata = { tags: ['baz'] }
expect(subject).to receive(:describe).with('get', {
swagger_object: :operation,
swagger_operation: {
tags: ['foo', 'baz'], method: :get
}
})
subject.operation(:get, tags: ['foo'])
end
end
described_class::METHODS.each do |method|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment