Skip to content

Commit 9f2d1e5

Browse files
committed
Merge pull request #67 from gwshaw/66-ignore-vendor-specific-tags
Ignore vendor specific tags in paths
2 parents 712f68f + 86d49e1 commit 9f2d1e5

File tree

6 files changed

+122
-115
lines changed

6 files changed

+122
-115
lines changed

apivore.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
22

33
Gem::Specification.new do |s|
44
s.name = 'apivore'
5-
s.version = '1.4.0'
5+
s.version = '1.4.1'
66
s.date = '2015-10-27'
77
s.summary = "Tests your API against its Swagger 2.0 spec"
88
s.description = "Tests your rails API using its Swagger description of end-points, models, and query parameters."

lib/apivore/swagger.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def base_path
2626

2727
def each_response(&block)
2828
paths.each do |path, path_data|
29+
next if vendor_specific_tag? path
2930
path_data.each do |verb, method_data|
3031
next if NONVERB_PATH_ITEMS.include?(verb)
3132
raise "No responses found in swagger for path '#{path}', method #{verb}: #{method_data.inspect}" if method_data.responses.nil?
@@ -39,5 +40,10 @@ def each_response(&block)
3940
end
4041
end
4142
end
43+
44+
def vendor_specific_tag? tag
45+
tag =~ /\Ax-.*/
46+
end
47+
4248
end
4349
end

spec/apivore_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe 'Apivore::Swagger' do
44

55
context 'with valid swagger 2.0 input' do
6-
let(:doc) { IO.read(File.join(File.dirname(__FILE__), "data", "sample2.0.json")) }
6+
let(:doc) { IO.read(File.join(File.dirname(__FILE__), "data", "01_sample2.0.json")) }
77
let(:swagger) { Apivore::Swagger.new(JSON.parse(doc)) }
88

99
subject { swagger }

spec/data/01_sample2.0.json

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"version": "testing",
5+
"title": "Example Centre Directory Service"
6+
},
7+
"host": "api.test.example.com",
8+
"basePath": "/api",
9+
"schemes": [
10+
"https"
11+
],
12+
"consumes": [
13+
"application/json"
14+
],
15+
"produces": [
16+
"application/json"
17+
],
18+
"paths": {
19+
"x-something": "Vendor Specific Tag",
20+
"/services.json": {
21+
"get": {
22+
"description": "Services available to shoppers.",
23+
"operationId": "Services#index",
24+
"responses": {
25+
"200": {
26+
"description": "service index response",
27+
"schema": {
28+
"type": "array",
29+
"items": {
30+
"$ref": "#/definitions/service"
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"post": {
37+
"description": "Creates a service.",
38+
"operationId": "Services#post",
39+
"responses": {
40+
"204": {
41+
"description": "Service created"
42+
}
43+
}
44+
}
45+
},
46+
"/services/{id}.json": {
47+
"parameters": [
48+
{
49+
"name": "id",
50+
"in": "path",
51+
"description": "Service identifier.",
52+
"required": true,
53+
"type": "integer"
54+
}
55+
],
56+
"get": {
57+
"description": "Returns a service.",
58+
"operationId": "Services#show",
59+
"responses": {
60+
"200": {
61+
"description": "show service response",
62+
"schema": {
63+
"$ref": "#/definitions/service"
64+
}
65+
}
66+
}
67+
},
68+
"put": {
69+
"description": "Update a service.",
70+
"operationId": "Services#put",
71+
"responses": {
72+
"204": {
73+
"description": "Service updated"
74+
}
75+
}
76+
},
77+
"delete": {
78+
"description": "Deletes a service.",
79+
"operationId": "Services#delete",
80+
"responses": {
81+
"204": {
82+
"description": "Service deleted"
83+
}
84+
}
85+
},
86+
"patch": {
87+
"description": "Patches a service.",
88+
"operationId": "Services#patch",
89+
"responses": {
90+
"204": {
91+
"description": "Service patched"
92+
}
93+
}
94+
}
95+
}
96+
},
97+
"definitions": {
98+
"service": {
99+
"type": "object",
100+
"required": [ "id" ],
101+
"properties": {
102+
"id": {
103+
"type": "integer",
104+
"description": "Service id"
105+
},
106+
"name": {
107+
"type": ["string", "null"],
108+
"description": "Service name"
109+
}
110+
}
111+
}
112+
}
113+
}

spec/data/sample2.0.json

Lines changed: 0 additions & 112 deletions
This file was deleted.

spec/fixtures/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def call(env)
3131
]
3232
case "#{method} #{path}"
3333
when "GET /swagger-doc.json"
34-
respond_with 200, File.read(File.expand_path("../../data/sample2.0.json", __FILE__))
34+
respond_with 200, File.read(File.expand_path("../../data/01_sample2.0.json", __FILE__))
3535
when "GET /api/services.json"
3636
respond_with 200, [{ id: 1, name: "hello world" }].to_json
3737
when "POST /api/services.json"

0 commit comments

Comments
 (0)