Permalink
Browse files

Add examples to waitFor and waiter resources

  • Loading branch information...
1 parent e166d8c commit c1a5d4cf5ec0f3a9f2b10d0bc0575847e0af852e @lsegal lsegal committed Feb 27, 2014
Showing with 24 additions and 4 deletions.
  1. +13 −4 doc-src/templates/api-versions/model_documentor.rb
  2. +11 −0 doc-src/templates/api-versions/plugin.rb
@@ -152,8 +152,19 @@ def shapes(rules)
end
def generate_example(klass, name, input)
+ ExampleShapeVisitor.new.example(klass, name, input)
+ end
+
+end
+
+class ExampleShapeVisitor
+ def initialize(required_only = false)
+ @required_only = required_only
+ end
+
+ def example(klass, name, input)
lines = []
- params = ExampleShapeVisitor.new.traverse(input)
+ params = traverse(input)
params_var = ""
if params.strip.length > 0
lines << "var params = " + params + ";"
@@ -166,9 +177,6 @@ def generate_example(klass, name, input)
lines.join("\n")
end
-end
-
-class ExampleShapeVisitor
def traverse(node)
if (meth = "visit_" + (node['type'] || 'string')) && respond_to?(meth)
return send(meth, node)
@@ -179,6 +187,7 @@ def traverse(node)
def visit_structure(node)
lines = ["{" + (node['required'] ? " // required" : "")]
node['members'].sort_by {|n, v| [v['required'] ? -1 : 1, n] }.each do |key, value|
+ next if @required_only && !value['required']
lines << " #{key}: " + indent(traverse(value), false) + "," +
(value['required'] && !%w(list map structure).include?(value['type']) ?
" // required" : "")
@@ -123,8 +123,19 @@ def add_waiters(service, klass, model)
@callback (see #{obj.operation.path})
@param (see #{obj.operation.path})
@return (see #{obj.operation.path})
+@see #{operation_name}
eof
+ waiter_ex = ExampleShapeVisitor.new(true).example(
+ service.name.to_s.downcase, 'waitFor', model['operations'][operation_name]['input'])
+ waiter_ex = waiter_ex.sub(/\.waitFor\(/, ".waitFor('#{name}', ")
+ obj.docstring.add_tag YARD::Tags::Tag.new(:example, waiter_ex, nil,
+ "Waiting for the #{name} state")
+ unless wait_for.docstring.tag(:example)
+ wait_for.docstring.add_tag YARD::Tags::Tag.new(:example, waiter_ex, nil,
+ "Waiting for the #{name} state")
+ end
+
wait_for.docstring.add_tag YARD::Tags::Tag.new(:waiter, "{#{obj.path}}")
end
end

0 comments on commit c1a5d4c

Please sign in to comment.