api_canon 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/api_canon/swagger/api_declaration.rb +14 -10
- data/lib/api_canon/version.rb +1 -1
- data/spec/lib/api_canon/documented_param_spec.rb +1 -1
- data/spec/lib/api_canon/swagger_spec/api_declaration_spec.rb +25 -13
- data/spec/lib/api_canon/swagger_spec/resource_listing_spec.rb +1 -1
- data/spec/lib/api_canon_spec.rb +1 -1
- data/spec/spec_helper.rb +7 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d498b5e331019ba5f31d82115085133721d4f36
|
4
|
+
data.tar.gz: 6c1c378ae8a3f3cdeaafa03cd8d5c373b5616021
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e9a3b40c35abee15e7cf22c876e71c2c95c9e790663701fb5bcaefcfa3355b73162d2c21b18ea6f79cb0e4b976a0bffff63931089f7e1f59a5580a78a3a188f
|
7
|
+
data.tar.gz: bb08a61bb7518a3e2790677eb63056e1a015a6219163892da508d975ee7d609be143add968997b8126f530c06abf016e54d028ad8b81a176526ee21e95131970
|
data/README.md
CHANGED
@@ -134,12 +134,12 @@ Right now, api_canon is changing a lot. I plan to support the following feature
|
|
134
134
|
|
135
135
|
1. Response codes - describe what you mean when you send back a 200, a 201, 403 etc.
|
136
136
|
2. Support API tokens or other authentication to allow users to edit data live, with non-GET requests.
|
137
|
-
3. Swagger API output (optional)
|
138
137
|
4. You will need to route the index action for each documented controller until such point as I provide an alternative means of getting at this documentation.
|
139
138
|
|
140
139
|
## Contributors
|
141
140
|
[Cameron Walsh](http://github.com/cwalsh)
|
142
141
|
[Leon Dewey](http://github.com/leondewey)
|
142
|
+
[Ben Tillman](http://github.com/warp)
|
143
143
|
|
144
144
|
## Contributions
|
145
145
|
1. Fork project
|
@@ -13,6 +13,16 @@ module ApiCanon
|
|
13
13
|
attributes :operations
|
14
14
|
|
15
15
|
def path
|
16
|
+
url = URI.unescape url_for(url_params)
|
17
|
+
|
18
|
+
# This is required because we dont know if the params are
|
19
|
+
# path params or query params, this way we dont care.
|
20
|
+
url = url.split('?').first
|
21
|
+
|
22
|
+
"#{url}.{format}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def url_params
|
16
26
|
url_params = {
|
17
27
|
:controller => object.controller_name,
|
18
28
|
:action => object.action_name,
|
@@ -20,16 +30,10 @@ module ApiCanon
|
|
20
30
|
}
|
21
31
|
|
22
32
|
object.params.keys.each do |name|
|
23
|
-
url_params[name] =
|
33
|
+
url_params[name] = "{#{name}}" unless name == :format
|
24
34
|
end
|
25
35
|
|
26
|
-
|
27
|
-
|
28
|
-
# This is required because we dont know if the params are
|
29
|
-
# path params or query params, this way we dont care.
|
30
|
-
url = url.split('?').first
|
31
|
-
|
32
|
-
"#{url}.{format}"
|
36
|
+
url_params
|
33
37
|
end
|
34
38
|
|
35
39
|
def operations
|
@@ -87,7 +91,7 @@ module ApiCanon
|
|
87
91
|
|
88
92
|
def param_type
|
89
93
|
# TODO: Tighten this up.
|
90
|
-
if object.name == 'id'
|
94
|
+
if object.name.to_s == 'id'
|
91
95
|
"path"
|
92
96
|
elsif %(POST PUT).include?(object.documented_action.http_method)
|
93
97
|
"form"
|
@@ -130,4 +134,4 @@ module ApiCanon
|
|
130
134
|
|
131
135
|
end
|
132
136
|
end
|
133
|
-
end
|
137
|
+
end
|
data/lib/api_canon/version.rb
CHANGED
@@ -4,7 +4,7 @@ describe ApiCanon::DocumentedParam do
|
|
4
4
|
let(:doc_opts) do
|
5
5
|
{:type => 'string', :default => :json, :example_values => example_values}
|
6
6
|
end
|
7
|
-
let(:fake_form) {
|
7
|
+
let(:fake_form) { double :form }
|
8
8
|
let(:doco_prefix) { 'foo' }
|
9
9
|
let(:documented_param) {ApiCanon::DocumentedParam.new :format, self, doc_opts}
|
10
10
|
subject { documented_param }
|
@@ -1,23 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe ApiCanon::Swagger::ApiDeclaration do
|
3
3
|
|
4
|
+
let(:documented_action) {
|
5
|
+
documented_action = ApiCanon::DocumentedAction.new('action_name', 'controller_name')
|
6
|
+
documented_action.describe 'description'
|
7
|
+
documented_action.response_code '404', 'reason'
|
8
|
+
documented_action.param 'name', :description => 'description', :type => 'string', :values => (1..10)
|
9
|
+
documented_action
|
10
|
+
}
|
4
11
|
let(:data) {
|
5
|
-
documented_actions
|
6
|
-
documented_actions.describe 'description'
|
7
|
-
documented_actions.response_code '404', 'reason'
|
8
|
-
documented_actions.param 'name', :description => 'description', :type => 'string', :values => (1..10)
|
9
|
-
mock :documented_actions => [ documented_actions ], :version => 'master'
|
12
|
+
double :documented_actions => [ documented_action ], :version => 'master'
|
10
13
|
}
|
11
|
-
subject {
|
12
|
-
|
14
|
+
subject { described_class.new(data) }
|
13
15
|
|
14
16
|
it 'should render the swagger api declaration' do
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
described_class.any_instance.stub :api_canon_test_url => 'http://example.com/api_canon/test'
|
18
|
+
described_class.any_instance.stub :api_canon_test_path => '/api_canon/test'
|
19
|
+
described_class.any_instance.stub :swagger_path => 'swagger_path'
|
18
20
|
ApiCanon::Swagger::ApiDeclaration::Api.any_instance.stub :url_for => 'url_for'
|
19
21
|
|
20
|
-
|
22
|
+
subject.to_json.should be_json_eql({
|
21
23
|
"apiVersion" => "master",
|
22
24
|
"basePath" => 'http://example.com/',
|
23
25
|
"swaggerVersion" => 1.1,
|
@@ -34,7 +36,7 @@ describe ApiCanon::Swagger::ApiDeclaration do
|
|
34
36
|
{
|
35
37
|
"paramType" => "query",
|
36
38
|
"dataType" => "string",
|
37
|
-
"allowableValues"=>{"max"=>10, "min"=>1, "valueType"=>"RANGE"},
|
39
|
+
"allowableValues" => {"max"=>10, "min"=>1, "valueType"=>"RANGE"},
|
38
40
|
"allowMultiple" => false,
|
39
41
|
"name" => "name",
|
40
42
|
"description" => 'description',
|
@@ -46,7 +48,17 @@ describe ApiCanon::Swagger::ApiDeclaration do
|
|
46
48
|
]
|
47
49
|
}
|
48
50
|
]
|
49
|
-
})
|
51
|
+
}.to_json)
|
50
52
|
end
|
51
53
|
|
54
|
+
describe ApiCanon::Swagger::ApiDeclaration::Api do
|
55
|
+
subject { ApiCanon::Swagger::ApiDeclaration::Api.new(documented_action) }
|
56
|
+
|
57
|
+
describe '#url_params' do
|
58
|
+
it 'should return params with placeholder values' do
|
59
|
+
documented_action.param 'id', :type => 'string'
|
60
|
+
subject.url_params['id'].should eql("{id}")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
52
64
|
end
|
data/spec/lib/api_canon_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe ApiCanon do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "document_method" do
|
20
|
-
let(:api_document) {
|
20
|
+
let(:api_document) { double :api_document }
|
21
21
|
context "without a current controller doc" do
|
22
22
|
it "creates and stores a new ApiCanon::Document and adds the documented action" do
|
23
23
|
ApiCanon::Document.should_receive(:new).with('fake', 'fake').and_return(api_document)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_canon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Walsh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -67,6 +67,20 @@ dependencies:
|
|
67
67
|
- - '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: json_spec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
70
84
|
- !ruby/object:Gem::Dependency
|
71
85
|
name: rake
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|