Debian Codegraph @

texmf-dist/source/latex/rest-api/rest-api.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2020 by Dennis Klein [email protected]
4 % ---------------------------------------------------------------------------
5 % This work may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.3
7 % of this license or (at your option) any later version.
8 % The latest version of this license is in
9 % http://www.latex-project.org/lppl.txt
10 % and version 1.3 or later is part of all distributions of LaTeX
11 % version 2008/05/04 or later.
12 %
13 % This work consists of the files rest-api.dtx and rest-api.ins
14 % and the derived filebase rest-api.sty.
15 %
16 % \fi
17 %
18 % \iffalse
19 %<*driver>
20 \ProvidesFile{rest-api.dtx}
21 %</driver>
22 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
23 %<package>\ProvidesPackage{rest-api}
24 %<*package>
25 [2020/12/04 v1.4 rest-api package]
26 %</package>
27 %
28 %<*driver>
29 \documentclass{ltxdoc}
30 \EnableCrossrefs
31 \usepackage{listings}
32 \CodelineIndex
33 \RecordChanges
34 \begin{document}
35 \setlength{\parindent}{0pt}
36 \DocInput{rest-api.dtx}
37 \PrintChanges
38 \PrintIndex
39 \end{document}
40 %</driver>
41 % \fi
42 %
43 % \CheckSum{514}
44 %
45 % \CharacterTable
46 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
47 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
48 % Digits \0\1\2\3\4\5\6\7\8\9
49 % Exclamation \! Double quote \" Hash (number) \#
50 % Dollar \$ Percent \% Ampersand \&
51 % Acute accent \' Left paren \( Right paren \)
52 % Asterisk \* Plus \+ Comma \,
53 % Minus \- Point \. Solidus \/
54 % Colon \: Semicolon \; Less than \<
55 % Equals \= Greater than \> Question mark \?
56 % Commercial at \@ Left bracket \[ Backslash \\
57 % Right bracket \] Circumflex \^ Underscore \_
58 % Grave accent \` Left brace \{ Vertical bar \|
59 % Right brace \} Tilde \~}
60 %
61 %
62 % \changes{v1.4}{2020/12/04}{Add xml syntax highlighting support for request and response body}
63 % \changes{v1.3}{2020/06/23}{Fix typo and table coloring after apiRoute block}
64 % \changes{v1.2}{2020/03/22}{Corrections for CTAN, rename to rest-api}
65 % \changes{v1.1}{2020/03/21}{Add documentation and usage}
66 % \changes{v1.0}{2020/02/18}{Converted to DTX file}
67 % \changes{v0.3}{2020/02/17}{Add commands for color customization}
68 % \changes{v0.2}{2020/02/17}{Add command to enable/disable breaks in route environments}
69 % \changes{v0.1}{2020/02/15}{Start project}
70 %
71 % \DoNotIndex{\newcommand,\newenvironment}
72 %
73 % \providecommand*{\url}{\texttt}
74 % \GetFileInfo{rest-api.dtx}
75 % \title{The \textsf{rest-api} package}
76 % \author{Dennis Klein \\ \url{[email protected]}}
77 % \date{\fileversion~from \filedate}
78 %
79 % \maketitle
80 %
81 % \section{Introduction}
82 % A package to discribe a REST API for documentation.
83 %
84 %
85 % \section{Usage}
86 % \paragraph{GET Request with parameter} \
87 % \iffalse
88 %<*example>
89 % \fi
90 \begin{lstlisting}[frame=single,breaklines=true]
91 \begin{apiRoute}{get}{/api/storage/\{id\}}{get specific storage with id}
92 \begin{routeParameter}
93 \routeParamItem{id}{id of storage}
94 \end{routeParameter}
95 \begin{routeResponse}{application/json}
96 \begin{routeResponseItem}{200}{ok}
97 \begin{routeResponseItemBody}
98 {
99 "id": 867654678,
100 "name" : "Apfelmus",
101 "count" : 25
102 }
103 \end{routeResponseItemBody}
104 \end{routeResponseItem}
105 \begin{routeResponseItem}{404}{error: storage not found}
106 \begin{routeResponseItemBody}
107 {
108 "message": "storage with id '11' not found!"
109 }
110 \end{routeResponseItemBody}
111 \end{routeResponseItem}
112 \end{routeResponse}
113 \end{apiRoute}
114 \end{lstlisting}
115 % \iffalse
116 %</example>
117 % \fi
118
119 % \paragraph{GET Request without parameter} \
120 % \iffalse
121 %<*example>
122 % \fi
123 \begin{lstlisting}[frame=single,breaklines=true]
124 \begin{apiRoute}{get}{/api/storage/}{get a list of all storage's}
125 \begin{routeParameter}
126 \noRouteParameter{no parameter}
127 \end{routeParameter}
128 \begin{routeResponse}{application/json}
129 \begin{routeResponseItem}{200}{ok}
130 \begin{routeResponseItemBody}
131 [
132 {
133 "id": 867654678,
134 "name" : "Apfelmus",
135 "count" : 25
136 },
137 {
138 "id": 342523,
139 "name" : "Birnenmus",
140 "count" : 1
141 },
142 ...
143 ]
144 \end{routeResponseItemBody}
145 \end{routeResponseItem}
146 \end{routeResponse}
147 \end{apiRoute}
148 \end{lstlisting}
149 % \iffalse
150 %</example>
151 % \fi
152
153 % \paragraph{GET Request without parameter and response} \
154 % \iffalse
155 %<*example>
156 % \fi
157 \begin{lstlisting}[frame=single,breaklines=true]
158 \begin{apiRoute}{get}{/api/storage/}{}
159 \begin{routeParameter}
160 \noRouteParameter{no parameter}
161 \end{routeParameter}
162 \begin{routeResponse}{application/json}
163 \noRouteResponse{no response}
164 \end{routeResponse}
165 \end{apiRoute}
166 \end{lstlisting}
167 % \iffalse
168 %</example>
169 % \fi
170
171 % \paragraph{POST Request} \
172 % \iffalse
173 %<*example>
174 % \fi
175 \begin{lstlisting}[frame=single,breaklines=true]
176 \begin{apiRoute}{post}{/api/storage/}{create a new storage}
177 \begin{routeParameter}
178 \noRouteParameter{no parameter}
179 \end{routeParameter}
180 \begin{routeRequest}{application/json}
181 \begin{routeRequestBody}
182 {
183 "name" : "Apfelmus",
184 "count" : 25
185 }
186 \end{routeRequestBody}
187 \end{routeRequest}
188 \begin{routeResponse}{application/json}
189 \begin{routeResponseItem}{200}{ok}
190 \begin{routeResponseItemBody}
191 {
192 "id": 867654678,
193 "name" : "Apfelmus",
194 "count" : 25
195 }
196 \end{routeResponseItemBody}
197 \end{routeResponseItem}
198 \end{routeResponse}
199 \end{apiRoute}
200 \end{lstlisting}
201 % \iffalse
202 %</example>
203 % \fi
204
205 % \paragraph{PUT Request} \
206 % \iffalse
207 %<*example>
208 % \fi
209 \begin{lstlisting}[frame=single,breaklines=true]
210 \begin{apiRoute}{put}{/api/storage/\{id\}}{change a existing storage with id}
211 \begin{routeParameter}
212 \routeParamItem{id}{id of storage}
213 \end{routeParameter}
214 \begin{routeRequest}{application/json}
215 \begin{routeRequestBody}
216 {
217 "id": 867654678,
218 "name" : "Apfelmus",
219 "count" : 255
220 }
221 \end{routeRequestBody}
222 \end{routeRequest}
223 \begin{routeResponse}{application/json}
224 \begin{routeResponseItem}{200}{ok}
225 \begin{routeResponseItemBody}
226 {
227 "id": 867654678,
228 "name" : "Apfelmus",
229 "count" : 255
230 }
231 \end{routeResponseItemBody}
232 \end{routeResponseItem}
233 \begin{routeResponseItem}{404}{error: storage not found}
234 \begin{routeResponseItemBody}
235 {
236 "message": "storage with id '11' not found!"
237 }
238 \end{routeResponseItemBody}
239 \end{routeResponseItem}
240 \end{routeResponse}
241 \end{apiRoute}
242 \end{lstlisting}
243 % \iffalse
244 %</example>
245 % \fi
246
247 % \paragraph{DELETE Request} \
248 % \iffalse
249 %<*example>
250 % \fi
251 \begin{lstlisting}[frame=single,breaklines=true]
252 \begin{apiRoute}{delete}{/api/storage/\{id\}}{remove a storage with id}
253 \begin{routeParameter}
254 \routeParamItem{id}{id of storage}
255 \end{routeParameter}
256 \begin{routeResponse}{application/json}
257 \begin{routeResponseItem}{200}{ok}
258
259 \end{routeResponseItem}
260 \begin{routeResponseItem}{404}{error: storage not found}
261 \begin{routeResponseItemBody}
262 {
263 "message": "storage with id '11' not found!"
264 }
265 \end{routeResponseItemBody}
266 \end{routeResponseItem}
267 \end{routeResponse}
268 \end{apiRoute}
269 \end{lstlisting}
270 % \iffalse
271 %</example>
272 % \fi
273
274 % \paragraph{DELETE Request xml} \
275 % \iffalse
276 %<*example>
277 % \fi
278 \begin{lstlisting}[frame=single,breaklines=true]
279 \begin{apiRoute}{delete}{/api/storage/\{id\}}{remove a storage with id}
280 \begin{routeParameter}
281 \routeParamItem{id}{id of storage}
282 \end{routeParameter}
283 \begin{routeResponse}{application/xml}
284 \begin{routeResponseItem}{200}{ok}
285
286 \end{routeResponseItem}
287 \begin{routeResponseItem}{404}{error: storage not found}
288 \begin{routeResponseItemBody}
289 <message>
290 storage with id '11' not found!
291 </message>
292 \end{routeResponseItemBody}
293 \end{routeResponseItem}
294 \end{routeResponse}
295 \end{apiRoute}
296 \end{lstlisting}
297 % \iffalse
298 %</example>
299 % \fi
300
301
302 %
303 %
304 %
305 % \subsection{Usercallable macros and environments}
306 %
307 % \DescribeMacro{\getGetColor}
308 % Return the main color for routes with get method.
309 %
310 % \DescribeMacro{\getGetBorderColor}
311 % Return the border color for routes with get method.
312 %
313 % \DescribeMacro{\getGetLightColor}
314 % Return the background color for routes with get method.
315 %
316 % \DescribeMacro{\getPostColor}
317 % Return the main color for routes with post method.
318 %
319 % \DescribeMacro{\getPostBorderColor}
320 % Return the border color for routes with post method.
321 %
322 % \DescribeMacro{\getPostLightColor}
323 % Return the background color for routes with post method.
324 %
325 % \DescribeMacro{\getPutColor}
326 % Return the main color for routes with put method.
327 %
328 % \DescribeMacro{\getPutBorderColor}
329 % Return the border color for routes with put method.
330 %
331 % \DescribeMacro{\getPutLightColor}
332 % Return the background color for routes with put method.
333 %
334 % \DescribeMacro{\getDeleteColor}
335 % Return the main color for routes with delete method.
336 %
337 % \DescribeMacro{\getDeleteBorderColor}
338 % Return the border color for routes with delete method.
339 %
340 % \DescribeMacro{\getDeleteLightColor}
341 % Return the background color for routes with delete method.
342 %
343 % \DescribeMacro{\noBreakRoute}
344 % Set \textbackslash routeBreakValue true.
345 %
346 % \DescribeMacro{\breakRoute}
347 % Set \textbackslash routeBreakValue false.
348 %
349 % \DescribeEnv{apiRoute}
350 % Describe an endpoint with path, method and describtion.
351 % Contains other environments with further information.
352 %
353 % \DescribeEnv{routeRequest}
354 % Describe the content type of the request.
355 % Contains the request body.
356 %
357 % \DescribeEnv{routeParameter}
358 % Describe the path parameter.
359 % Contains a list of \textbackslash routeParamItem commands.
360 % If no paramters excists you can use the command \textbackslash noRouteParameter.
361 %
362 % \DescribeMacro{\routeParamItem}
363 % Describe a parameter with name and describtion.
364 %
365 % \DescribeMacro{\noRouteParameter}
366 % Show a text e.g. 'no parameter'.
367 %
368 % \DescribeEnv{routeResponse}
369 % Describe the content type of the response.
370 % Contains a list of routeResponseItem environments or the command \textbackslash noRouteResponse.
371 %
372 % \DescribeMacro{\noRouteResponse}
373 % Show a text e.g. 'no response'.
374 %
375 % \DescribeEnv{routeResponseItem}
376 % Describe the the http status code with describtion.
377 % Contains the response body.
378 %
379 %
380 % \subsection{Helper macros}
381 %
382 % \DescribeMacro{\routeBreakValue}
383 % Return true or false to enable/disable noBreak of a route.
384 %
385 % \DescribeMacro{\methodColor}
386 % Return the main color of the current route.
387 %
388 % \DescribeMacro{\methodLightColor}
389 % Return the background color of the current route.
390 %
391 % \DescribeMacro{\methodBorderColor}
392 % Return the border color of the current route.
393 %
394 % \DescribeMacro{\methodJson}
395 % Set the color scheme and language with \\lstset for the listings of the current route to json.
396 %
397 % \DescribeMacro{\methodXml}
398 % Set the color scheme and language with \\lstset for the listings of the current route to xml.
399 %
400
401 %
402 % \StopEventually{}
403 %
404 % \section{Implementation}
405 %
406 % \iffalse
407 %<*package>
408 % \fi
409 %
410 % this is my first package
411 %
412 % (c) Dennis Klein
413 %
414 %% This program can be redistributed and/or modified under the terms
415 %% of the LaTeX Project Public License Distributed from CTAN archives
416 %% in directory macros/latex/base/lppl.txt.
417 %
418 %
419 % \begin{macrocode}
420 \NeedsTeXFormat{LaTeX2e}
421 \ProvidesPackage{restapi}[2020/02/18 REST API package]
422 \RequirePackage[T1]{fontenc}
423 \RequirePackage{tabularx,colortbl}
424 \RequirePackage{transparent}
425 \RequirePackage{xcolor}
426 \RequirePackage{color}
427 \RequirePackage{xifthen, xstring}
428 \RequirePackage{tikz}
429 \RequirePackage[framemethod=tikz]{mdframed}
430 \RequirePackage{array}
431 \RequirePackage{verbatim}
432 \RequirePackage{listings}
433 % \end{macrocode}
434 %
435 % \begin{macrocode}
436 \definecolor{getBlue}{HTML}{1391FF}
437 \definecolor{getBlueBorder}{HTML}{61affe}
438 \definecolor{getLightBlue}{HTML}{ECF6FF}
439 % \end{macrocode}
440 %
441 % \begin{macro}{\getGetColor}
442 % \begin{macrocode}
443 \newcommand{\getGetColor}{getBlue}
444 % \end{macrocode}
445 % \end{macro}
446 %
447 %
448 % \begin{macro}{\getGetBorderColor}
449 % \begin{macrocode}
450 \newcommand{\getGetBorderColor}{getBlueBorder}
451 % \end{macrocode}
452 % \end{macro}
453 %
454 %
455 % \begin{macro}{\getGetLightColor}
456 % \begin{macrocode}
457 \newcommand{\getGetLightColor}{getLightBlue}
458 % \end{macrocode}
459 % \end{macro}
460 %
461 % \begin{macrocode}
462 \definecolor{postGreen}{HTML}{009D77}
463 \definecolor{postGreenBorder}{HTML}{49CC97}
464 \definecolor{postLightGreen}{HTML}{EBF7F4}
465 % \end{macrocode}
466 %
467 % \begin{macro}{\getPostColor}
468 % \begin{macrocode}
469 \newcommand{\getPostColor}{postGreen}
470 % \end{macrocode}
471 % \end{macro}
472 %
473 %
474 % \begin{macro}{\getPostBorderColor}
475 % \begin{macrocode}
476 \newcommand{\getPostBorderColor}{postGreenBorder}
477 % \end{macrocode}
478 % \end{macro}
479 %
480 %
481 % \begin{macro}{\getPostLightColor}
482 % \begin{macrocode}
483 \newcommand{\getPostLightColor}{postLightGreen}
484 % \end{macrocode}
485 % \end{macro}
486 %
487 % \begin{macrocode}
488 \definecolor{putOrange}{HTML}{E97500}
489 \definecolor{putOrangeBorder}{HTML}{fca130}
490 \definecolor{putLightOrange}{HTML}{FEF4EB}
491 % \end{macrocode}
492 %
493 % \begin{macro}{\getPutColor}
494 % \begin{macrocode}
495 \newcommand{\getPutColor}{putOrange}
496 % \end{macrocode}
497 % \end{macro}
498 %
499 %
500 % \begin{macro}{\getPutBorderColor}
501 % \begin{macrocode}
502 \newcommand{\getPutBorderColor}{putOrangeBorder}
503 % \end{macrocode}
504 % \end{macro}
505 %
506 %
507 % \begin{macro}{\getPutLightColor}
508 % \begin{macrocode}
509 \newcommand{\getPutLightColor}{putLightOrange}
510 % \end{macrocode}
511 % \end{macro}
512 %
513 % \begin{macrocode}
514 \definecolor{deleteRed}{HTML}{CF3030}
515 \definecolor{deleteRedBorder}{HTML}{f93e3e}
516 \definecolor{deleteLightRed}{HTML}{FBEEEE}
517 % \end{macrocode}
518 %
519 % \begin{macro}{\getDeleteColor}
520 % \begin{macrocode}
521 \newcommand{\getDeleteColor}{deleteRed}
522 % \end{macrocode}
523 % \end{macro}
524 %
525 %
526 % \begin{macro}{\getDeleteBorderColor}
527 % \begin{macrocode}
528 \newcommand{\getDeleteBorderColor}{deleteRedBorder}
529 % \end{macrocode}
530 % \end{macro}
531 %
532 %
533 % \begin{macro}{\getDeleteLightColor}
534 % \begin{macrocode}
535 \newcommand{\getDeleteLightColor}{deleteLightRed}
536 % \end{macrocode}
537 % \end{macro}
538 %
539 % \begin{macro}{color definitions for json}
540 % \begin{macrocode}
541 \colorlet{punct}{black}
542 \definecolor{background}{HTML}{EEEEEE}
543 \colorlet{delimGet}{\getGetColor}
544 \colorlet{numbGet}{delimGet}
545 \colorlet{delimPost}{\getPostColor}
546 \colorlet{numbPost}{delimPost}
547 \colorlet{delimPut}{\getPutColor}
548 \colorlet{numbPut}{delimPut}
549 \colorlet{delimDelete}{\getDeleteColor}
550 \colorlet{numbDelete}{delimDelete}
551 % \end{macrocode}
552 % \end{macro}
553 %
554 % \begin{macro}{json language defintions}
555 % \begin{macrocode}
556 \lstdefinelanguage{jsonGet}{
557 basicstyle=\small\ttfamily\color{black},
558 numberstyle=\small\color{black},
559 keywordstyle=\color{black},
560 commentstyle=\color{black},
561 stringstyle=\color{black},
562 frame=L,
563 framesep=8pt,
564 framerule=2pt,
565 xleftmargin=50pt,
566 xrightmargin=0pt,
567 rulesep=0pt,
568 backgroundcolor=\color{white},
569 numbersep=8pt,
570 tabsize=4,
571 showstringspaces=false,
572 breaklines=true,
573 literate=
574 *{0}{{{\color{numbGet}0}}}{1}
575 {1}{{{\color{numbGet}1}}}{1}
576 {2}{{{\color{numbGet}2}}}{1}
577 {3}{{{\color{numbGet}3}}}{1}
578 {4}{{{\color{numbGet}4}}}{1}
579 {5}{{{\color{numbGet}5}}}{1}
580 {6}{{{\color{numbGet}6}}}{1}
581 {7}{{{\color{numbGet}7}}}{1}
582 {8}{{{\color{numbGet}8}}}{1}
583 {9}{{{\color{numbGet}9}}}{1}
584 {:}{{{\color{punct}{:}}}}{1}
585 {,}{{{\color{punct}{,}}}}{1}
586 {\{}{{{\color{delimGet}{\{}}}}{1}
587 {\}}{{{\color{delimGet}{\}}}}}{1}
588 {[}{{{\color{delimGet}{[}}}}{1}
589 {]}{{{\color{delimGet}{]}}}}{1},
590 }
591 \lstdefinelanguage{jsonPost}{
592 basicstyle=\small\ttfamily\color{black},
593 numberstyle=\small\color{black},
594 keywordstyle=\color{black},
595 commentstyle=\color{black},
596 stringstyle=\color{black},
597 frame=L,
598 framesep=8pt,
599 framerule=2pt,
600 xleftmargin=50pt,
601 xrightmargin=0pt,
602 rulesep=0pt,
603 backgroundcolor=\color{white},
604 numbersep=8pt,
605 tabsize=4,
606 showstringspaces=false,
607 breaklines=true,
608 literate=
609 *{0}{{{\color{numbPost}0}}}{1}
610 {1}{{{\color{numbPost}1}}}{1}
611 {2}{{{\color{numbPost}2}}}{1}
612 {3}{{{\color{numbPost}3}}}{1}
613 {4}{{{\color{numbPost}4}}}{1}
614 {5}{{{\color{numbPost}5}}}{1}
615 {6}{{{\color{numbPost}6}}}{1}
616 {7}{{{\color{numbPost}7}}}{1}
617 {8}{{{\color{numbPost}8}}}{1}
618 {9}{{{\color{numbPost}9}}}{1}
619 {:}{{{\color{punct}{:}}}}{1}
620 {,}{{{\color{punct}{,}}}}{1}
621 {\{}{{{\color{delimPost}{\{}}}}{1}
622 {\}}{{{\color{delimPost}{\}}}}}{1}
623 {[}{{{\color{delimPost}{[}}}}{1}
624 {]}{{{\color{delimPost}{]}}}}{1},
625 }
626 \lstdefinelanguage{jsonPut}{
627 basicstyle=\small\ttfamily\color{black},
628 numberstyle=\small\color{black},
629 keywordstyle=\color{black},
630 commentstyle=\color{black},
631 stringstyle=\color{black},
632 frame=L,
633 framesep=8pt,
634 framerule=2pt,
635 xleftmargin=50pt,
636 xrightmargin=0pt,
637 rulesep=0pt,
638 backgroundcolor=\color{white},
639 numbersep=8pt,
640 tabsize=4,
641 showstringspaces=false,
642 breaklines=true,
643 literate=
644 *{0}{{{\color{numbPut}0}}}{1}
645 {1}{{{\color{numbPut}1}}}{1}
646 {2}{{{\color{numbPut}2}}}{1}
647 {3}{{{\color{numbPut}3}}}{1}
648 {4}{{{\color{numbPut}4}}}{1}
649 {5}{{{\color{numbPut}5}}}{1}
650 {6}{{{\color{numbPut}6}}}{1}
651 {7}{{{\color{numbPut}7}}}{1}
652 {8}{{{\color{numbPut}8}}}{1}
653 {9}{{{\color{numbPut}9}}}{1}
654 {:}{{{\color{punct}{:}}}}{1}
655 {,}{{{\color{punct}{,}}}}{1}
656 {\{}{{{\color{delimPut}{\{}}}}{1}
657 {\}}{{{\color{delimPut}{\}}}}}{1}
658 {[}{{{\color{delimPut}{[}}}}{1}
659 {]}{{{\color{delimPut}{]}}}}{1},
660 }
661 \lstdefinelanguage{jsonDelete}{
662 basicstyle=\small\ttfamily\color{black},
663 numberstyle=\small\color{black},
664 keywordstyle=\color{black},
665 commentstyle=\color{black},
666 stringstyle=\color{black},
667 frame=L,
668 framesep=8pt,
669 framerule=2pt,
670 xleftmargin=50pt,
671 xrightmargin=0pt,
672 rulesep=0pt,
673 backgroundcolor=\color{white},
674 numbersep=8pt,
675 tabsize=4,
676 showstringspaces=false,
677 breaklines=true,
678 literate=
679 *{0}{{{\color{numbDelete}0}}}{1}
680 {1}{{{\color{numbDelete}1}}}{1}
681 {2}{{{\color{numbDelete}2}}}{1}
682 {3}{{{\color{numbDelete}3}}}{1}
683 {4}{{{\color{numbDelete}4}}}{1}
684 {5}{{{\color{numbDelete}5}}}{1}
685 {6}{{{\color{numbDelete}6}}}{1}
686 {7}{{{\color{numbDelete}7}}}{1}
687 {8}{{{\color{numbDelete}8}}}{1}
688 {9}{{{\color{numbDelete}9}}}{1}
689 {:}{{{\color{punct}{:}}}}{1}
690 {,}{{{\color{punct}{,}}}}{1}
691 {\{}{{{\color{delimDelete}{\{}}}}{1}
692 {\}}{{{\color{delimDelete}{\}}}}}{1}
693 {[}{{{\color{delimDelete}{[}}}}{1}
694 {]}{{{\color{delimDelete}{]}}}}{1},
695 }
696 % \end{macrocode}
697 % \end{macro}
698 %
699 % \begin{macro}{xml language defintions}
700 % \begin{macrocode}
701 \lstdefinelanguage{xmlGet}{
702 basicstyle=\small\ttfamily\color{black},
703 numberstyle=\small\color{numbGet},
704 keywordstyle=\color{black},
705 commentstyle=\color{black},
706 stringstyle=\color{black},
707 frame=L,
708 framesep=8pt,
709 framerule=2pt,
710 xleftmargin=50pt,
711 xrightmargin=0pt,
712 rulesep=0pt,
713 backgroundcolor=\color{white},
714 numbersep=8pt,
715 tabsize=4,
716 showstringspaces=false,
717 breaklines=false,
718 morestring=[b]",
719 morestring=[s]{>}{<},
720 morecomment=[s]{<?}{?>},
721 identifierstyle=\color{numbGet},
722 }
723 \lstdefinelanguage{xmlPost}{
724 basicstyle=\small\ttfamily\color{black},
725 numberstyle=\small\color{numbPost},
726 keywordstyle=\color{black},
727 commentstyle=\color{black},
728 stringstyle=\color{black},
729 frame=L,
730 framesep=8pt,
731 framerule=2pt,
732 xleftmargin=50pt,
733 xrightmargin=0pt,
734 rulesep=0pt,
735 backgroundcolor=\color{white},
736 numbersep=8pt,
737 tabsize=4,
738 showstringspaces=false,
739 breaklines=false,
740 morestring=[b]",
741 morestring=[s]{>}{<},
742 morecomment=[s]{<?}{?>},
743 identifierstyle=\color{numbPost},
744 }
745 \lstdefinelanguage{xmlPut}{
746 basicstyle=\small\ttfamily\color{black},
747 numberstyle=\small\color{numbPut},
748 keywordstyle=\color{black},
749 commentstyle=\color{black},
750 stringstyle=\color{black},
751 frame=L,
752 framesep=8pt,
753 framerule=2pt,
754 xleftmargin=50pt,
755 xrightmargin=0pt,
756 rulesep=0pt,
757 backgroundcolor=\color{white},
758 numbersep=8pt,
759 tabsize=4,
760 showstringspaces=false,
761 breaklines=false,
762 morestring=[b]",
763 morestring=[s]{>}{<},
764 morecomment=[s]{<?}{?>},
765 stringstyle=\color{black},
766 identifierstyle=\color{numbPut},
767 }
768 \lstdefinelanguage{xmlDelete}{
769 basicstyle=\small\ttfamily\color{black},
770 numberstyle=\small\color{numbDelete},
771 keywordstyle=\color{black},
772 commentstyle=\color{black},
773 stringstyle=\color{black},
774 frame=L,
775 framesep=8pt,
776 framerule=2pt,
777 xleftmargin=50pt,
778 xrightmargin=0pt,
779 rulesep=0pt,
780 backgroundcolor=\color{white},
781 numbersep=8pt,
782 tabsize=4,
783 showstringspaces=false,
784 breaklines=false,
785 morestring=[b]",
786 morestring=[s]{>}{<},
787 morecomment=[s]{<?}{?>},
788 identifierstyle=\color{numbDelete},
789 }
790 % \end{macrocode}
791 % \end{macro}
792 %
793 % \begin{macro}{apiRoute frame style defintion}
794 % \begin{macrocode}
795 \mdfdefinestyle{mystyle}{
796 linecolor=\methodBorderColor,
797 backgroundcolor=\methodLightColor,
798 skipabove=0pt,
799 linewidth=1.5pt,
800 skipbelow=0pt,
801 innertopmargin=0pt,
802 innerbottommargin=-3pt,
803 innerrightmargin=0pt,
804 innerleftmargin=0pt,
805 leftmargin=0pt,
806 rightmargin=0pt,
807 nobreak=true
808 }
809 % \end{macrocode}
810 % \end{macro}
811 %
812 %
813 % \begin{macro}{\bodyFormat}
814 % \begin{macrocode}
815 \newcommand{\bodyFormat}{json}
816 % \end{macrocode}
817 % \end{macro}
818 %
819 %
820 % \begin{macro}{\routeBreakValue}
821 % \begin{macrocode}
822 \newcommand{\routeBreakValue}{true}
823 % \end{macrocode}
824 % \end{macro}
825 %
826 %
827 % \begin{macro}{\noBreakRoute}
828 % \begin{macrocode}
829 \newcommand{\noBreakRoute}
830 % \end{macrocode}
831 % \end{macro}
832 %
833 % \begin{macrocode}
834 {
835 \renewcommand{\routeBreakValue}{true}
836 }
837 % \end{macrocode}
838 %
839 % \begin{macro}{\breakRoute}
840 % \begin{macrocode}
841 \newcommand{\breakRoute}
842 % \end{macrocode}
843 % \end{macro}
844 %
845 % \begin{macrocode}
846 {
847 \renewcommand{\routeBreakValue}{false}
848 }
849 % \end{macrocode}
850 %
851 % \begin{macro}{\methodColor}
852 % \begin{macrocode}
853 \newcommand{\methodColor}{getBlue}
854 % \end{macrocode}
855 % \end{macro}
856 %
857 %
858 % \begin{macro}{\methodLightColor}
859 % \begin{macrocode}
860 \newcommand{\methodLightColor}{getLightBlue}
861 % \end{macrocode}
862 % \end{macro}
863 %
864 %
865 % \begin{macro}{\methodBorderColor}
866 % \begin{macrocode}
867 \newcommand{\methodBorderColor}{getBlueBorder}
868 % \end{macrocode}
869 % \end{macro}
870 %
871 %
872 % \begin{macro}{\methodJson}
873 % \begin{macrocode}
874 \newcommand{\methodJson}
875 % \end{macrocode}
876 % \end{macro}
877 %
878 % \begin{macrocode}
879 {
880 \lstset{language=jsonGet,rulecolor=\color{\methodColor}}
881 }
882 % \end{macrocode}
883 %
884 % \begin{macro}{\methodXml}
885 % \begin{macrocode}
886 \newcommand{\methodXml}
887 % \end{macrocode}
888 % \end{macro}
889 %
890 % \begin{macrocode}
891 {
892 \lstset{language=xmlGet,rulecolor=\color{\methodColor}}
893 }
894 % \end{macrocode}
895 %
896 %
897 % \begin{environment}{apiRoute}
898 % \begin{macrocode}
899 \newenvironment{apiRoute}[3]
900 {
901 \global\let\saved@CT@arc@\CT@arc@
902 \newcommand{\method}{#1}
903 \newcommand{\urlPath}{#2}
904 \newcommand{\routeDescription}{#3}
905
906 \ifthenelse{\equal{\method}{get}}
907 {
908 \renewcommand{\methodColor}{\getGetColor}
909 \renewcommand{\methodLightColor}{\getGetLightColor}
910 \renewcommand{\methodBorderColor}{\getGetBorderColor}
911 \renewcommand{\methodJson}
912 {
913 \colorlet{delimGet}{\methodColor}
914 \colorlet{numbGet}{delimGet}
915 \lstset{language=jsonGet,rulecolor=\color{\methodColor}}
916 }
917 \renewcommand{\methodXml}
918 {
919 \colorlet{delimGet}{\methodColor}
920 \colorlet{numbGet}{delimGet}
921 \lstset{language=xmlGet,rulecolor=\color{\methodColor}}
922 }
923 }
924 {}
925
926 \ifthenelse{\equal{\method}{post}}
927 {
928 \renewcommand{\methodColor}{\getPostColor}
929 \renewcommand{\methodLightColor}{\getPostLightColor}
930 \renewcommand{\methodBorderColor}{\getPostBorderColor}
931 \renewcommand{\methodJson}
932 {
933 \colorlet{delimPost}{\methodColor}
934 \colorlet{numbPost}{delimPost}
935 \lstset{language=jsonPost,rulecolor=\color{\methodColor}}
936 }
937 \renewcommand{\methodXml}
938 {
939 \colorlet{delimPost}{\methodColor}
940 \colorlet{numbPost}{delimPost}
941 \lstset{language=xmlPost,rulecolor=\color{\methodColor}}
942 }
943 }
944 {}
945
946 \ifthenelse{\equal{\method}{put}}
947 {
948 \renewcommand{\methodColor}{\getPutColor}
949 \renewcommand{\methodLightColor}{\getPutLightColor}
950 \renewcommand{\methodBorderColor}{\getPutBorderColor}
951 \renewcommand{\methodJson}
952 {
953 \colorlet{delimPut}{\methodColor}
954 \colorlet{numbPut}{delimPut}
955 \lstset{language=jsonPut,rulecolor=\color{\methodColor}}
956 }
957 \renewcommand{\methodXml}
958 {
959 \colorlet{delimPut}{\methodColor}
960 \colorlet{numbPut}{delimPut}
961 \lstset{language=xmlPut,rulecolor=\color{\methodColor}}
962 }
963 }
964 {}
965 \ifthenelse{\equal{\method}{delete}}
966 {
967 \renewcommand{\methodColor}{\getDeleteColor}
968 \renewcommand{\methodLightColor}{\getDeleteLightColor}
969 \renewcommand{\methodBorderColor}{\getDeleteBorderColor}
970 \renewcommand{\methodJson}
971 {
972 \colorlet{delimDelete}{\methodColor}
973 \colorlet{numbDelete}{delimDelete}
974 \lstset{language=jsonDelete,rulecolor=\color{\methodColor}}
975 }
976 \renewcommand{\methodXml}
977 {
978 \colorlet{delimDelete}{\methodColor}
979 \colorlet{numbDelete}{delimDelete}
980 \lstset{language=xmlDelete,rulecolor=\color{\methodColor}}
981 }
982 }
983 {}
984
985 \ifthenelse{\equal{\routeDescription}{}}
986 {
987 \newcommand{\printDescription}{}
988 }
989 {
990 \newcommand{\printDescription}
991 {
992 \rowcolor{\methodLightColor}
993 & \textit{\routeDescription} \\
994 }
995
996 }
997
998
999 \begingroup
1000 \setlength{\parindent}{0em}
1001 \begin{mdframed}[style=mystyle,nobreak=\routeBreakValue]
1002 \begin{tabularx}{\textwidth}{p{1.6cm} X}
1003 \rowcolor{\methodLightColor}
1004
1005 \cellcolor{\methodColor}
1006 \centering
1007 \textcolor{white}{\textbf{\textsc{\method}}}
1008 & \textbf{\urlPath} \\
1009
1010 \printDescription
1011
1012 \rowcolor{\methodLightColor} & \\
1013 \end{tabularx}
1014 }
1015 % \end{macrocode}
1016 % \end{environment}
1017 %
1018 % \begin{macrocode}
1019 {
1020 \end{mdframed}
1021 \endgroup
1022 \global\let\CT@arc@\saved@CT@arc@
1023 }
1024 % \end{macrocode}
1025 %
1026 % \begin{environment}{routeRequest}
1027 % \begin{macrocode}
1028 \newenvironment{routeRequest}[1]
1029 {
1030 \renewcommand{\bodyFormat}{#1}
1031
1032 \arrayrulecolor{\methodColor}
1033
1034 \begin{tabularx}{\textwidth}{X l}
1035 \rowcolor{\methodLightColor!20}
1036 \textbf{Body} & #1 \\ \hline
1037 \end{tabularx}
1038 \vspace{1ex}
1039 }
1040 % \end{macrocode}
1041 % \end{environment}
1042 %
1043 % \begin{macrocode}
1044 {
1045 \bigskip
1046 }
1047 \lstnewenvironment{routeRequestBody}
1048 {
1049 \IfSubStr{\bodyFormat}{xml}{\methodXml}{\methodJson}
1050 }
1051 {}
1052 % \end{macrocode}
1053 %
1054 % \begin{environment}{routeParameter}
1055 % \begin{macrocode}
1056 \newenvironment{routeParameter}
1057 {
1058 \newcommand{\routeParamItem}[2]
1059 {
1060 \rowcolor{\methodLightColor} ##1 & ##2 \\
1061 }
1062 \newcommand{\noRouteParameter}[1]
1063 {
1064 \small{\textit{##1}}
1065 }
1066 %\vspace{-0.61em}
1067
1068 \arrayrulecolor{\methodColor}
1069
1070 \begin{tabularx}{\textwidth}{X}
1071 \rowcolor{\methodLightColor!20}
1072 \textbf{Parameter} \\ \hline
1073 \end{tabularx}
1074
1075 \tabularx{\textwidth}{l X}
1076 }
1077 % \end{macrocode}
1078 % \end{environment}
1079 %
1080 % \begin{macrocode}
1081 {
1082 \endtabularx
1083 }
1084 % \end{macrocode}
1085 %
1086 % \begin{environment}{routeResponse}
1087 % \begin{macrocode}
1088 \newenvironment{routeResponse}[1]
1089 {
1090 \renewcommand{\bodyFormat}{#1}
1091
1092 \newcommand{\noRouteResponse}[1]
1093 {
1094 \begin{tabularx}{\textwidth}{X}
1095 \rowcolor{\methodLightColor}
1096 \small{\textit{##1}} \\
1097 \end{tabularx}
1098 }
1099
1100 \arrayrulecolor{\methodColor}
1101 \begin{tabularx}{\textwidth}{X l}
1102 \rowcolor{\methodLightColor!20}
1103 \textbf{Response} & #1 \\ \hline
1104 \end{tabularx}
1105 }
1106 % \end{macrocode}
1107 % \end{environment}
1108 %
1109 % \begin{macrocode}
1110 {}
1111 % \end{macrocode}
1112 %
1113 % \begin{environment}{routeResponseItem}
1114 % \begin{macrocode}
1115 \newenvironment{routeResponseItem}[2]
1116 {
1117 \begin{tabularx}{\textwidth}{l X}
1118 \textbf{#1} & #2 \\
1119 \end{tabularx}
1120 }
1121 % \end{macrocode}
1122 % \end{environment}
1123 %
1124 % \begin{macrocode}
1125 {
1126 \medskip
1127 }
1128 \lstnewenvironment{routeResponseItemBody}
1129 {
1130 \vspace{-1.4em}
1131 \IfSubStr{\bodyFormat}{xml}{\methodXml}{\methodJson}
1132 }
1133 {}
1134 \endinput
1135 % \end{macrocode}
1136 %%
1137 %% End of file `rest-api.sty'.
1138 %
1139
1140 %
1141 % \iffalse
1142 %</package>
1143 % \fi
1144 %
1145 % \Finale
1146 \endinput