This file is indexed.

/usr/share/perl5/Swagger2/Editor.pm is in libswagger2-perl 0.73-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
package Swagger2::Editor;
use Mojo::Base 'Mojolicious';
use Mojo::Util;
use File::Basename;
use Swagger2;

has specification_file => sub { $ENV{SWAGGER_API_FILE} || '' };

has _swagger => sub { Swagger2->new };

sub _get {
  my $c = shift;

  $c->respond_to(
    txt => {data => $c->app->_swagger->pod->to_string, layout => undef},
    any => sub {
      my $c = shift;
      $c->stash(layout => undef) if $c->req->is_xhr;
      $c->render(template => 'editor');
    }
  );
}

sub _post {
  my $c    = shift;
  my $spec = $c->req->body || '{}';
  my $file = $c->app->specification_file;

  eval {
    my $s = Swagger2->new->parse($spec);
    Mojo::Util::spurt($spec, $file) if $file and -w $file;
    $c->render(text => $c->podify($s->pod), layout => undef);
  } or do {
    my $e = $@;
    $c->app->log->error($e);
    $e =~ s!^(Could not.*?:)\s+!$1\n\n!s;
    $e =~ s!\s+at \S+\.pm line \d\S+!!g;
    $c->render(template => 'error', error => $e);
  };
}

sub startup {
  my $self = shift;
  my $raw  = '';

  if (my $file = $self->specification_file) {
    $raw
      = $file =~ /^https?:/
      ? $self->ua->get($file)->res->body
      : Mojo::Util::slurp(File::Spec->catfile(split '/', $file));
    $self->_swagger->parse($raw, $file);
  }

  unshift @{$self->renderer->classes}, __PACKAGE__;
  unshift @{$self->static->paths}, File::Spec->catdir(File::Basename::dirname(__FILE__), 'public');

  $self->routes->get('/' => \&_get);
  $self->routes->post('/' => \&_post);
  $self->defaults(raw => $raw, swagger => $self->_swagger, layout => 'default');
  $self->plugin('PODRenderer');
  $self->helper(podify => \&_podify);
}

sub _podify {
  my ($c, $pod) = @_;
  my $dom = Mojo::DOM->new($c->pod_to_html($pod->to_string));
  my $ul  = '<ul>';
  my ($sub, @parts);

  for my $e ($dom->find('h1, h2')->each) {
    my $id     = $e->{id};
    my $text   = $e->all_text;
    my $anchor = $c->tag(a => href => "#$id", sub {$text});

    if ($e->type eq 'h1') {
      $ul .= '</ul>' if $sub;
      $sub = 0;
    }
    else {
      $ul .= '<ul>' unless $sub;
      $sub = 1;
    }

    $ul .= "<li>$anchor</li>";

    $e->content($c->link_to($text => Mojo::URL->new->fragment('toc'), id => $id));
  }

  $ul .= '</ul>' if $ul;

  return $c->b(qq(<div class="pod-container"><h1 id="toc">TABLE OF CONTENTS</h1>$ul$dom</div>));
}

$ENV{SWAGGER_LOAD_EDITOR} ? __PACKAGE__->new : 1;

__DATA__
@@ error.html.ep
% title "Error in specification";
<h2>Error in specification</h2>
<pre><%= $error %></pre>

