api_canon 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d498b5e331019ba5f31d82115085133721d4f36
4
- data.tar.gz: 6c1c378ae8a3f3cdeaafa03cd8d5c373b5616021
3
+ metadata.gz: 5ae973a42fab02db3f846d289447747a5cb35460
4
+ data.tar.gz: 963a6ebde8bd3d854afbb64ff694e43fd20c4343
5
5
  SHA512:
6
- metadata.gz: 1e9a3b40c35abee15e7cf22c876e71c2c95c9e790663701fb5bcaefcfa3355b73162d2c21b18ea6f79cb0e4b976a0bffff63931089f7e1f59a5580a78a3a188f
7
- data.tar.gz: bb08a61bb7518a3e2790677eb63056e1a015a6219163892da508d975ee7d609be143add968997b8126f530c06abf016e54d028ad8b81a176526ee21e95131970
6
+ metadata.gz: f2b597c23d3dfaa4daca2351c242123008ac3985488ab97abfd27adda7d9b2a93cce84ba3964613f9f3a0ffcc68022a49ee6a0306bfdfd9804e4e12825d8b846
7
+ data.tar.gz: f302da8afcc840853dabee58982860f19c9dac85571275f113cb37212435eb76274ce1fefffad43a7ddf0db7fa91aaa34444e0efd10d090ee8c7056b5640940b
data/README.md CHANGED
@@ -119,7 +119,7 @@ class FunkyCategoriesController < ApplicationController
119
119
  document_method :show do
120
120
  describe %Q{This action returns a tree of categories starting at the
121
121
  requested root node.}
122
- param :id, :type => :string,:default => 'mens-fashion-accessories',
122
+ param :id, :type => :string, :default => 'mens-fashion-accessories',
123
123
  :example_values => Category.limit(5).pluck(:code),
124
124
  :description => "Category code to show, the root node for the entire tree."
125
125
  end
@@ -137,9 +137,9 @@ Right now, api_canon is changing a lot. I plan to support the following feature
137
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.
138
138
 
139
139
  ## Contributors
