line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package APISchema::Generator::Markdown; |
2
|
2
|
|
|
2
|
|
2979
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
54
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# lib |
6
|
2
|
|
|
2
|
|
717
|
use APISchema::Generator::Markdown::Formatter; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
169
|
|
7
|
2
|
|
|
2
|
|
757
|
use APISchema::Generator::Markdown::ExampleFormatter; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
72
|
|
8
|
2
|
|
|
2
|
|
723
|
use APISchema::Generator::Markdown::ResourceResolver; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# cpan |
11
|
2
|
|
|
2
|
|
536
|
use Text::MicroTemplate::DataSection qw(); |
|
2
|
|
|
|
|
18978
|
|
|
2
|
|
|
|
|
1032
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
12
|
|
|
12
|
0
|
4625
|
my ($class) = @_; |
15
|
|
|
|
|
|
|
|
16
|
12
|
|
|
|
|
81
|
my $renderer = Text::MicroTemplate::DataSection->new( |
17
|
|
|
|
|
|
|
escape_func => undef |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
bless { |
20
|
|
|
|
|
|
|
renderer => $renderer, |
21
|
|
|
|
|
|
|
map { |
22
|
12
|
|
|
|
|
999
|
( $_ => $renderer->build_file($_) ); |
|
96
|
|
|
|
|
155754
|
|
23
|
|
|
|
|
|
|
} qw(index toc route resource request response |
24
|
|
|
|
|
|
|
request_example response_example), |
25
|
|
|
|
|
|
|
}, $class; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub resolve_encoding ($) { |
29
|
19
|
|
|
19
|
0
|
72
|
my ($resources) = @_; |
30
|
19
|
100
|
|
|
|
61
|
$resources = { body => $resources } unless ref $resources; |
31
|
19
|
|
100
|
|
|
112
|
my $encoding = $resources->{encoding} // { '' => 'auto' }; |
32
|
19
|
100
|
|
|
|
43
|
$encoding = { '' => $encoding } unless ref $encoding; |
33
|
19
|
|
|
|
|
117
|
return { %$resources, encoding => $encoding }; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub format_schema { |
37
|
11
|
|
|
11
|
0
|
9099
|
my ($self, $schema) = @_; |
38
|
|
|
|
|
|
|
|
39
|
11
|
|
|
|
|
35
|
my $renderer = $self->{renderer}; |
40
|
11
|
|
|
|
|
53
|
my $routes = $schema->get_routes; |
41
|
11
|
|
|
|
|
44
|
my $resources = $schema->get_resources; |
42
|
|
|
|
|
|
|
|
43
|
11
|
|
|
|
|
84
|
my $root = $schema->get_resource_root; |
44
|
11
|
|
|
|
|
163
|
my $resolver = APISchema::Generator::Markdown::ResourceResolver->new( |
45
|
|
|
|
|
|
|
schema => $root, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
return $self->{index}->( |
48
|
|
|
|
|
|
|
$renderer, |
49
|
|
|
|
|
|
|
$schema, |
50
|
|
|
|
|
|
|
$self->{toc}->( |
51
|
|
|
|
|
|
|
$renderer, |
52
|
|
|
|
|
|
|
$routes, |
53
|
|
|
|
|
|
|
$resources, |
54
|
|
|
|
|
|
|
), |
55
|
|
|
|
|
|
|
join('', map { |
56
|
9
|
|
|
|
|
822
|
my $route = $_; |
57
|
9
|
|
|
|
|
29
|
my $req = resolve_encoding($route->request_resource); |
58
|
9
|
|
|
|
|
44
|
my $request_resource = $route->canonical_request_resource($root); |
59
|
|
|
|
|
|
|
|
60
|
9
|
|
|
|
|
106
|
my $codes = $route->responsible_codes; |
61
|
9
|
|
|
|
|
28
|
my $default_code = $route->default_responsible_code; |
62
|
9
|
|
|
|
|
32
|
my $response_resource = $route->canonical_response_resource($root, [ |
63
|
|
|
|
|
|
|
$default_code |
64
|
|
|
|
|
|
|
]); |
65
|
|
|
|
|
|
|
|
66
|
9
|
|
|
|
|
98
|
my $res = $_->response_resource; |
67
|
|
|
|
|
|
|
$res = $_->responsible_code_is_specified |
68
|
9
|
100
|
|
|
|
42
|
? { map { $_ => resolve_encoding($res->{$_}) } @$codes } |
|
2
|
|
|
|
|
6
|
|
69
|
|
|
|
|
|
|
: { '' => resolve_encoding($res) }; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$self->{route}->( |
72
|
|
|
|
|
|
|
$renderer, |
73
|
|
|
|
|
|
|
$route, |
74
|
|
|
|
|
|
|
{ |
75
|
|
|
|
|
|
|
req => $self->{request_example}->( |
76
|
|
|
|
|
|
|
$renderer, |
77
|
|
|
|
|
|
|
$route, |
78
|
|
|
|
|
|
|
APISchema::Generator::Markdown::ExampleFormatter->new( |
79
|
|
|
|
|
|
|
resolver => $resolver, |
80
|
|
|
|
|
|
|
spec => $request_resource, |
81
|
|
|
|
|
|
|
), |
82
|
|
|
|
|
|
|
), |
83
|
|
|
|
|
|
|
res => $self->{response_example}->( |
84
|
|
|
|
|
|
|
$renderer, |
85
|
|
|
|
|
|
|
$route, |
86
|
|
|
|
|
|
|
$default_code, |
87
|
|
|
|
|
|
|
APISchema::Generator::Markdown::ExampleFormatter->new( |
88
|
|
|
|
|
|
|
resolver => $resolver, |
89
|
|
|
|
|
|
|
spec => $response_resource, |
90
|
|
|
|
|
|
|
), |
91
|
|
|
|
|
|
|
), |
92
|
|
|
|
|
|
|
}, |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
req => $self->{request}->($renderer, $route, $req), |
95
|
|
|
|
|
|
|
res => join("\n", map { |
96
|
9
|
|
|
|
|
62
|
$self->{response}->($renderer, $route, $_, $res->{$_}); |
|
10
|
|
|
|
|
434
|
|
97
|
|
|
|
|
|
|
} sort keys %$res), |
98
|
|
|
|
|
|
|
}, |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
} @$routes), |
101
|
|
|
|
|
|
|
join('', map { |
102
|
19
|
|
|
|
|
379
|
my $properties = $resolver->properties($_->definition); |
103
|
19
|
|
|
|
|
90
|
$self->{resource}->($renderer, $resolver, $_, [ map { +{ |
104
|
|
|
|
|
|
|
path => $_, |
105
|
41
|
|
|
|
|
525
|
definition => $properties->{$_}, |
106
|
|
|
|
|
|
|
} } sort keys %$properties ]); |
107
|
|
|
|
|
|
|
} grep { |
108
|
11
|
|
100
|
|
|
354
|
( $_->definition->{type} // '' ) ne 'hidden'; |
|
19
|
|
|
|
|
1368
|
|
109
|
|
|
|
|
|
|
} @$resources), |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
__DATA__ |