Commit d2c108e3 by andrew morton

Write JSON to disk

Fixes #1
parent e95d89af
...@@ -16,9 +16,9 @@ module RSpec ...@@ -16,9 +16,9 @@ module RSpec
metadata = notification.example.metadata metadata = notification.example.metadata
return unless metadata[:swagger_object] == :response return unless metadata[:swagger_object] == :response
metadata.each do |k, v| # metadata.each do |k, v|
puts "#{k}\t#{v}" if k.to_s.starts_with?("swagger") # puts "#{k}\t#{v}" if k.to_s.starts_with?("swagger")
end # end
document = document_for(metadata[:swagger_document]) document = document_for(metadata[:swagger_document])
path_item = path_item_for(document, metadata[:swagger_path_item]) path_item = path_item_for(document, metadata[:swagger_path_item])
...@@ -31,7 +31,12 @@ module RSpec ...@@ -31,7 +31,12 @@ module RSpec
end end
def write_json(name, document) def write_json(name, document)
puts JSON.pretty_generate(document) root = ::RSpec.configuration.swagger_root
# It would be good to at least warn if the name includes some '../' that
# takes it out of root directory.
target = Pathname(name).expand_path(root)
target.dirname.mkpath
target.write(JSON.pretty_generate(document))
end end
def document_for(doc_name = nil) def document_for(doc_name = nil)
......
...@@ -197,6 +197,8 @@ module RSpec ...@@ -197,6 +197,8 @@ module RSpec
module Resolver module Resolver
def resolve_document metadata def resolve_document metadata
# TODO: It's really inefficient to keep recreating this. It'd be nice
# if we could cache them some place.
name = metadata[:swagger_document] name = metadata[:swagger_document]
Document.new(RSpec.configuration.swagger_docs[name]) Document.new(RSpec.configuration.swagger_docs[name])
end end
......
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