@@ -12,27 +12,33 @@ def sections
12
12
attrs = fields ( :attributes , examples )
13
13
params = fields ( :parameters , examples )
14
14
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
22
27
23
28
{
24
29
"has_attributes?" . to_sym => attrs . size > 0 ,
25
30
"has_parameters?" . to_sym => params . size > 0 ,
26
31
route : format_route ( examples [ 0 ] ) ,
27
32
route_name : examples [ 0 ] [ :route_name ] ,
33
+ explanation : examples [ 0 ] [ :route_explanation ] ,
28
34
attributes : attrs ,
29
35
parameters : params ,
30
36
http_methods : methods
31
37
}
32
38
end
33
39
34
40
section . merge ( {
35
- routes : routes
41
+ routes : @configuration . sort_routes ? routes . sort_by { | r | r [ :route_name ] } : routes
36
42
} )
37
43
end
38
44
end
@@ -60,11 +66,10 @@ def format_route(example)
60
66
# with all of its properties, like name, description, required.
61
67
# {
62
68
# required: true,
63
- # example: "1",
64
69
# type: "string",
65
70
# name: "id",
66
71
# description: "The id",
67
- # properties_description: "required, string "
72
+ # properties_description: "string, required "
68
73
# }
69
74
def fields ( property_name , examples )
70
75
examples
@@ -74,8 +79,10 @@ def fields(property_name, examples)
74
79
. uniq { |property | property [ :name ] }
75
80
. map do |property |
76
81
properties = [ ]
77
- properties << "required" if property [ :required ]
78
82
properties << property [ :type ] if property [ :type ]
83
+ properties << "required" if property [ :required ] == true
84
+ properties << "optional" if property [ :required ] . blank?
85
+
79
86
if properties . count > 0
80
87
property [ :properties_description ] = properties . join ( ", " )
81
88
else
0 commit comments