templates/api/fulldoc/json/setup.rb in yard-api-0.3.7 vs templates/api/fulldoc/json/setup.rb in yard-api-1.0.0

- old
+ new

@@ -53,20 +53,35 @@ schema_tags = schema.map do |(prop_name, prop)| is_required = prop.has_key?('required') ? prop['required'] : false is_required_str = is_required ? 'Required' : 'Optional' - ArgumentTag.new(nil, "[#{is_required_str}, #{prop['type']}] #{prop_name}\n #{prop['description']}") + { + "name" => prop_name, + "types" => Array(prop["type"]), + "is_required" => !!prop["required"], + "text" => prop.fetch('description', ''), + "example" => prop['example'], + "accepted_values" => Array( + first_in([ + "accepted values", + "accepted_values", + "accepts", + "accepted", + "acceptable values", + ], prop) + ) + } end { id: topicize("#{obj.object.path}::#{title}"), scoped_id: topicize(title), title: title, text: spec['description'] || '', controller: obj.object.path, - schema: schema_tags.as_json.map { |e| e.delete('tag_name'); e } + schema: schema_tags } end def dump_endpoint(endpoint) title = endpoint.tag(:API).text @@ -124,5 +139,9 @@ path: route.path.spec.to_s.gsub("(.:format)", ""), verb: verb } end end + +def first_in(keys, obj) + obj[keys.detect { |k| obj.key?(k) }] +end \ No newline at end of file