Commit 7e77096a by andrew morton

Cleaning up stuff around the params

parent db6e3635
......@@ -21,8 +21,10 @@ module RSpec
data = notification.example.metadata[:swagger_data]
document = document_for(nil)
path = path_for(document, data[:path])
operation = operation_for(path, data[:operation])
path_item = path_item_for(document, data[:path])
# TODO output path_item's parameters
operation = operation_for(path_item, data[:operation])
# TODO output operation's parameters
response = response_for(operation, data[:status_code])
response[:description] = data[:response_description] if data[:response_description]
response[:examples] = prepare_example(data[:example]) if data[:example]
......@@ -37,7 +39,7 @@ module RSpec
end
def write_json(name, document)
pp document
puts JSON.pretty_generate(document)
end
def document_for doc_name = nil
......@@ -48,7 +50,7 @@ module RSpec
end
end
def path_for document, path_name
def path_item_for document, path_name
document[:paths] ||= {}
document[:paths][path_name] ||= {}
end
......
......@@ -11,7 +11,7 @@ module RSpec
config.extend Operation, swagger_object: :operation
config.extend Parameters, swagger_object: :operation
config.extend Response, swagger_object: :status_code
config.include Common, :swagger_object
config.include Resolver, :swagger_object
end
......@@ -105,11 +105,6 @@ paths: (Paths)
describe("#{status_code}", meta) do
self.module_exec(&block) if block_given?
# TODO: this needs a better mechanism
if metadata[:capture_example]
example = metadata[:swagger_data][:example] = {}
end
before do |example|
method = example.metadata[:swagger_data][:operation]
path = resolve_path(example.metadata[:swagger_data][:path], self)
......@@ -119,15 +114,18 @@ paths: (Paths)
[path, params, headers]
end
# Run the request
self.send(method, *args)
# TODO fix the naming collision
# if example
# example.merge!(body: response.body, content_type: response.content_type.to_s)
# end
if example.metadata[:capture_example]
example.metadata[:swagger_data][:example] = {
body: response.body,
content_type: response.content_type.to_s
}
end
end
it("matches", { swagger_object: :response }) do
it("returns the correct status code", { swagger_object: :response }) do
expect(response).to have_http_status(status_code)
end
end
......@@ -140,17 +138,20 @@ paths: (Paths)
end
end
module Common
module Resolver
def resolve_params swagger_data, group_instance
params = swagger_data[:params].values
# TODO resolve $refs
# TODO there should only be one body param
# TODO there should not be both body and formData params
swagger_data[:params].values.map do |p|
params.map do |p|
p.slice(:name, :in).merge(value: group_instance.send(p[:name]))
end
end
def resolve_path template, group_instance
# Should check that the parameter is actually defined before trying
# fetch a value?
template.gsub(/(\{.*?\})/){|match| group_instance.send(match[1...-1]) }
end
end
......
......@@ -8,8 +8,16 @@ RSpec.describe "Requestsing", type: :request do
end
operation "POST", "create" do
# params
parameter "body", in: :body
let(:body) { { post: { title: 'asdf', body: "blah" } } }
# TODO: it should pull the body from the params
response(201, "successfully created", { post: { title: 'asdf', body: "blah" } }.to_json, {'CONTENT_TYPE' => 'application/json', 'HTTP_ACCEPT' => 'application/json'}) do
it "uses the body we passed in" do
post = JSON.parse(response.body)
expect(post["title"]).to eq('asdf')
expect(post["body"]).to eq('blah')
end
capture_example
end
end
......
......@@ -83,7 +83,7 @@ RSpec.describe RSpec::Swagger::Helpers::Operation do
end
RSpec.describe RSpec::Swagger::Helpers::Common do
RSpec.describe RSpec::Swagger::Helpers::Resolver do
# Tthis helper is an include rather than an extend we can get it pulled into
# the test just by matching the filter metadata.
describe("#resolve_params", swagger_object: :something) do
......
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