spec/diesel/swagger/parser_spec.rb in diesel-api-dsl-0.1.0 vs spec/diesel/swagger/parser_spec.rb in diesel-api-dsl-0.1.1

- old
+ new

@@ -2,16 +2,16 @@ require 'diesel/swagger/parser' describe Diesel::Swagger::Parser do subject { Diesel::Swagger::Parser } - let(:specification_json) do - File.read(File.join(File.dirname(__FILE__), '..', '..', 'files', 'pivotal_tracker.json')) + def load_spec(name) + File.read(File.join(File.dirname(__FILE__), '..', '..', 'files', "#{name}.json")) end - it "should parse a diesel specification" do - specification = Diesel::Swagger::Parser.new.parse(specification_json) + it "should parse a swagger specification" do + specification = Diesel::Swagger::Parser.new.parse(load_spec('pivotal_tracker')) expect(specification).to_not be_nil expect(specification.host).to eq "www.pivotaltracker.com" expect(specification.schemes).to include "https" expect(specification.base_path).to eq "/services/v5" @@ -21,13 +21,16 @@ expect(specification.info.version).to eq "5" api_token = specification.security_definitions['apiToken'] expect(api_token).to_not be_nil expect(api_token.type).to eq "apiKey" - expect(api_token.in).to eq "header" + expect(api_token.in).to eq :header expect(api_token.name).to eq "X-TrackerToken" + security = specification.security['apiToken'] + expect(security).to_not be_nil + expect(specification.produces).to include "application/json" expect(specification.paths.count).to eq 1 path = specification.paths["/projects/{projectId}/stories"] @@ -46,11 +49,11 @@ expect(param1).to be_required param2 = path.post.parameters[1] expect(param2).to_not be_nil expect(param2.in).to eq :body - expect(param2.name).to eq "body" + expect(param2.name).to eq "story" expect(param2).to be_required expect(param2.schema).to eq "NewStory" expect(specification.definitions.count).to eq 1 @@ -74,7 +77,17 @@ "started", "rejected", "unstarted", "unscheduled" ] + end + + it "should parse a swagger specification with an array of schema objects" do + specification = Diesel::Swagger::Parser.new.parse(load_spec('slack')) + payload = specification.definitions["Payload"] + + attachments_prop = payload.properties['attachments'] + expect(attachments_prop.type).to eq :array + expect(attachments_prop.items.count).to eq 1 + expect(attachments_prop.items["$ref"]).to eq '#/definitions/Attachment' end end