@@ editor.html.ep
% title "Editor";
<div id="editor"><%= stash('raw') || '---' %></div>
<div id="resizer">&nbsp;</div>
<div id="preview"><%= podify $swagger->pod %></div>
% my $ace_url = $c->req->url->base->path->clone;
% push @{$ace_url->parts}, 'ace.js';
<script src="<%= $ace_url %>"></script>
%= javascript begin
(function(ace) {
  var localStorage = window.localStorage || {};
  var draggable = document.getElementById("resizer");
  var editor = document.getElementById("editor");
  var preview = document.getElementById("preview");
  var focusId = location.href.split("#")[1] || "";
  var initializing = true;
  var tid, xhr, i;

  var loaded = function() {
    if (initializing) {
      ace.focus();
      ace.gotoLine(2);
    }
    initializing = false;
    ace.session.setMode("ace/mode/" + (ace.getValue().match(/^\s*\{/) ? "json" : "yaml"));
    preview.scrollTop = scrollSave();
  };

  var render = function() {
    scrollSave();
    xhr = new XMLHttpRequest();
    xhr.open("POST", "<%= url_for("/") %>", true);
    xhr.onload = function() { preview.firstChild.innerHTML = xhr.responseText; loaded(); };
    localStorage["swagger-spec"] = ace.getValue();
    xhr.send(localStorage["swagger-spec"]);
  };

  var scrollSave = function() {
    var elem = document.getElementById(location.href.split("#")[1] || "toc");
    if (!elem) return 0;
    var last = scrollSave.last;
    scrollSave.last = preview.scrollTop || elem.offsetTop;
    return last || scrollSave.last;
  };

  ace.commands.addCommand({ bindKey: { win: "Ctrl-L", mac: "Command-L" }, command: "passKeysToBrowser" });
  ace.commands.addCommand({
    name: "find",
    bindKey: { win: "Ctrl-F", mac: "Command-F" },
    exec: function(editor) { editor.find(prompt("Find:", editor.getCopyText())); }
  });
  ace.setTheme("ace/theme/solarized_dark");
  ace.getSession().on("change", function(e) {
    if (initializing) return;
    if (tid) clearTimeout(tid);
    tid = setTimeout(render, 600);
  });

  if (!focusId) {
    location.href = location.href + "#toc";
  }

  if (focusId.indexOf("/") == 0) {
    xhr = new XMLHttpRequest();
    xhr.open("GET", focusId, true);
    xhr.onload = function() {
      if (!xhr.responseText.match(/^\s*(---|{)/)) return alert("Could not load specification from " + focusId);
      ace.setValue(xhr.responseText);
      render();
    };
    xhr.send(false);
    location.href = location.href.replace(/\#.*/, "#toc");
  }
  else if (localStorage["swagger-spec"]) {
    ace.setValue(localStorage["swagger-spec"]);
    render();
  }
  else {
    loaded();
  }

  var resize = function(width, done) {
    draggable.style.left = width + "px";
    editor.style.width = width + "px";
    preview.style.marginLeft = width + "px";
    if(done) ace.resize();
  };

  resize.x = false;
  resize.w = localStorage["swagger-editor-width"];

  if (resize.w) resize(resize.w, true);

  draggable.addEventListener("mousedown", function(e) { resize.x = e.clientX; resize.w = editor.offsetWidth; });
  window.addEventListener("resize", function(e) { if (resize.w > this.innerWidth) resize(this.innerWidth - 30, true); })
  window.addEventListener("mouseup", function(e) {
    if (resize.x === false) return;
    resize(resize.w + e.clientX - resize.x, true);
    resize.w = editor.offsetWidth;
    resize.x = false;
    localStorage["swagger-editor-width"] = resize.w;
  });
  window.addEventListener("mousemove", function(e) {
    if (resize.x === false) return;
    e.preventDefault();
    resize(resize.w + e.clientX - resize.x);
  });
})(ace.edit("editor"));
% end

@@ layouts/default.html.ep
<html>
<head>
  <title>Swagger2 - <%= title %></title>
  %= stylesheet begin
  html, body {
    background: #f5f5f5;
    font-family: sans-serif;
    font-size: 14px;
    color: #111;
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
  }
  a { color: #222; }
  p { margin: 0.5em 0; }
  h1, h2, h3 { padding: 0; margin: 1em 0 0 0; }
  h1 { font-size: 2em; }
  h2 { font-size: 1.5em; border-bottom: 1px solid #bbb; }
  h3 { font-size: 1.2em; }
  h4 { font-size: 1em; }
  h1 a, h2 a, h3 a, h4 a { text-decoration: none; }
  h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover { text-decoration: underline; }
  #editor, #resizer { position: fixed; top: 0; bottom: 0; }
  #editor {
    font-size: 14px;
    left: 0;
    width: 620px;
  }
  #resizer {
    border-left: 4px solid rgba(25, 63, 73, 0.99);
    left: 620px;
    width: 4px;
    cursor: ew-resize;
  }
  #preview { overflow: auto; margin-left: 620px; height: 100%; }
  #preview .pod-container { padding-left: 10px; padding-bottom: 100px; }
  #preview .link:hover { color: #679; cursor: pointer; }

  @media print {
    #editor, #resizer { display: none; }
    #preview { margin: 0; width: 100%; height: auto; }
    #preview .pod-container { padding: 0; }
  }
  % end
</head>
<body>
  %= content
</body>
</html>
1;

=encoding utf8

=head1 NAME

Swagger2::Editor - A WEB based Swagger2 API editor

=head1 DESCRIPTION

L<Swagger2::Editor> is a WEB based Swagger2 API editor.

=head1 SYNOPSIS

  $ mojo swagger2 edit /path/to/api.json --listen http://*:3000

=head1 ATTRIBUTES

=head2 specification_file

Returns path to swagger specification file. Defaults to
C<SWAGGER_API_FILE> environment variable.

=head1 ROUTES

=head2 GET /

Will render the editor and any Swagger specification given as input.

Can also just render the POD if requested as C</.txt> instead.

=head2 POST /

Will L<parse|Swagger/parse> the JSON/YAML in the HTTP body and render it as POD.

=head1 METHODS

=head2 startup

Used to set up the L</ROUTES>.

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2014-2015, Jan Henning Thorsen

This program is free software, you can redistribute it and/or modify it under
the terms of the Artistic License version 2.0.

=head1 AUTHOR

Jan Henning Thorsen - C<jhthorsen@cpan.org>

=cut