140
- [Cameron Walsh](http://github.com/cwalsh)
141
- [Leon Dewey](http://github.com/leondewey)
142
- [Ben Tillman](http://github.com/warp)
140
+ * [Cameron Walsh](http://github.com/cwalsh)
141
+ * [Leon Dewey](http://github.com/leondewey)
142
+ * [Ben Tillman](http://github.com/warp)
143
143
 
144
144
  ## Contributions
145
145
  1. Fork project
@@ -1,8 +1,9 @@
1
1
  module ApiCanon
2
2
  class DocumentedParam
3
3
  include ActiveModel::Serialization
4
- attr_accessor :name, :values, :type, :default, :description, :example_values, :required, :description, :documented_action
4
+ attr_accessor :name, :values, :type, :param_type, :default, :description, :example_values, :required, :description, :documented_action
5
5
  attr_writer :multiple
6
+ delegate :http_method, :to => :documented_action
6
7
  include ActionView::Helpers
7
8
  def values_for_example
8
9
  example_values || values || ""
@@ -17,9 +17,7 @@ module ApiCanon
17
17
 
18
18
  # This is required because we dont know if the params are
19
19
  # path params or query params, this way we dont care.
20
- url = url.split('?').first
21
-
22
- "#{url}.{format}"
20
+ url.split('?').first
23
21
  end
24
22
 
25
23
  def url_params
@@ -30,7 +28,7 @@ module ApiCanon
30
28
  }
31
29
 
32
30
  object.params.keys.each do |name|
33
- url_params[name] = "{#{name}}" unless name == :format
31
+ url_params[name] = "{#{name}}"
34
32
  end
35
33
 
36
34
  url_params
@@ -84,16 +82,18 @@ module ApiCanon
84
82
  self.root = false
85
83
  attributes :param_type => :paramType,
86
84
  :data_type => :dataType,
85
+ :default => :defaultValue,
87
86
  :allowable_values => :allowableValues,
88
87
  :allow_multiple => :allowMultiple
89
88
 
90
89
  attributes :name, :description, :required
91
90
 
92
91
  def param_type
93
- # TODO: Tighten this up.
94
- if object.name.to_s == 'id'
92
+ if object.param_type.present?
93
+ object.param_type
94
+ elsif object.name.to_s == 'id'
95
95
  "path"
96
- elsif %(POST PUT).include?(object.documented_action.http_method)
96
+ elsif %(POST PUT).include?(object.http_method)
97
97
  "form"
98
98
  else
99
99
  "query"
@@ -1,3 +1,3 @@
1
1
  module ApiCanon
2
- VERSION = '0.4.4'
2
+ VERSION = '0.4.5'
3
3
  end
@@ -5,7 +5,7 @@ describe ApiCanon::Swagger::ApiDeclaration do
5
5
  documented_action = ApiCanon::DocumentedAction.new('action_name', 'controller_name')
6
6
  documented_action.describe 'description'
7
7
  documented_action.response_code '404', 'reason'
8
- documented_action.param 'name', :description => 'description', :type => 'string', :values => (1..10)
8
+ documented_action.param 'name', :description => 'description', :type => 'string', :default => 'test', :values => (1..10)
9
9
  documented_action
10
10
  }
11
11
  let(:data) {
@@ -25,7 +25,7 @@ describe ApiCanon::Swagger::ApiDeclaration do
25
25
  "swaggerVersion" => 1.1,
26
26
  "apis" => [
27
27
  {
28
- "path" => "url_for.{format}",
28
+ "path" => "url_for",
29
29
  "description" => 'description',
30
30
  "operations" => [
31
31
  {
@@ -36,7 +36,8 @@ describe ApiCanon::Swagger::ApiDeclaration do
36
36
  {
37
37
  "paramType" => "query",
38
38
  "dataType" => "string",
39
- "allowableValues" => {"max"=>10, "min"=>1, "valueType"=>"RANGE"},
39
+ "defaultValue" => "test",
40
+ "allowableValues" => {"max" => 10, "min" => 1, "valueType" => "RANGE"},
40
41
  "allowMultiple" => false,
41
42
  "name" => "name",
42
43
  "description" => 'description',
@@ -51,7 +52,7 @@ describe ApiCanon::Swagger::ApiDeclaration do
51
52
  }.to_json)
52
53
  end
53
54
 
54
- describe ApiCanon::Swagger::ApiDeclaration::Api do
55
+ describe '::Api' do
55
56
  subject { ApiCanon::Swagger::ApiDeclaration::Api.new(documented_action) }
56
57
 
57
58
  describe '#url_params' do
@@ -60,5 +61,44 @@ describe ApiCanon::Swagger::ApiDeclaration do
60
61
  subject.url_params['id'].should eql("{id}")
61
62
  end
62
63
  end
64
+
65
+ describe '::Parameter' do
66
+ subject { ApiCanon::Swagger::ApiDeclaration::Api::Operation::Parameter.new(param) }
67
+
68
+ describe '#param_type' do
69
+
70
+ describe 'with param_type path' do
71
+ let(:param) { double :param_type => 'path' }
72
+
73
+ it 'should return path' do
74
+ subject.param_type.should eql('path')
75
+ end
76
+ end
77
+
78
+ describe 'with name id' do
79
+ let(:param) { double :param_type => nil, :name => 'id' }
80
+
81
+ it 'should return path' do
82
+ subject.param_type.should eql('path')
83
+ end
84
+ end
85
+
86
+ describe 'with POST http_method' do
87
+ let(:param) { double :param_type => nil, :name => 'name', :http_method => 'POST' }
88
+
89
+ it 'should return path' do
90
+ subject.param_type.should eql('form')
91
+ end
92
+ end
93
+
94
+ describe 'with GET http_method' do
95
+ let(:param) { double :param_type => nil, :name => 'name', :http_method => 'GET' }
96
+
97
+ it 'should return query' do
98
+ subject.param_type.should eql('query')
99
+ end
100
+ end
101
+ end
102
+ end
63
103
  end
64
104
  end
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
4
+ version: 0.4.5
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-19 00:00:00.000000000 Z
12
+ date: 2013-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails