From: Michal Fojtik <[email protected]>

Signed-off-by: Michal fojtik <[email protected]>
---
 server/lib/sinatra/rabbit.rb          |    7 ++++++-
 server/views/api/constraints.xml.haml |   24 ++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletions(-)
 create mode 100644 server/views/api/constraints.xml.haml

diff --git a/server/lib/sinatra/rabbit.rb b/server/lib/sinatra/rabbit.rb
index 5c1d757..007ba2f 100644
--- a/server/lib/sinatra/rabbit.rb
+++ b/server/lib/sinatra/rabbit.rb
@@ -221,7 +221,12 @@ module Sinatra
         
::Sinatra::Application.options("#{Sinatra::UrlForHelper::DEFAULT_URI_PREFIX}/#{name}")
 do
           operations_allowed = current_collection.operations.collect { |o| 
o[0] }.join(',')
           headers 'X-Operations-Allowed' => operations_allowed
-          [200, '']
+          @collection = current_collection
+          @operations = @collection.operations
+          @features = driver.features(@collection.name)
+          respond_to do |format|
+            format.xml { haml :'api/constraints'}
+          end
         end
       end
 
diff --git a/server/views/api/constraints.xml.haml 
b/server/views/api/constraints.xml.haml
new file mode 100644
index 0000000..b045f58
--- /dev/null
+++ b/server/views/api/constraints.xml.haml
@@ -0,0 +1,24 @@
+%api{ :driver => driver_symbol, :version => settings.version }
+  %collection{ :name => @collection.name.to_s }
+    - @operations.keys.sort_by { |k| k.to_s }.each do |operation|
+      %operation{ :url => api_url_for(@collection.name.to_s), :name => 
operation, :href => api_url_for(@operations[operation].path), :method => 
@operations[operation].method }
+        - @operations[operation].params.each do |param_name, param|
+          %param{ :name => param_name }
+            - unless param.description.empty?
+              %description=cdata(param.description)
+            %constraint{ :name => :type, :value => param.klass }
+            %constraint{ :name => :required, :value => (param.type == 
:required) ? 'true' : 'false' }
+            - unless param.options.empty?
+              %constraint{ :name => :options}
+                - param.options.each do |option|
+                  %option=option
+        - for feature in driver.features(@collection.name.to_sym)
+          - feature.operations.select { |o| o.name == operation }.each do |op|
+            - op.params.each do |param_name, param|
+              %param{ :name => param_name, :feature => feature.name }
+                - unless param.description.empty?
+                  %description=cdata(param.description)
+                %constraint{ :name => :type, :value => param.klass }
+                %constraint{ :name => :required, :value => (param.type == 
:required) ? 'true' : 'false' }
+                - for name, value in feature.constraints
+                  %constraint{ :name => name, :value => value }
-- 
1.7.4.1

Reply via email to