@@ -12,27 +12,33 @@ def sections
1212 attrs = fields ( :attributes , examples )
1313 params = fields ( :parameters , examples )
1414
15- methods = examples . group_by ( &:http_method ) . map do |http_method , examples |
16- {
17- http_method : http_method ,
18- description : examples . first . respond_to? ( :action_name ) && examples . first . action_name ,
19- examples : examples
20- }
21- end
15+ methods = examples
16+ . group_by { |e | "#{ e . http_method } - #{ e . action_name } " }
17+ . map do |group , examples |
18+ first_example = examples . first
19+
20+ {
21+ http_method : first_example . try ( :http_method ) ,
22+ description : first_example . try ( :action_name ) ,
23+ explanation : first_example . try ( :[] , :metadata ) . try ( :[] , :method_explanation ) ,
24+ examples : examples
25+ }
26+ end
2227
2328 {
2429 "has_attributes?" . to_sym => attrs . size > 0 ,
2530 "has_parameters?" . to_sym => params . size > 0 ,
2631 route : format_route ( examples [ 0 ] ) ,
2732 route_name : examples [ 0 ] [ :route_name ] ,
33+ explanation : examples [ 0 ] [ :route_explanation ] ,
2834 attributes : attrs ,
2935 parameters : params ,
3036 http_methods : methods
3137 }
3238 end
3339
3440 section . merge ( {
35- routes : routes
41+ routes : @configuration . sort_routes ? routes . sort_by { | r | r [ :route_name ] } : routes
3642 } )
3743 end
3844 end
@@ -60,11 +66,10 @@ def format_route(example)
6066 # with all of its properties, like name, description, required.
6167 # {
6268 # required: true,
63- # example: "1",
6469 # type: "string",
6570 # name: "id",
6671 # description: "The id",
67- # properties_description: "required, string "
72+ # properties_description: "string, required "
6873 # }
6974 def fields ( property_name , examples )
7075 examples
@@ -74,8 +79,10 @@ def fields(property_name, examples)
7479 . uniq { |property | property [ :name ] }
7580 . map do |property |
7681 properties = [ ]
77- properties << "required" if property [ :required ]
7882 properties << property [ :type ] if property [ :type ]
83+ properties << "required" if property [ :required ] == true
84+ properties << "optional" if property [ :required ] . blank?
85+
7986 if properties . count > 0
8087 property [ :properties_description ] = properties . join ( ", " )
8188 else
0 commit comments