Compare commits
696 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83bb63321a | ||
|
|
cd5b5c9240 | ||
|
|
2096ec0d5d | ||
|
|
25d4311237 | ||
|
|
7e07c2fc81 | ||
|
|
5a8a618e6b | ||
|
|
f072fc99b9 | ||
|
|
54e881fc58 | ||
|
|
cd6a3ed724 | ||
|
|
5a00dde912 | ||
|
|
876d7b2f7b | ||
|
|
4b74ec0e54 | ||
|
|
a719e33332 | ||
|
|
86a727f097 | ||
|
|
2670780076 | ||
|
|
ebf9912269 | ||
|
|
11549ab64e | ||
|
|
d128146952 | ||
|
|
686abd8842 | ||
|
|
551aeed835 | ||
|
|
5b1a1a2bcf | ||
|
|
09d2474a9a | ||
|
|
5c00e5493c | ||
|
|
c343af8f5a | ||
|
|
4af7eb5b89 | ||
|
|
aa9a340144 | ||
|
|
35ae68ceee | ||
|
|
560fb4ece6 | ||
|
|
8eb494cd5b | ||
|
|
0766336a56 | ||
|
|
24352f4d1c | ||
|
|
adb0fee973 | ||
|
|
13a7113aa7 | ||
|
|
e882975726 | ||
|
|
12209fe923 | ||
|
|
8a63744198 | ||
|
|
5871f0c9b0 | ||
|
|
908f524c64 | ||
|
|
9fa0ee3def | ||
|
|
35e9450f74 | ||
|
|
6033ea5a98 | ||
|
|
6f24c3cb39 | ||
|
|
e975e49d3e | ||
|
|
c5cfe10fa6 | ||
|
|
7c988460f0 | ||
|
|
21f1892de0 | ||
|
|
b97344849d | ||
|
|
935d48d4cc | ||
|
|
73ba233f9e | ||
|
|
ff955d392b | ||
|
|
19fde31f67 | ||
|
|
b3f368ac37 | ||
|
|
c5efb401b4 | ||
|
|
f386e6ed91 | ||
|
|
55b323c063 | ||
|
|
6f286b52d8 | ||
|
|
4850673b96 | ||
|
|
353af537ba | ||
|
|
2367d86eb7 | ||
|
|
1aec46a57c | ||
|
|
f650fb7b3e | ||
|
|
568d6a6441 | ||
|
|
630e86cd31 | ||
|
|
0e3e229434 | ||
|
|
f41d1cbcb0 | ||
|
|
20b653086d | ||
|
|
ae4cf35de4 | ||
|
|
86fc9a9746 | ||
|
|
1b4626d9ca | ||
|
|
7528b34ba3 | ||
|
|
ebecde1768 | ||
|
|
2301de6466 | ||
|
|
f7efad2480 | ||
|
|
c23bd01495 | ||
|
|
7e5986237a | ||
|
|
1bf26c95e3 | ||
|
|
3888e67d02 | ||
|
|
54e17321b6 | ||
|
|
90f56cfe61 | ||
|
|
44e33ad6f3 | ||
|
|
65d4e0c225 | ||
|
|
d37a374d02 | ||
|
|
5bb5e5ff29 | ||
|
|
de1f84d2aa | ||
|
|
aa35c0169c | ||
|
|
b53727842a | ||
|
|
f88e3d2ed4 | ||
|
|
eefda62d99 | ||
|
|
592446f714 | ||
|
|
3275a07325 | ||
|
|
1c2b9eee26 | ||
|
|
3a5533447b | ||
|
|
2fcd2d1a79 | ||
|
|
07d878be35 | ||
|
|
7a75d7874b | ||
|
|
99c3044218 | ||
|
|
fec5fb54bb | ||
|
|
031051f1f9 | ||
|
|
d432c398cf | ||
|
|
8eb44c26d2 | ||
|
|
3a76a3e920 | ||
|
|
52e80e7af6 | ||
|
|
1eac6a63d9 | ||
|
|
6e379042a0 | ||
|
|
8367195315 | ||
|
|
7de954958d | ||
|
|
a161924a7f | ||
|
|
9568f3a960 | ||
|
|
fdb24fdf33 | ||
|
|
3c0f935e99 | ||
|
|
826f4ff762 | ||
|
|
ed926139b8 | ||
|
|
cb23bfe1a4 | ||
|
|
ab7d355fe4 | ||
|
|
87ccc182f1 | ||
|
|
ff21d7c985 | ||
|
|
b69797ef51 | ||
|
|
f1614fe81a | ||
|
|
d5c9116dc7 | ||
|
|
5aaff59f71 | ||
|
|
a20ed66400 | ||
|
|
6312c2f3e0 | ||
|
|
2e2bd7d6c5 | ||
|
|
dd7de8fe08 | ||
|
|
934039bcd4 | ||
|
|
98efe9543d | ||
|
|
b68c0031a7 | ||
|
|
a587899976 | ||
|
|
4528f2aa0e | ||
|
|
b2e6f498be | ||
|
|
d32179009d | ||
|
|
c815318972 | ||
|
|
7cbb52094d | ||
|
|
7c8dfb520f | ||
|
|
6395adddb6 | ||
|
|
01a63f895c | ||
|
|
5d2ba5b21e | ||
|
|
6e4c0c1498 | ||
|
|
dce6b4183a | ||
|
|
1bf36592ef | ||
|
|
24d9218d14 | ||
|
|
9ee6c96a3a | ||
|
|
507307308d | ||
|
|
14d4268cc3 | ||
|
|
aade4453e1 | ||
|
|
232a635c06 | ||
|
|
545cf13584 | ||
|
|
b7ef781fda | ||
|
|
3f18a446af | ||
|
|
391bb20de2 | ||
|
|
aafac7821c | ||
|
|
103aef6cd6 | ||
|
|
6282459905 | ||
|
|
293132e6a4 | ||
|
|
0e4b193d70 | ||
|
|
277e452a73 | ||
|
|
80e96933b0 | ||
|
|
1ab4f8ff6c | ||
|
|
9a67581ad9 | ||
|
|
9ef34dd853 | ||
|
|
b37c173e07 | ||
|
|
105ac545b3 | ||
|
|
ae3f9aa353 | ||
|
|
3e9fca8a0d | ||
|
|
1a45054b5d | ||
|
|
be56290257 | ||
|
|
64195e095b | ||
|
|
5a33b3473e | ||
|
|
df23dc09e8 | ||
|
|
2a3ac1e6d0 | ||
|
|
bad8cde186 | ||
|
|
d9adcc2016 | ||
|
|
7b59a069ef | ||
|
|
310a2e47b6 | ||
|
|
954e302467 | ||
|
|
abb77b7c5f | ||
|
|
aaac78f985 | ||
|
|
e959c9ed59 | ||
|
|
1965110df9 | ||
|
|
1300249555 | ||
|
|
05a4ee230c | ||
|
|
78411de398 | ||
|
|
e697815c0c | ||
|
|
fbd22779ee | ||
|
|
b13c57ea35 | ||
|
|
0b38f2a91c | ||
|
|
db36397e81 | ||
|
|
066fd597da | ||
|
|
e979d2b45b | ||
|
|
4fa9f0d645 | ||
|
|
fecf6c6161 | ||
|
|
7eecba583d | ||
|
|
9c6111da3e | ||
|
|
f10882d14d | ||
|
|
0ac9e13948 | ||
|
|
fb3ef974a3 | ||
|
|
65522e4569 | ||
|
|
ae8961d43c | ||
|
|
c131a8cad8 | ||
|
|
7ad8ef8d18 | ||
|
|
539520903f | ||
|
|
566300a598 | ||
|
|
b64bbee4b4 | ||
|
|
8c005466c6 | ||
|
|
d222e01466 | ||
|
|
d692f616ba | ||
|
|
656ebde58c | ||
|
|
4973f9674a | ||
|
|
9fe3bf9ec0 | ||
|
|
074794830f | ||
|
|
1f4fd9f115 | ||
|
|
82ac10c7a5 | ||
|
|
505b9047ba | ||
|
|
735123749e | ||
|
|
df3c8f51d5 | ||
|
|
6de159fa7d | ||
|
|
119b190585 | ||
|
|
14c0be59dd | ||
|
|
fd2ae92663 | ||
|
|
a57b16504f | ||
|
|
ee36c1b9f3 | ||
|
|
928ec8b325 | ||
|
|
3d720f2c81 | ||
|
|
040c60a9ba | ||
|
|
2e874957fb | ||
|
|
3ed94986ed | ||
|
|
32f7561e26 | ||
|
|
dbaaa195b5 | ||
|
|
7f01e9beaa | ||
|
|
2e95cf6b25 | ||
|
|
23314507db | ||
|
|
cfbff5402c | ||
|
|
6c6c625273 | ||
|
|
a66560a255 | ||
|
|
5ff5fc8f0f | ||
|
|
f001b5bb7c | ||
|
|
403b8fcfc7 | ||
|
|
456625ae4b | ||
|
|
5dd9163610 | ||
|
|
3953b3328a | ||
|
|
124be6c37a | ||
|
|
6fc474ac09 | ||
|
|
49ccad694e | ||
|
|
370fa5eb8d | ||
|
|
df61f140ca | ||
|
|
b80b16d03f | ||
|
|
97c75c306f | ||
|
|
30258c7e75 | ||
|
|
e66feb5a27 | ||
|
|
972f2c2d6d | ||
|
|
fcf46c1588 | ||
|
|
cd38ed01a4 | ||
|
|
5f965e6378 | ||
|
|
d20bce81f0 | ||
|
|
d9e2397f48 | ||
|
|
6fe35c34be | ||
|
|
05924c5813 | ||
|
|
b931d7f3af | ||
|
|
5b970eb2c8 | ||
|
|
52b5bf2361 | ||
|
|
8eee21baf0 | ||
|
|
e99656704f | ||
|
|
235e5b7ddf | ||
|
|
69e7992f3e | ||
|
|
29bfddc8d2 | ||
|
|
3fc8a897a1 | ||
|
|
451e377cac | ||
|
|
6379b3ccf1 | ||
|
|
456f27c85b | ||
|
|
c739649f20 | ||
|
|
3dceb21bd5 | ||
|
|
23331930cc | ||
|
|
da48f49a25 | ||
|
|
3775f26458 | ||
|
|
365d3278ff | ||
|
|
7cc9742530 | ||
|
|
0648a9cbea | ||
|
|
7766276abc | ||
|
|
19bc2dd0e2 | ||
|
|
6126260aae | ||
|
|
cdd0bc52e2 | ||
|
|
ccf3ee8e7d | ||
|
|
54147bbddb | ||
|
|
914fa2da0f | ||
|
|
d41b14bbff | ||
|
|
354d2167fb | ||
|
|
9eb7c671cd | ||
|
|
aee7708cd1 | ||
|
|
e3f946ecf8 | ||
|
|
c25b6be1f3 | ||
|
|
eff69079a6 | ||
|
|
8d8d4cd5d0 | ||
|
|
4bce1234af | ||
|
|
d892f0b39d | ||
|
|
831e949d91 | ||
|
|
d48b9c217b | ||
|
|
124a66aaa9 | ||
|
|
08eb6841fc | ||
|
|
e74ac9fda5 | ||
|
|
d4bbcc3acc | ||
|
|
9655e113c0 | ||
|
|
54c7682f00 | ||
|
|
7c8efa1060 | ||
|
|
0caf2d7a43 | ||
|
|
533590656f | ||
|
|
fe0fa8a9ce | ||
|
|
a85b695c80 | ||
|
|
251a6b7e73 | ||
|
|
08b0d085db | ||
|
|
0b95f35a61 | ||
|
|
4073b7627d | ||
|
|
2c2b599528 | ||
|
|
eb86d6f1d0 | ||
|
|
2d74e441dc | ||
|
|
8145dea0d5 | ||
|
|
a4a217a223 | ||
|
|
cd023a99b5 | ||
|
|
a339e78135 | ||
|
|
1425414b4a | ||
|
|
a8e189408a | ||
|
|
fbb535d241 | ||
|
|
7d6fc09c24 | ||
|
|
00f62124af | ||
|
|
138be996db | ||
|
|
722b2b24b7 | ||
|
|
d90d68332f | ||
|
|
0470d984cc | ||
|
|
c001452abf | ||
|
|
b25378463c | ||
|
|
63d3a95529 | ||
|
|
1c1eb106d6 | ||
|
|
916d2515b0 | ||
|
|
caff7db0d4 | ||
|
|
85006b2c15 | ||
|
|
727c6c6467 | ||
|
|
12fc80c8b0 | ||
|
|
97ae3df30d | ||
|
|
3189043b7f | ||
|
|
9f01adfb25 | ||
|
|
5155e6510f | ||
|
|
37d99eb86f | ||
|
|
014e9354ce | ||
|
|
c8ecab6d78 | ||
|
|
2e7e10aaae | ||
|
|
9f197074ef | ||
|
|
5b054761cf | ||
|
|
be3ae6bd0d | ||
|
|
71980aafeb | ||
|
|
d1c20ed325 | ||
|
|
16f559cd70 | ||
|
|
d0dc6188cd | ||
|
|
e79f6c49a4 | ||
|
|
4ec11f8359 | ||
|
|
52c1780f79 | ||
|
|
c6becb9995 | ||
|
|
194efab1f6 | ||
|
|
34af7a4899 | ||
|
|
2b6c699828 | ||
|
|
e376b972fe | ||
|
|
445a04b9d6 | ||
|
|
4283b2489d | ||
|
|
c6e21b9ed1 | ||
|
|
c61a94495f | ||
|
|
99049d156a | ||
|
|
f8d331fc8b | ||
|
|
667a883fb0 | ||
|
|
2bd1719637 | ||
|
|
d9d62dec6b | ||
|
|
f3fdd45019 | ||
|
|
ded1cd6b06 | ||
|
|
854dcf48b2 | ||
|
|
0916fa38e2 | ||
|
|
c590f5102c | ||
|
|
9bda5b7941 | ||
|
|
ebba92368a | ||
|
|
3e5df92223 | ||
|
|
2d17071c8c | ||
|
|
38d4bff7f4 | ||
|
|
fc5434cb3d | ||
|
|
3c0e545661 | ||
|
|
c0f758ba9b | ||
|
|
e96dd94ee9 | ||
|
|
8a913d075d | ||
|
|
bbaf3a05b3 | ||
|
|
61c4f8861f | ||
|
|
1e7c51a2cb | ||
|
|
21620917f7 | ||
|
|
cc65055f3c | ||
|
|
71fab0ca94 | ||
|
|
b272e812d0 | ||
|
|
cb9092492f | ||
|
|
0a79020e59 | ||
|
|
4e4fa960b6 | ||
|
|
c28fddb4f6 | ||
|
|
e36587f61a | ||
|
|
40c53cf27b | ||
|
|
09c78a1cee | ||
|
|
b2d9e5ab73 | ||
|
|
a630c1a161 | ||
|
|
1771330890 | ||
|
|
02fed86851 | ||
|
|
46ae248056 | ||
|
|
5730a3be09 | ||
|
|
462df0032e | ||
|
|
d058a99874 | ||
|
|
2399cc25ca | ||
|
|
c7fe39bf21 | ||
|
|
a5bf4c64bb | ||
|
|
3fd97ea471 | ||
|
|
3dae4dd155 | ||
|
|
a510740fa3 | ||
|
|
91ba9e7fd3 | ||
|
|
f3056d316f | ||
|
|
0e9f556994 | ||
|
|
b9727c9275 | ||
|
|
d649fb0d87 | ||
|
|
1aa8221931 | ||
|
|
cbb541f1a3 | ||
|
|
8b215d7425 | ||
|
|
52ef344ba4 | ||
|
|
44eff18b3e | ||
|
|
a0c8d47369 | ||
|
|
d19a0020fd | ||
|
|
5494ad911e | ||
|
|
5ead0975c1 | ||
|
|
34cd890cd9 | ||
|
|
329756d664 | ||
|
|
8ebc4f603f | ||
|
|
07bcdf220d | ||
|
|
2f71a011c3 | ||
|
|
e6244fc3f8 | ||
|
|
9eb713cefb | ||
|
|
714c0aa8c9 | ||
|
|
91a0aeec9d | ||
|
|
a28c1d4efe | ||
|
|
a6af12ae06 | ||
|
|
910b2ff187 | ||
|
|
64adbfaab6 | ||
|
|
d60b8d4b83 | ||
|
|
684fc221b1 | ||
|
|
cf96642db5 | ||
|
|
ab6628b1ab | ||
|
|
06beab3865 | ||
|
|
bd77f4400f | ||
|
|
deebb2be9a | ||
|
|
22c6cab910 | ||
|
|
ea771c80d1 | ||
|
|
861b97c4ff | ||
|
|
b1ffe7cfc2 | ||
|
|
852ea15dc2 | ||
|
|
45768a5bba | ||
|
|
76b5a83511 | ||
|
|
c0d1da781f | ||
|
|
1a80a7a8eb | ||
|
|
cd66661026 | ||
|
|
b88e4eea56 | ||
|
|
f64a0d199d | ||
|
|
5f47f49cf4 | ||
|
|
7a0c8d81f6 | ||
|
|
427efca6f8 | ||
|
|
54546185ab | ||
|
|
493f045764 | ||
|
|
fd79e98ed7 | ||
|
|
40bf5762bb | ||
|
|
c291991236 | ||
|
|
7cb9b97bfb | ||
|
|
eddbd9610e | ||
|
|
a66ebec28f | ||
|
|
cdad18194e | ||
|
|
17f69b2bbc | ||
|
|
84176e5e27 | ||
|
|
67a3b924e8 | ||
|
|
84c86873fb | ||
|
|
2a486a2939 | ||
|
|
0550128e1d | ||
|
|
ff867c9ba4 | ||
|
|
c5fada0a62 | ||
|
|
7316ae0ce4 | ||
|
|
c8919e9844 | ||
|
|
4e340466de | ||
|
|
2fceda6f09 | ||
|
|
2aa29fde8a | ||
|
|
a76b7c545a | ||
|
|
8178bf1380 | ||
|
|
63ca190a32 | ||
|
|
836d9fbae7 | ||
|
|
9df1c73641 | ||
|
|
1899efd209 | ||
|
|
9d90766592 | ||
|
|
bd9d3ee4c3 | ||
|
|
20fac6ab26 | ||
|
|
5be5a7d8e3 | ||
|
|
35f0192ecb | ||
|
|
69949d6257 | ||
|
|
94ad45d2b0 | ||
|
|
c62f6085f7 | ||
|
|
2a300a2ef6 | ||
|
|
a77a0f281d | ||
|
|
d794cd989b | ||
|
|
60c687f3f8 | ||
|
|
8da5d3a770 | ||
|
|
ead3e0bc22 | ||
|
|
a0c1f20fc3 | ||
|
|
8e6586d4e4 | ||
|
|
b2f4229f70 | ||
|
|
2425074855 | ||
|
|
7d53a8aedb | ||
|
|
a16617880f | ||
|
|
650431b8ce | ||
|
|
a6654b65a9 | ||
|
|
4f15ea9ed7 | ||
|
|
aa34532b33 | ||
|
|
3fe711a3ba | ||
|
|
93e2175435 | ||
|
|
5c61006d11 | ||
|
|
6da74af830 | ||
|
|
93ba67c405 | ||
|
|
04fed3d4d5 | ||
|
|
1ead6614ba | ||
|
|
887e63464d | ||
|
|
47e5d5e56e | ||
|
|
c505c1e88e | ||
|
|
6a8c04c031 | ||
|
|
33f68a7f41 | ||
|
|
c5af8676e5 | ||
|
|
618898cb09 | ||
|
|
36bdcc57d9 | ||
|
|
eb418c07f5 | ||
|
|
9a265fbbc3 | ||
|
|
cf32d6cf29 | ||
|
|
9d216e3dc2 | ||
|
|
9d387b3e80 | ||
|
|
1e6be2f26d | ||
|
|
e56f824cd2 | ||
|
|
d38014f4b5 | ||
|
|
b331062fa6 | ||
|
|
88df748451 | ||
|
|
5384197bd1 | ||
|
|
2b5d4b7fe9 | ||
|
|
c15d074488 | ||
|
|
b0c3aa71b9 | ||
|
|
32d85ffb55 | ||
|
|
59fcd61738 | ||
|
|
7ce969882d | ||
|
|
ee70cdb94f | ||
|
|
f21fce7730 | ||
|
|
c426c7b341 | ||
|
|
1231d1e0c2 | ||
|
|
66073aebb8 | ||
|
|
882d9e5709 | ||
|
|
ba9ec45d9e | ||
|
|
f2787a41ae | ||
|
|
3469523225 | ||
|
|
1dc9a07cb9 | ||
|
|
a34807e5c9 | ||
|
|
85ef33a720 | ||
|
|
3163c077a1 | ||
|
|
fbb446875d | ||
|
|
e8cdcabffe | ||
|
|
832813d40a | ||
|
|
e2f28bca7d | ||
|
|
3ed894688c | ||
|
|
bb7422d755 | ||
|
|
b2f3f4a6c7 | ||
|
|
f21794a253 | ||
|
|
ffa96e56a5 | ||
|
|
38e50dfe77 | ||
|
|
1d3ec2d5a3 | ||
|
|
495751433b | ||
|
|
de7d73eae9 | ||
|
|
f825cf9613 | ||
|
|
6e32056c26 | ||
|
|
85bc2aa8f9 | ||
|
|
d56de83368 | ||
|
|
065e65a31c | ||
|
|
a68980bc76 | ||
|
|
90880a00f3 | ||
|
|
675dd762a8 | ||
|
|
7cdd436b10 | ||
|
|
a78126c551 | ||
|
|
f729bf15c3 | ||
|
|
ce129703f8 | ||
|
|
c99bba90a4 | ||
|
|
914a8ed5fb | ||
|
|
85b95c189e | ||
|
|
8722bdc8cb | ||
|
|
2ce724cdd0 | ||
|
|
922b6b8534 | ||
|
|
a05f4b2e29 | ||
|
|
e4e32f3f9f | ||
|
|
bf0b864c0d | ||
|
|
4948c8bea1 | ||
|
|
9397bf4255 | ||
|
|
a6d85d7b0c | ||
|
|
16371443e8 | ||
|
|
5738d86988 | ||
|
|
e1bf3fbe94 | ||
|
|
7ce98408f4 | ||
|
|
1a7b219c40 | ||
|
|
8a8e93f3ca | ||
|
|
1d95d9afc2 | ||
|
|
5b49187cb7 | ||
|
|
7b99565636 | ||
|
|
32980d1476 | ||
|
|
490a6d974f | ||
|
|
4e971817a2 | ||
|
|
f649553727 | ||
|
|
3576a80872 | ||
|
|
2bbb9ffd8e | ||
|
|
7d2acae537 | ||
|
|
1e68587097 | ||
|
|
71d77ce6ab | ||
|
|
de849b69d4 | ||
|
|
a8e84995ea | ||
|
|
edffd47067 | ||
|
|
cef474955e | ||
|
|
00dffe7b57 | ||
|
|
fea79bd4f9 | ||
|
|
fb5d30f700 | ||
|
|
ab15b393d0 | ||
|
|
7d1cf12c48 | ||
|
|
14d8acc385 | ||
|
|
e91d639d93 | ||
|
|
3671873349 | ||
|
|
f920a3e954 | ||
|
|
cb35f1f319 | ||
|
|
c8805f5018 | ||
|
|
cc04be6790 | ||
|
|
13eb453c2a | ||
|
|
d20dfa9027 | ||
|
|
38429152f2 | ||
|
|
cf382e9890 | ||
|
|
81b1846fcd | ||
|
|
7d48a65ec1 | ||
|
|
dc50cdff15 | ||
|
|
165e615698 | ||
|
|
2559bef4ce | ||
|
|
7847a74104 | ||
|
|
685596c213 | ||
|
|
20862d3ee4 | ||
|
|
2527792b58 | ||
|
|
d85d307e30 | ||
|
|
58e01e96e1 | ||
|
|
1b425b83b6 | ||
|
|
96d7195365 | ||
|
|
e14af63a4c | ||
|
|
925f1a1f81 | ||
|
|
1e5e2b20dd | ||
|
|
d209718987 | ||
|
|
31619b26c9 | ||
|
|
2277c7410b | ||
|
|
90d8b088d2 | ||
|
|
a5d9588a7d | ||
|
|
ff17b1d857 | ||
|
|
2a5bd83bb8 | ||
|
|
aa7800ba37 | ||
|
|
8a1a1a9d91 | ||
|
|
e7b59f8a2f | ||
|
|
8e75655346 | ||
|
|
e45498a1d7 | ||
|
|
5f838ca2b4 | ||
|
|
85e53ce89f | ||
|
|
51c1cd3fe5 | ||
|
|
29c7db1980 | ||
|
|
663323cd1e | ||
|
|
ab13a6ec0e | ||
|
|
d78eb490cb | ||
|
|
48e724cb4b | ||
|
|
0a3db6c013 | ||
|
|
a843fad921 | ||
|
|
de41e3b058 | ||
|
|
6bf3a5aab4 | ||
|
|
8d4bc8c0bc | ||
|
|
76df322bb4 | ||
|
|
36cdd3cebb | ||
|
|
ca4587cb29 | ||
|
|
ce958ba798 | ||
|
|
7c5c0fea8c | ||
|
|
5bc557a5d2 | ||
|
|
e23a649c17 | ||
|
|
a5300ceab5 | ||
|
|
fdb405e52a | ||
|
|
79cdd26ef0 | ||
|
|
87c24c8f31 | ||
|
|
6216165515 | ||
|
|
77640d21be | ||
|
|
57282f4933 | ||
|
|
1a12e0dc11 | ||
|
|
2b0317d1f6 | ||
|
|
8fce706f31 | ||
|
|
ae0f3ab31d | ||
|
|
34cb438757 | ||
|
|
8747ba2c1d | ||
|
|
bef4e3c735 | ||
|
|
6396b8fdb7 | ||
|
|
e27ba4304d |
4
.gitignore
vendored
@@ -2,3 +2,7 @@
|
||||
*.iml
|
||||
.gradle
|
||||
build
|
||||
/bin/
|
||||
/.classpath
|
||||
/.project
|
||||
/.settings/
|
||||
|
||||
17
.travis.yml
@@ -1,7 +1,18 @@
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk7
|
||||
- oraclejdk8
|
||||
before_install:
|
||||
- chmod +x gradlew
|
||||
- chmod +x gradlew
|
||||
after_success:
|
||||
- ./gradlew jacocoTestReport coveralls
|
||||
- ./gradlew jacocoTestReport coveralls
|
||||
- ./gradlew artifactoryPublish -PbintrayUsername="${BINTRAY_USER}" -PbintrayApiKey="${BINTRAY_KEY}"
|
||||
- ./gradlew publishGhPages -PgithubUser="${GITHUB_USER}" -PgithubPassword="${GITHUB_PASSWORD}"
|
||||
--stacktrace
|
||||
notifications:
|
||||
slack: swagger2markup:Zz5kz0SnvtG6aVvZUM8yMkER
|
||||
env:
|
||||
global:
|
||||
- secure: SPKolgUdjIa/uJ+7/B/GPFlsa8IZg7NuZdFA8zROTaqew/xu+oX7qVGImseeBpPIEPJb02ac6hr7Y3/zvv0GJxIPtIbyDzVh73ImQUhT1ttLYGJfITAWqAPFF7RNNMtuOl3S2DLZ5OMJddkcFp00pa9nyI82Gk47B8GsaGIntAI=
|
||||
- secure: nXXuHfvFACZwdiFM3Ta0x/f49N7cAgi0AMkgEnQrh/2xWlvQk2z2ySGJQLkhJ7Wy8LDY7Yt1b1GUt6DlP3PuFFMW/cT4iARewqiJRXZXxUQz8fpTDeTo1nmVmW/zzII6Qj3QHM3NRbR/xDOVSJiT30Hnq2hcCBQJWYsTICmzjRk=
|
||||
- secure: Ia/wJ572M2II76roFeGEVCzIiktG4v2j/reSn60fpk1gnoEPQEObL4j1dbVCgXBLz54YWcaQ3mICvOfBPPEl9IIV3Y6DDE2sBOmB3soznfdA/YVnJx0h0f1pfXu1dwqoiv1sgc1wewQuUWq+FV7xeDhFE3cnh9CXIexe9ykip8k=
|
||||
- secure: GWfhYDsHRmTfOuEOIcHY8kT4jKBTbdhNLDQ/2amY06xenFblb4pEn6pgmn4IdK3ytjNovnZPTOOK8HqdEjhbfIGoQt6PZwuyANn4Df+zdqOC0+V+7DFG2QhEhbRCyEwPlDqTPjxlOMfAmvjFuY/NvQywoF3PYUyMfJwUV8ehmYk=
|
||||
|
||||
5
ISSUE_TEMPLATE
Normal file
@@ -0,0 +1,5 @@
|
||||
Thanks for raising a Swagger2Markup issue. Please provide a brief description of your problem along with the Swagger2Markup version you are using. If possible, please also consider putting together a complete Swagger specification that reproduces the issue. It's better if the Swagger specification is small and isolate the issue.
|
||||
|
||||
Swagger2Markup version:
|
||||
|
||||
Problem description:
|
||||
238
README.adoc
@@ -1,230 +1,66 @@
|
||||
= Swagger2Markup
|
||||
:author: Robert Winkler
|
||||
:version: 0.2.3
|
||||
:hardbreaks:
|
||||
|
||||
image:https://travis-ci.org/RobWin/swagger2markup.svg["Build Status", link="https://travis-ci.org/RobWin/swagger2markup"] image:https://coveralls.io/repos/RobWin/swagger2markup/badge.svg["Coverage Status", link="https://coveralls.io/r/RobWin/swagger2markup"] image:https://api.bintray.com/packages/robwin/maven/swagger2markup/images/download.svg[link="https://bintray.com/robwin/maven/swagger2markup/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"]
|
||||
image:https://badges.gitter.im/Join%20Chat.svg[link="https://gitter.im/RobWin/swagger2markup?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]
|
||||
image:https://travis-ci.org/Swagger2Markup/swagger2markup.svg?branch=master["Build Status", link="https://travis-ci.org/Swagger2Markup/swagger2markup"] image:https://coveralls.io/repos/Swagger2Markup/swagger2markup/badge.svg["Coverage Status", link="https://coveralls.io/r/Swagger2Markup/swagger2markup"] image:https://api.codacy.com/project/badge/grade/498a6a39d7d84ff687546359f58ee18d["Codacy code quality", link="https://www.codacy.com/app/robwin/swagger2markup"] image:https://api.bintray.com/packages/swagger2markup/Maven/swagger2markup/images/download.svg[link="https://bintray.com/swagger2markup/Maven/swagger2markup/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"] image:https://img.shields.io/badge/Twitter-rbrtwnklr-blue.svg["Twitter", link="https://twitter.com/rbrtwnklr"] image:https://badges.gitter.im/Join%20Chat.svg[link="https://gitter.im/RobWin/swagger2markup?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]
|
||||
|
||||
|
||||
== Overview
|
||||
|
||||
This project is a Swagger to Markup (AsciiDoc and Markdown) converter. The *Swagger2MarkupConverter* takes a swagger.json or swagger.yaml file as source and converts it into an AsciiDoc or Markdown document. The Swagger source file can be located locally or remotely accessible via HTTP. The Swagger2MarkupConverter supports the Swagger 1.2 and 2.0 specification. Internally it uses the _official_ https://github.com/swagger-api/swagger-parser[swagger-parser] and my https://github.com/RobWin/markup-document-builder[markup-document-builder].
|
||||
The primary goal of this project is to *simplify the generation of an up-to-date RESTful API documentation by combining documentation that's been hand-written with auto-generated API documentation* produced by https://github.com/swagger-api[Swagger]. The result is intended to be an *up-to-date, easy-to-read, on- and offline user guide*, comparable to https://developer.github.com/v3/[GitHub's API documentation]. The output of Swagger2Markup can be used as an alternative to https://github.com/swagger-api/swagger-ui[swagger-ui] and can be served as static content.
|
||||
NOTE: The Swagger Specification has been donated to to the https://openapis.org/[Open API Initiative (OAI)] and has been renamed to the https://github.com/OAI/OpenAPI-Specification[OpenAPI Specification].
|
||||
|
||||
The primary goal of this project is to simplify the documentation of RESTful APIs. The result is intended to be an easy-to-read, on- and offline user guide, comparable to https://developer.github.com/v3/[GitHub's API documentation].
|
||||
Swagger2Markup can be used together with https://github.com/springfox/springfox[springfox] and https://github.com/spring-projects/spring-restdocs[spring-restdocs]. See <<integration-with-spring-restdocs, Integration with spring-restdocs>>.
|
||||
Swagger2Markup converts a Swagger JSON or YAML file into several *AsciiDoc* or *GitHub Flavored Markdown* documents which can be combined with hand-written documentation. The Swagger source file can be located locally or remotely via HTTP. Swagger2Markup supports the Swagger 1.2 and 2.0 specification. Internally it uses the _official_ https://github.com/swagger-api/swagger-parser[swagger-parser] and my https://github.com/RobWin/markup-document-builder[markup-document-builder].
|
||||
|
||||
The project requires at least JDK 7.
|
||||
You can use Swagger2Markup to convert your contract-first Swagger YAML file into a human-readable format and combine it with hand-written documentation. As an alternative, you can choose the code-first approach and use Swagger2Markup together with https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X[Swagger JAX-RS], https://github.com/springfox/springfox[springfox] or https://github.com/spring-projects/spring-restdocs[spring-restdocs]. If you are Gradle or Maven user, you can also use the https://github.com/RobWin/swagger2markup-gradle-plugin[Swagger2Markup Gradle Plugin] or https://github.com/redowl/swagger2markup-maven-plugin[Swagger2markup Maven Plugin].
|
||||
|
||||
== Usage
|
||||
http://asciidoctor.org/docs/asciidoc-writers-guide/[AsciiDoc] is preferable to Markdown as it has more features. AsciiDoc is a text document format for writing documentation, articles, books, ebooks, slideshows, web pages and blogs. AsciiDoc files can be converted to *HTML*, *PDF* and *EPUB*. AsciiDoc is much better suited for describing public APIs than *JavaDoc* or *Annotations*.
|
||||
|
||||
=== Adding Swagger2Markup to your project
|
||||
The project is published in JCenter and Maven Central.
|
||||
You can generate your HTML5, PDF and EPUB documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/asciidoctor/asciidoctor-maven-plugin[asciidoctor-maven-plugin].
|
||||
|
||||
==== Maven
|
||||
The project requires at least JDK 8.
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<repositories>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>central</id>
|
||||
<name>bintray</name>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
== Example
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.robwin</groupId>
|
||||
<artifactId>swagger2markup</artifactId>
|
||||
<version>0.2.3</version>
|
||||
</dependency>
|
||||
----
|
||||
image::src/docs/asciidoc/images/Swagger2Markup.PNG[]
|
||||
|
||||
==== Gradle
|
||||
image::src/docs/asciidoc/images/Swagger2Markup_definitions.PNG[]
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
== Reference documentation
|
||||
- http://swagger2markup.github.io/swagger2markup/1.1.0/[Reference Documentation]
|
||||
- https://github.com/Swagger2Markup/swagger2markup/blob/master/RELEASENOTES.adoc[Release notes]
|
||||
- https://github.com/Swagger2Markup/spring-swagger2markup-demo[Demo using Swagger2Markup, Spring Boot, Springfox and spring-restdocs]
|
||||
|
||||
compile "io.github.robwin:swagger2markup:0.2.3"
|
||||
----
|
||||
== Contributing
|
||||
|
||||
=== Using Swagger2Markup
|
||||
=== Community contributions
|
||||
|
||||
Using the Swagger2MarkupConverter is simple. For instance, you can generate your AsciiDoc/Markdown documentation using https://github.com/spring-projects/spring-boot[Spring Boot] and https://github.com/springfox/springfox[springfox] as follows.
|
||||
See demo project https://github.com/RobWin/spring-swagger2markup-demo[spring-swagger2markup-demo].
|
||||
Pull requests are welcome.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SpringBootSwaggerConfig.class)
|
||||
@IntegrationTest
|
||||
@WebAppConfiguration
|
||||
public class Swagger2MarkupTest {
|
||||
=== Questions
|
||||
You can ask questions about Swagger2Markup in https://gitter.im/Swagger2Markup/swagger2markup[Gitter].
|
||||
|
||||
@Test
|
||||
public void convertSwaggerToMarkup() {
|
||||
//Remote Swagger source
|
||||
//Markdown
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).build()
|
||||
.intoFolder("src/docs/markdown");
|
||||
=== Bugs
|
||||
If you believe you have found a bug, please take a moment to search the existing issues. If no one else has reported the problem, please open a new issue that describes the problem in detail and, ideally, includes a test that reproduces it.
|
||||
|
||||
//Remote Swagger source
|
||||
//Default is AsciiDoc
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").build()
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
=== Enhancements
|
||||
If you’d like an enhancement to be made to Swagger2Markup, pull requests are most welcome. The source code is on GitHub. You may want to search the existing issues and pull requests to see if the enhancement is already being worked on. You may also want to open a new issue to discuss a possible enhancement before work on it begins.
|
||||
|
||||
//Local Swagger source
|
||||
//Default is AsciiDoc
|
||||
File file = new File(Swagger2MarkupTest.class.getResource("/json/swagger.json").getFile());
|
||||
Swagger2MarkupConverter.from(file.getAbsolutePath()).build()
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
}
|
||||
== Companies who use Swagger2Markup
|
||||
|
||||
@Test
|
||||
public void testSwagger2HtmlConversion() throws IOException {
|
||||
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger.json").getFile());
|
||||
String asciiDoc = Swagger2MarkupConverter.from(file.getAbsolutePath()).build().asString();
|
||||
String path = "src/docs/asciidocAsString";
|
||||
Files.createDirectories(Paths.get(path));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "swagger.adoc"), StandardCharsets.UTF_8)){
|
||||
writer.write(asciiDoc); }
|
||||
String asciiDocAsHtml = Asciidoctor.Factory.create().convert(asciiDoc,
|
||||
OptionsBuilder.options().backend("html5").headerFooter(true).safe(SafeMode.UNSAFE).docType("book").attributes(AttributesBuilder.attributes()
|
||||
.tableOfContents(true).tableOfContents(Placement.LEFT).sectionNumbers(true).hardbreaks(true).setAnchors(true).attribute("sectlinks")));
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "swagger.html"), StandardCharsets.UTF_8)){
|
||||
writer.write(asciiDocAsHtml);
|
||||
}
|
||||
}
|
||||
}
|
||||
----
|
||||
* Deutsche Telekom AG
|
||||
* https://restlet.com/[Restlet] -- Restlet offers an API platform, covering the https://restlet.com/products/restlet-studio/[design], https://restlet.com/products/dhc/[test] and https://restlet.com/products/apispark/[operation] of Web APIs, and uses Swagger2Markup to generate appealing HTML documentation from API definitions.
|
||||
* http://www.qaware.de/[QAware GmbH]
|
||||
* http://www.appdirect.com/[AppDirect] -- The leading commerce platform for selling cloud services.
|
||||
* http://www.wescale.com[wescale]
|
||||
* http://taskassure.com[TaskAssure]
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
@EnableSwagger
|
||||
public class SpringBootSwaggerConfig {
|
||||
== License
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootTestConfig.class, args);
|
||||
}
|
||||
Copyright 2015 Robert Winkler
|
||||
|
||||
@Autowired
|
||||
private SpringSwaggerConfig springSwaggerConfig;
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
@Bean
|
||||
public SwaggerSpringMvcPlugin customImplementation(){
|
||||
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
|
||||
.apiInfo(apiInfo()).excludeAnnotations(Controller.class);
|
||||
}
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
ApiInfo apiInfo = new ApiInfo(
|
||||
"My Apps API Title",
|
||||
"My Apps API Description",
|
||||
"My Apps API terms of service",
|
||||
"My Apps API Contact Email",
|
||||
"My Apps API Licence Type",
|
||||
"My Apps API License URL"
|
||||
);
|
||||
return apiInfo;
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
You can generate your HTML5 and PDF documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/aalmiray/markdown-gradle-plugin[markdown-gradle-plugin].
|
||||
You can also use https://github.com/tomchristie/mkdocs[MkDocs] and https://github.com/rtfd/readthedocs.org[ReadTheDocs] to publish your Markdown documentation.
|
||||
See http://spring-swagger2markup-demo.readthedocs.org/[ReadTheDocs-demo]
|
||||
|
||||
== Examples
|
||||
== Swagger source file
|
||||
image::images/swagger_json.PNG[swagger_json]
|
||||
|
||||
=== Generated AsciiDoc file
|
||||
image::images/asciidoc.PNG[asciidoc]
|
||||
|
||||
=== Generated Markdown file
|
||||
image::images/markdown.PNG[markdown]
|
||||
|
||||
=== Generated HTML using AsciidoctorJ
|
||||
image::images/asciidoc_html.PNG[asciidoc_html]
|
||||
|
||||
=== Generated HTML using Mkdocs
|
||||
image::images/mkdocs_html.PNG[mkdocs_html]
|
||||
|
||||
=== Generated PDF using AsciidoctorJ
|
||||
image::images/asciidoc_pdf.PNG[asciidoc_pdf]
|
||||
|
||||
|
||||
== Integration with spring-restdocs
|
||||
https://github.com/spring-projects/spring-restdocs[spring-restdocs] can be used together with Swagger2Markup.
|
||||
Swagger2Markup can include the generated examples from spring-restdocs into the generated AsciiDoc document.
|
||||
Currently it does not work for Markdown, since spring-restdocs generates only AsciiDoc files.
|
||||
|
||||
Let's say I have a Swagger-annotated Spring RestController method with an ApiOperation value: _"Create a quota"_
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@ApiOperation(value = "Create a quota", notes = "Create a quota allows bla bla bla bla")
|
||||
public void createMailStorageQuota(@ApiParam(name = "MailStorageQuota",
|
||||
value = "MailStorageQuota", required = true) @RequestBody MailStorageQuota mailStorageQuota) {
|
||||
}
|
||||
----
|
||||
|
||||
I'm using spring-restdocs in combination with https://github.com/jayway/rest-assured to test the Controller.
|
||||
The target folder of the generated request and response example files must be _"create_a_quota"_ (similar to the value of the ApiOperation).
|
||||
|
||||
[source,java]
|
||||
----
|
||||
given().contentType(ContentType.XML).body(storageQuota).resultHandlers(document("create_a_quota")).
|
||||
when().put("/quotas").
|
||||
then().statusCode(204);
|
||||
----
|
||||
|
||||
The spring-restdocs output directory is configured as follows:
|
||||
|
||||
[source]
|
||||
----
|
||||
io.restdocumented.outputDir = docs/generated
|
||||
----
|
||||
|
||||
The Swagger2MarkupConverter must know the output directory of spring-restdocs.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").
|
||||
withExamples("docs/generated").build()
|
||||
.intoFolder("src/docs/asciidoc");
|
||||
----
|
||||
|
||||
The Swagger2MarkupConverter searches for a Swagger ApiOperation with value: _"Create a quota"_ in a folder called _"docs/generated/create_a_quota"_ and includes the _request.asciidoc_ and _response.asciidoc_ files, if they are available.
|
||||
|
||||
== Integration of JSON and XML Schema files.
|
||||
Swagger2Markup can also include JSON and XML Schema files into the generated document.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
Swagger2MarkupConverter.from("http://localhost:8080/api-docs").
|
||||
withMarkupLanguage(MarkupLanguage.MARKDOWN).
|
||||
withExamples("docs/generated").withSchemas("docs/schemas").build()
|
||||
.intoFolder("src/docs/markdown");
|
||||
----
|
||||
|
||||
I create the Schemas files in Unit-Tests as follows:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
RestDocumented restDocumented = RestDocumented.fromProperties();
|
||||
restDocumented.documentJsonSchema(MailStorageQuota.class, "docs/schemas");
|
||||
restDocumented.documentXmlSchema(MailStorageQuota.class, "docs/schemas");
|
||||
----
|
||||
|
||||
I will make RestDocumented public soon. RestDocumented creates a MailStorageQuota.xsd and MailStorageQuota.json file in the folder "docs/schemas".
|
||||
The Swagger2MarkupConverter will include the JSON and XML Schemas, if a Swagger Operation uses the MailStorageQuota class as Input or Output.
|
||||
|
||||
See example: http://spring-swagger2markup-demo.readthedocs.org/en/latest/generated/definitions/[ReadTheDocs-demo]
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
@@ -1,20 +1,117 @@
|
||||
= Release Notes
|
||||
|
||||
== Version 0.1.0
|
||||
* Initial version with support for AsciiDoc and Markdown
|
||||
|
||||
== Version 0.2.0
|
||||
* This version is not downward compatible. This version supports includes of example files and JSON/XML Schema files. See documentation.
|
||||
|
||||
=== Version 0.2.1
|
||||
* Signed jar files and published in Maven Central
|
||||
|
||||
=== Version 0.2.2
|
||||
* Fixed wrong dependency version to io.github.robwin:markup-document-builder
|
||||
|
||||
=== Version 0.2.3
|
||||
* Fixed issue #7: @ApiModelProperty metadata are ignored for definitions file
|
||||
|
||||
=== Version 0.2.4
|
||||
* Fixed issue #8: logback.xml on the classpath
|
||||
* Fixed issue #13: unknown format not supported for properties
|
||||
= Release Notes
|
||||
|
||||
== Version 0.1.0
|
||||
* Initial version with support for AsciiDoc and Markdown
|
||||
|
||||
== Version 0.2.0
|
||||
* This version is not downward compatible. This version supports includes of example files and JSON/XML Schema files. See documentation.
|
||||
|
||||
=== Version 0.2.1
|
||||
* Signed jar files and published in Maven Central
|
||||
|
||||
=== Version 0.2.2
|
||||
* Fixed wrong dependency version to io.github.robwin:markup-document-builder
|
||||
|
||||
=== Version 0.2.3
|
||||
* Fixed issue #7: @ApiModelProperty metadata are ignored for definitions file
|
||||
|
||||
=== Version 0.2.4
|
||||
* Fixed issue #8: logback.xml on the classpath
|
||||
* Fixed issue #13: unknown format not supported for properties
|
||||
|
||||
== Version 0.3.0
|
||||
* Support of YAML or JSON String as input.
|
||||
|
||||
== Version 0.4.0
|
||||
* Updated Swagger-Parser from 1.0.0 to 1.0.5
|
||||
* Updated commons-lang to commons-lang3
|
||||
* Swagger2MarkupConverter generates three documents now: overview, paths and definitions
|
||||
* Support for enums in HeaderParameter, QueryParameter, FormParameter and QueryParameter
|
||||
* Support for global consumes, produces and tags
|
||||
|
||||
== Version 0.5.0
|
||||
* Support for including hand-written descriptions instead of using Swagger Annotations for descriptions
|
||||
|
||||
=== Version 0.5.1
|
||||
* Bugfix: Definition name must be lowercase so that descriptions file can be found
|
||||
|
||||
=== Version 0.5.2
|
||||
* Swagger License is not mandatory anymore
|
||||
* Updated markup-document-builder from v0.1.3 to v0.1.4
|
||||
|
||||
=== Version 0.5.3
|
||||
* Fixed compiler warning: [options] bootstrap class path not set in conjunction with -source 1.7
|
||||
|
||||
== Version 0.6.0
|
||||
* Updated swagger-parser from v1.0.5 to v1.0.6
|
||||
* Support for default values in Parameters and Model properties
|
||||
|
||||
=== Version 0.6.1
|
||||
* Updated swagger-parser from v1.0.6 to v1.0.8
|
||||
|
||||
=== Version 0.6.2
|
||||
* curl-request.adoc from spring-restdocs is also added to the example chapters
|
||||
|
||||
=== Version 0.6.3
|
||||
* Added possibility to write object definitions to separate files. Issue #19
|
||||
|
||||
== Version 0.7.0
|
||||
* Added support for both reference models and composed models
|
||||
|
||||
=== Version 0.7.1
|
||||
* Workaround: If the type of a BodyParameter is String and not a Model, the schema is null and lost. Therefore the fallback type of a BodyParameter is String now.
|
||||
|
||||
== Version 0.8.0
|
||||
* Enhancement #26 and #27: Added a pre-process hook to modify a Swagger Model before it is converted.
|
||||
* Bugfix #29: Tags are rendered twice
|
||||
|
||||
== Version 0.9.0
|
||||
* Updated swagger-parser from v1.0.8 to v1.0.13
|
||||
* Support for global responses and parameters
|
||||
|
||||
=== Version 0.9.1
|
||||
* Added support to group the paths by tags or as-is
|
||||
* Added support to order the definitions by natural ordering or as-is
|
||||
|
||||
=== Version 0.9.2
|
||||
* Multi language support. Added russian.
|
||||
|
||||
=== Version 0.9.3
|
||||
* Updated swagger-parser from v1.0.13 to v1.0.16
|
||||
* Enhancement #61: Refactor separated documents logic to support inter-document cross-references
|
||||
* Enhancement #53: Support for tags, paths and methods ordering
|
||||
* Enhancement #51: Support for separated operations files
|
||||
* Enhancement #52: Markdown generation for inline schemas
|
||||
|
||||
== Version 1.0.0
|
||||
* New configuration API
|
||||
* New extension SPI
|
||||
* Added new languages: turkish, german, france
|
||||
* New security document
|
||||
* Inline schema support
|
||||
* New configuration options
|
||||
* Support of deprecated path operations
|
||||
|
||||
=== Version 1.0.1
|
||||
* Enhancement: Support to render validation constraints of properties
|
||||
* Enhancement: Possibility to disable rendering of the security chapter below operations
|
||||
|
||||
== Version 1.1.0
|
||||
* PR #177: Fixed rendering of recursive examples
|
||||
* PR #186: Add support for Chinese language
|
||||
* PR #190: Add support for Spanish language
|
||||
* PR #192: Updated min/max value to format correctly based on the data type
|
||||
* PR #193: Added support for exclusiveMin and exclusiveMax
|
||||
|
||||
=== Version 1.1.1
|
||||
* Issue #194: Added a config parameter which allows to prepend the basePath to all paths.
|
||||
* Updated swagger-parser from v1.0.16 to v1.0.23
|
||||
* Added javslang v2.0.4 as a dependency
|
||||
* Added paleo-core v0.10.1 as a dependency
|
||||
* Updated markup-document-builder from 1.0.0 to 1.1.0
|
||||
* PR #201: Add support for Brazilian Portuguese language
|
||||
* PR #202: Add support for Japanese language
|
||||
* Issue #205: Fixed the option to influence resource ordering
|
||||
* Issue #198: Chinese chinese language encoding
|
||||
* Issue #207: Properties that start with an underscore are displayed correctly now
|
||||
* Refactored Swagger2Markup to use a Component-Based design. A document can be composed of components and components can be composed of other components.
|
||||
115
build.gradle
@@ -4,110 +4,67 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.2'
|
||||
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.6'
|
||||
classpath 'io.spring.gradle:dependency-management-plugin:0.4.0.RELEASE'
|
||||
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
|
||||
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.10.1'
|
||||
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1'
|
||||
classpath 'org.asciidoctor:asciidoctorj:1.5.2'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
|
||||
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0"
|
||||
classpath "org.ajoberstar:gradle-git:1.3.2"
|
||||
}
|
||||
}
|
||||
description = 'swagger2markup Build'
|
||||
version = '0.2.4'
|
||||
group = 'io.github.robwin'
|
||||
version = '1.1.1'
|
||||
ext.releaseVersion = '1.1.0'
|
||||
group = 'io.github.swagger2markup'
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'org.asciidoctor.convert'
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'com.github.kt3k.coveralls'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
apply plugin: 'eclipse'
|
||||
apply from: 'gradle/publishing.gradle'
|
||||
apply from: 'gradle/coverage.gradle'
|
||||
apply from: 'gradle/documentation.gradle'
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
sourceCompatibility = "1.7"
|
||||
targetCompatibility = "1.7"
|
||||
sourceCompatibility = "1.8"
|
||||
targetCompatibility = "1.8"
|
||||
options.deprecation = true
|
||||
options.encoding = 'UTF-8'
|
||||
options.compilerArgs << "-Xlint:unchecked"
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url "https://oss.jfrog.org/artifactory/oss-snapshot-local"
|
||||
}
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
//mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'io.github.robwin:markup-document-builder'
|
||||
compile 'io.swagger:swagger-compat-spec-parser'
|
||||
compile 'commons-collections:commons-collections'
|
||||
compile 'commons-io:commons-io'
|
||||
compile 'ch.qos.logback:logback-classic'
|
||||
testCompile 'junit:junit'
|
||||
testCompile 'org.asciidoctor:asciidoctorj:1.5.2'
|
||||
testCompile 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.6'
|
||||
compile 'io.github.swagger2markup:markup-document-builder:1.1.0'
|
||||
compile 'io.swagger:swagger-compat-spec-parser:1.0.23'
|
||||
compile 'org.apache.commons:commons-configuration2:2.1'
|
||||
compile 'commons-beanutils:commons-beanutils:1.9.2'
|
||||
compile 'org.apache.commons:commons-collections4:4.1'
|
||||
compile 'io.javaslang:javaslang:2.0.4'
|
||||
compile 'ch.netzwerg:paleo-core:0.10.1'
|
||||
testCompile 'junit:junit:4.11'
|
||||
testCompile 'org.asciidoctor:asciidoctorj:1.5.4'
|
||||
testCompile 'ch.qos.logback:logback-classic:1.1.2'
|
||||
testCompile 'org.assertj:assertj-core:3.5.2'
|
||||
testCompile 'io.github.robwin:assertj-diff:0.1.1'
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
dependencies {
|
||||
"io.github.robwin:markup-document-builder" "0.1.2"
|
||||
"io.swagger:swagger-compat-spec-parser" "1.0.0"
|
||||
"commons-collections:commons-collections" "3.2.1"
|
||||
"commons-io:commons-io" "2.4"
|
||||
"com.mangofactory:swagger-springmvc" "0.9.5"
|
||||
"com.jayway.restassured:spring-mock-mvc" "2.4.0"
|
||||
"ch.qos.logback:logback-classic" "1.1.2"
|
||||
"junit:junit" "4.11"
|
||||
test {
|
||||
if (System.properties['http.proxyHost']) {
|
||||
systemProperty 'http.proxyHost', System.properties['http.proxyHost']
|
||||
systemProperty 'http.proxyPort', System.properties['http.proxyPort']
|
||||
systemProperty 'http.nonProxyHosts', System.properties['http.nonProxyHosts']
|
||||
}
|
||||
systemProperty 'file.encoding', 'UTF-8'
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
}
|
||||
|
||||
asciidoctor {
|
||||
sources {
|
||||
include 'index.adoc'
|
||||
}
|
||||
backends = ['html5', 'pdf']
|
||||
attributes = [
|
||||
doctype: 'book',
|
||||
toc: 'left',
|
||||
toclevels: '2',
|
||||
numbered: '',
|
||||
sectlinks: '',
|
||||
sectanchors: ''
|
||||
]
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
reports {
|
||||
xml.enabled = true // coveralls plugin depends on xml format report
|
||||
html.enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
tasks.coveralls {
|
||||
dependsOn 'check'
|
||||
}
|
||||
|
||||
tasks.asciidoctor {
|
||||
dependsOn 'check'
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.2.1'
|
||||
gradleVersion = '3.1'
|
||||
}
|
||||
|
||||
13
gradle/coverage.gradle
Normal file
@@ -0,0 +1,13 @@
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'com.github.kt3k.coveralls'
|
||||
|
||||
jacocoTestReport {
|
||||
reports {
|
||||
xml.enabled = true // coveralls plugin depends on xml format report
|
||||
html.enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
tasks.coveralls {
|
||||
dependsOn 'check'
|
||||
}
|
||||
35
gradle/documentation.gradle
Normal file
@@ -0,0 +1,35 @@
|
||||
apply plugin: 'org.asciidoctor.convert'
|
||||
apply plugin: 'org.ajoberstar.github-pages'
|
||||
|
||||
asciidoctor {
|
||||
sources {
|
||||
include 'index.adoc'
|
||||
}
|
||||
backends = ['html5', 'pdf']
|
||||
attributes = [
|
||||
doctype: 'book',
|
||||
toc: 'left',
|
||||
toclevels: '3',
|
||||
numbered: '',
|
||||
sectlinks: '',
|
||||
sectanchors: '',
|
||||
hardbreaks: '',
|
||||
'release-version': project.releaseVersion
|
||||
]
|
||||
}
|
||||
|
||||
publishGhPages.dependsOn asciidoctor
|
||||
|
||||
githubPages {
|
||||
repoUri = 'https://github.com/Swagger2Markup/swagger2markup.git'
|
||||
|
||||
credentials {
|
||||
username = project.hasProperty('githubUser') ? project.githubUser : System.getenv('GITHUB_USER')
|
||||
password = project.hasProperty('githubPassword') ? project.githubPassword : System.getenv('GITHUB_PASSWORD')
|
||||
}
|
||||
|
||||
pages {
|
||||
from file(asciidoctor.outputDir.path + '/html5')
|
||||
into project.releaseVersion
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,44 @@
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
apply plugin: "com.jfrog.artifactory"
|
||||
|
||||
Date buildTimeAndDate = new Date()
|
||||
ext {
|
||||
buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
|
||||
buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate)
|
||||
projectUrl = 'https://github.com/Swagger2Markup/swagger2markup'
|
||||
licenseUrl = 'https://github.com/Swagger2Markup/swagger2markup/blob/master/LICENSE.txt'
|
||||
scmUrl = 'https://github.com/Swagger2Markup/swagger2markup.git'
|
||||
issuesUrl = 'https://github.com/Swagger2Markup/swagger2markup/issues'
|
||||
}
|
||||
|
||||
def projectArtifactId = 'swagger2markup'
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
'Built-By': 'Robert Winkler',
|
||||
'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")",
|
||||
'Build-Date': project.buildDate,
|
||||
'Build-Time': project.buildTime,
|
||||
'Specification-Title': projectArtifactId,
|
||||
'Specification-Version': project.version,
|
||||
'Implementation-Title': projectArtifactId,
|
||||
'Implementation-Version': project.version
|
||||
'Built-With': "gradle-${project.getGradle().getGradleVersion()}, groovy-${GroovySystem.getVersion()}",
|
||||
'Build-Time': "${new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")}",
|
||||
'Specification-Title': "${project.name}",
|
||||
'Specification-Version': project.version.toString(),
|
||||
'Implementation-Title': "${project.name}",
|
||||
'Implementation-Version': project.version.toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -29,35 +49,6 @@ if (!project.hasProperty('gpgPassphrase')) ext.gpgPassphrase = ''
|
||||
if (!project.hasProperty('ossUser')) ext.ossUser = ''
|
||||
if (!project.hasProperty('ossPassword')) ext.ossPassword = ''
|
||||
|
||||
bintray {
|
||||
user = project.bintrayUsername
|
||||
key = project.bintrayApiKey
|
||||
dryRun = false //Whether to run this as dry-run, without deploying
|
||||
publish = true //If version should be auto published after an upload
|
||||
publications = ['mavenJava']
|
||||
pkg {
|
||||
repo = 'maven'
|
||||
name = 'swagger2markup'
|
||||
websiteUrl = 'https://github.com/RobWin/swagger2markup'
|
||||
issueTrackerUrl = 'https://github.com/RobWin/swagger2markup/issues'
|
||||
vcsUrl = 'https://github.com/RobWin/swagger2markup.git'
|
||||
desc = 'A Swagger to Markup (AsciiDoc and Markdown) converter.'
|
||||
licenses = ['Apache-2.0']
|
||||
version {
|
||||
vcsTag = project.version
|
||||
gpg {
|
||||
sign = true //Determines whether to GPG sign the files. The default is false
|
||||
passphrase = project.gpgPassphrase //Optional. The passphrase for GPG signing'
|
||||
}
|
||||
mavenCentralSync {
|
||||
sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
|
||||
user = ossUser //OSS user token
|
||||
password = ossPassword //OSS user password
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
@@ -74,17 +65,17 @@ publishing {
|
||||
it.scope*.value = 'compile'
|
||||
}
|
||||
|
||||
root.appendNode('name', 'swagger2markup')
|
||||
root.appendNode('name', project.name)
|
||||
root.appendNode('packaging', 'jar')
|
||||
root.appendNode('url', 'https://github.com/RobWin/swagger2markup')
|
||||
root.appendNode('description', 'A Swagger to Markup (AsciiDoc and Markdown) converter.')
|
||||
root.appendNode('url', projectUrl)
|
||||
root.appendNode('description', project.description)
|
||||
|
||||
def license = root.appendNode('licenses').appendNode('license')
|
||||
license.appendNode('name', 'Apache-2.0')
|
||||
license.appendNode('url', 'https://github.com/RobWin/swagger2markup/blob/master/LICENSE.txt')
|
||||
license.appendNode('url', licenseUrl)
|
||||
license.appendNode('distribution', 'repo')
|
||||
|
||||
root.appendNode('scm').appendNode('url', 'https://github.com/RobWin/swagger2markup.git')
|
||||
root.appendNode('scm').appendNode('url', scmUrl)
|
||||
|
||||
def developers = root.appendNode('developers')
|
||||
devs.each {
|
||||
@@ -97,4 +88,64 @@ publishing {
|
||||
artifact javadocJar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bintray {
|
||||
user = project.bintrayUsername
|
||||
key = project.bintrayApiKey
|
||||
dryRun = false //Whether to run this as dry-run, without deploying
|
||||
publish = true //If version should be auto published after an upload
|
||||
publications = ['mavenJava']
|
||||
pkg {
|
||||
repo = 'Maven'
|
||||
name = 'swagger2markup'
|
||||
userOrg = 'swagger2markup'
|
||||
websiteUrl = projectUrl
|
||||
issueTrackerUrl = issuesUrl
|
||||
vcsUrl = scmUrl
|
||||
desc = rootProject.description
|
||||
licenses = ['Apache-2.0']
|
||||
version {
|
||||
vcsTag = rootProject.version
|
||||
gpg {
|
||||
sign = true //Determines whether to GPG sign the files. The default is false
|
||||
passphrase = project.gpgPassphrase //Optional. The passphrase for GPG signing'
|
||||
}
|
||||
mavenCentralSync {
|
||||
sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
|
||||
user = ossUser //OSS user token
|
||||
password = ossPassword //OSS user password
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
artifactory {
|
||||
contextUrl = 'https://oss.jfrog.org'
|
||||
resolve {
|
||||
repository {
|
||||
repoKey = 'libs-release'
|
||||
}
|
||||
}
|
||||
publish {
|
||||
repository {
|
||||
repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to
|
||||
//when using oss.jfrog.org the credentials are from Bintray. For local build we expect them to be found in
|
||||
//~/.gradle/gradle.properties, otherwise to be set in the build server
|
||||
username = project.hasProperty('bintrayUsername') ? project.bintrayUsername : System.getenv('BINTRAY_USER')
|
||||
password = project.hasProperty('bintrayApiKey') ? project.bintrayApiKey : System.getenv('BINTRAY_KEY')
|
||||
}
|
||||
defaults {
|
||||
publications('mavenJava')
|
||||
}
|
||||
}
|
||||
if (System.properties['https.proxyHost']) {
|
||||
clientConfig.proxy.host = System.properties['https.proxyHost']
|
||||
clientConfig.proxy.port = System.properties['https.proxyPort'].toInteger()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
tasks.artifactoryPublish {
|
||||
dependsOn 'check'
|
||||
}
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Fri Feb 13 13:57:45 CET 2015
|
||||
#Thu Nov 03 09:37:13 CET 2016
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip
|
||||
|
||||
10
gradlew
vendored
Normal file → Executable file
@@ -42,11 +42,6 @@ case "`uname`" in
|
||||
;;
|
||||
esac
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||
if $cygwin ; then
|
||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
fi
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
@@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >&-
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >&-
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
@@ -114,6 +109,7 @@ fi
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
|
||||
180
gradlew.bat
vendored
@@ -1,90 +1,90 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
||||
|
Before Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 95 KiB |
|
Before Width: | Height: | Size: 124 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 26 KiB |
94
src/docs/asciidoc/advanced_usage.adoc
Normal file
@@ -0,0 +1,94 @@
|
||||
== Advanced usage
|
||||
|
||||
[[swagger_operationId]]
|
||||
=== Swagger operationId
|
||||
|
||||
Swagger2Markup uniquely identify each operations for multiple purposes :
|
||||
|
||||
* generating separated operation files : file name
|
||||
* generating unique Markup anchors for operations and all sub-items.
|
||||
* searching for extra content for operations : operation folder name for content plugins (Hand-written descriptions, Dynamic content, etc...)
|
||||
* ...
|
||||
|
||||
Swagger specification supports the `operationId` field which create an unique name for each operation.
|
||||
When provided, this `operationId` value will be used primarily. Otherwise Swagger2Markup generates an id using `normalize(operation.summary + " " + lowerCase(operation.HTTPmethod))`.
|
||||
|
||||
IMPORTANT: It is highly recommended to set an operationId for each operation, so that a lot of actions does not depend on operation `summary` which *can change at anytime*.
|
||||
|
||||
=== Swagger schema title
|
||||
|
||||
Swagger2Markup displays inline schemas by decomposing them (when schema is complex). In this process, some intermediate references are generated using field names which is not always the best choice.
|
||||
The Swagger document supports JSON Schema `title` items in inline schemas.
|
||||
It's recommended to use them in inline schemas so that they'll be used primarily to field names and this will lead to a better naming.
|
||||
|
||||
.Inline schema without title items
|
||||
====
|
||||
[source,yaml,subs="quotes"]
|
||||
----
|
||||
InlinePet:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
category:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tags:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
----
|
||||
|
||||
image::images/untitledSwagger.png[]
|
||||
====
|
||||
|
||||
.Inline schema with title items
|
||||
====
|
||||
[source,yaml,subs="quotes"]
|
||||
----
|
||||
InlineTitlePet:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
category:
|
||||
type: object
|
||||
*title: CategoryModel*
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tags:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
*title: TagModel*
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
----
|
||||
|
||||
image::images/titledSwagger.png[]
|
||||
====
|
||||
103
src/docs/asciidoc/command_line_interface.adoc
Normal file
@@ -0,0 +1,103 @@
|
||||
== Command Line Interface
|
||||
|
||||
Swagger2Markup provides a Command line interface (CLI). The CLI is published in JCenter and Maven Central. The artifacts can be viewed at the following locations:
|
||||
|
||||
* Releases: https://jcenter.bintray.com/io/github/swagger2markup/swagger2markup-cli/
|
||||
|
||||
* Snapshots: https://oss.jfrog.org/artifactory/oss-snapshot-local/io/github/swagger2markup/swagger2markup-cli/
|
||||
|
||||
NOTE: The CLI requires at least JDK 8.
|
||||
|
||||
=== Usage guide
|
||||
|
||||
==== Show help
|
||||
|
||||
You can show the help:
|
||||
|
||||
[source, subs="attributes"]
|
||||
----
|
||||
java -jar swagger2markup-cli-{release-version}.jar help convert
|
||||
----
|
||||
|
||||
Output:
|
||||
----
|
||||
NAME
|
||||
swagger2markup convert - Converts a Swagger JSON or YAML file into
|
||||
Markup documents.
|
||||
|
||||
SYNOPSIS
|
||||
swagger2markup convert [(-c <configFile> | --config <configFile>)]
|
||||
[(-d <outputDir> | --outputDir <outputDir>)]
|
||||
[(-f <outputFile> | --outputFile <outputFile>)]
|
||||
(-i <swaggerInput> | --swaggerInput <swaggerInput>)
|
||||
|
||||
OPTIONS
|
||||
-c <configFile>, --config <configFile>
|
||||
Config file.
|
||||
|
||||
-d <outputDir>, --outputDir <outputDir>
|
||||
Output directory. Converts the Swagger specification into multiple
|
||||
files.
|
||||
|
||||
-f <outputFile>, --outputFile <outputFile>
|
||||
Output file. Converts the Swagger specification into one file.
|
||||
|
||||
-h, --help
|
||||
Display help information
|
||||
|
||||
-i <swaggerInput>, --swaggerInput <swaggerInput>
|
||||
Swagger input. Can either be a URL or a file path.
|
||||
|
||||
|
||||
----
|
||||
|
||||
==== Conversion into a folder
|
||||
|
||||
You can convert a Swagger file into a folder as follows:
|
||||
|
||||
[source, subs="attributes"]
|
||||
----
|
||||
java -jar swagger2markup-cli-{release-version}.jar convert -i /path/to/swagger_petstore.yaml -d /tmp/asiidoc
|
||||
----
|
||||
|
||||
It generates the Markup documents into the `/tmp/asiidoc` folder.
|
||||
|
||||
==== Conversion into a file
|
||||
|
||||
You can convert a local Swagger file into a file as follows:
|
||||
|
||||
[source, subs="attributes"]
|
||||
----
|
||||
java -jar swagger2markup-cli-{release-version}.jar convert -i /path/to/swagger_petstore.yaml -f /tmp/asiidoc/swagger
|
||||
----
|
||||
|
||||
NOTE: The input file must not have a file extension
|
||||
|
||||
It generates the Markup documents into the file `/tmp/asiidoc/swagger.adoc`.
|
||||
|
||||
==== Conversion of a remote Swagger file
|
||||
|
||||
You can convert a remote Swagger specification which must be accessible via HTTP.
|
||||
|
||||
[source, subs="attributes"]
|
||||
----
|
||||
java -jar swagger2markup-cli-{release-version}.jar convert -i "http://petstore.swagger.io/v2/swagger.json" -d /tmp
|
||||
----
|
||||
|
||||
=== Configuration
|
||||
|
||||
Create a `config.properties` file to customize the <<Swagger2Markup properties>>. For Example:
|
||||
|
||||
.config.properties
|
||||
----
|
||||
swagger2markup.markupLanguage=MARKDOWN
|
||||
swagger2markup.outputLanguage=DE
|
||||
----
|
||||
|
||||
Invoke the CLI as follows:
|
||||
|
||||
[source, subs="attributes"]
|
||||
----
|
||||
java -jar swagger2markup-cli-{release-version}.jar convert -i /path/to/swagger_petstore.yaml -o /tmp -c /path/to/config.properties
|
||||
----
|
||||
|
||||
10
src/docs/asciidoc/contributing.adoc
Normal file
@@ -0,0 +1,10 @@
|
||||
== Contributing
|
||||
|
||||
=== Questions
|
||||
You can ask questions about Swagger2Markup in https://gitter.im/Swagger2Markup/swagger2markup[Gitter].
|
||||
|
||||
=== Bugs
|
||||
If you believe you have found a bug, please take a moment to search the existing issues. If no one else has reported the problem, please open a new issue that describes the problem in detail and, ideally, includes a test that reproduces it.
|
||||
|
||||
=== Enhancements
|
||||
If you’d like an enhancement to be made to Swagger2Markup, pull requests are most welcome. The source code is on GitHub. You may want to search the existing issues and pull requests to see if the enhancement is already being worked on. You may also want to open a new issue to discuss a possible enhancement before work on it begins.
|
||||
@@ -1,55 +0,0 @@
|
||||
== Definitions
|
||||
=== User
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|username||string|false
|
||||
|firstName||string|false
|
||||
|lastName||string|false
|
||||
|email||string|false
|
||||
|password||string|false
|
||||
|phone||string|false
|
||||
|userStatus|User Status|integer (int32)|false
|
||||
|===
|
||||
|
||||
=== Category
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|name||string|false
|
||||
|===
|
||||
|
||||
=== Pet
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|category||<<Category>>|false
|
||||
|name||string|true
|
||||
|photoUrls||string array|true
|
||||
|tags||<<Tag>> array|false
|
||||
|status|pet status in the store|string|false
|
||||
|===
|
||||
|
||||
=== Tag
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|name||string|false
|
||||
|===
|
||||
|
||||
=== Order
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|petId||integer (int64)|false
|
||||
|quantity||integer (int32)|false
|
||||
|shipDate||string (date-time)|false
|
||||
|status|Order Status|string|false
|
||||
|complete||boolean|false
|
||||
|===
|
||||
|
||||
82
src/docs/asciidoc/demo.adoc
Normal file
@@ -0,0 +1,82 @@
|
||||
== Spring Boot and Springfox
|
||||
|
||||
If you use Spring Boot and Springfox or Swagger JAX-RS, you can do the following:
|
||||
|
||||
* generate an up-to-date Swagger JSON file during an unit or integration test
|
||||
* convert the Swagger JSON file into AsciiDoc
|
||||
* add hand-written AsciiDoc documentation
|
||||
* convert AsciiDoc into HTML and PDF
|
||||
* copy the HTML and PDF artifacts into an executable Spring Boot Jar file and serve it as static content
|
||||
|
||||
This transformation pipeline can be done with Gradle or Maven in the build phase. That way there is no runtime overhead and there are no additional runtime libraries required.
|
||||
|
||||
The Swagger2MarkupConverter can be used to make a request to a remote Swagger endpoint during an integration test. The Swagger2MarkupConverter allows to write the generated documents into any folder. In this this example it is ``src/docs/asciidoc/generated``.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = {Application.class, SwaggerConfig.class})
|
||||
@WebIntegrationTest
|
||||
public class Swagger2MarkupTest {
|
||||
|
||||
@Test
|
||||
public void convertRemoteSwaggerToAsciiDoc() {
|
||||
// Remote Swagger source
|
||||
Swagger2MarkupConverter.from(new URL("http://localhost:8080/v2/api-docs")).build()
|
||||
.toFolder(Paths.get("src/docs/asciidoc/generated"));
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
Spring's MVC Test framework can also be used to make a request to a Springfox Swagger endpoint during an unit test. A custom ResultHandler ``Swagger2MarkupResultHandler`` can be used to write the Swagger JSON response into a directory. The custom ResultHandler is part of ``springfox-staticdocs``. That way you also verify that your Swagger endpoint is working.
|
||||
The Swagger JSON response can be converted using the <<Gradle Plugin>> or <<Maven Plugin>>.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@WebAppConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = {Application.class, SwaggerConfig.class})
|
||||
public class Swagger2MarkupTest {
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext context;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertSwaggerToAsciiDoc() throws Exception {
|
||||
this.mockMvc.perform(get("/v2/api-docs")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(Swagger2MarkupResultHandler
|
||||
.outputDirectory("src/docs/asciidoc/generated").build())
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
=== Demo
|
||||
|
||||
The quickest way to get started is to look at the demo project https://github.com/Swagger2Markup/spring-swagger2markup-demo[spring-swagger2markup-demo]. The demo shows how to generate static docs (HTML5 and PDF) by using the Swagger2Markup Gradle Plugin and serve the generated documentation as static content in a Spring Boot App under http://localhost:9080/docs/index.html and http://localhost:9080/docs/index.pdf.
|
||||
|
||||
If you want to start the Spring Boot application, please run:
|
||||
|
||||
[source, java, subs="attributes"]
|
||||
----
|
||||
gradlew clean build
|
||||
----
|
||||
|
||||
----
|
||||
java -jar build/libs/spring-swagger2markup-demo-{project-version}.jar
|
||||
----
|
||||
|
||||
If you only want to generate the HTML and PDF documentation, please run:
|
||||
|
||||
----
|
||||
gradlew clean asciidoctor
|
||||
----
|
||||
|
||||
13
src/docs/asciidoc/docker.adoc
Normal file
@@ -0,0 +1,13 @@
|
||||
== Docker image
|
||||
|
||||
The Swagger2Markup-CLI has been published as a Docker image on DockerHub.
|
||||
|
||||
=== Usage guide
|
||||
|
||||
You can pull the Swagger2Markup image as follows:
|
||||
|
||||
`docker pull swagger2markup/swagger2markup`
|
||||
|
||||
You can convert a Swagger Spec by running a Docker container as follows:
|
||||
|
||||
`docker run --rm -v $(pwd):/opt swagger2markup/swagger2markup convert -i /opt/swagger.yaml -f /opt/swagger -c /opt/config.properties`
|
||||
187
src/docs/asciidoc/extension_spi.adoc
Normal file
@@ -0,0 +1,187 @@
|
||||
== Extension SPI
|
||||
|
||||
Swagger2Markup provides an Extension SPI to extend the functionality of Swagger2Markup. Five types of extension are available. An extension is an abstract class which must be implemented.
|
||||
|
||||
[options="header"]
|
||||
.Swagger2Markup extensions
|
||||
|====
|
||||
| Name | Class | Description
|
||||
| <<OverviewDocumentExtension>> | io.github.swagger2markup.spi.OverviewDocumentExtension | Can be used to extend the content of the Overview document
|
||||
| <<PathsDocumentExtension>> | io.github.swagger2markup.spi.PathsDocumentExtension | Can be used to extend the content of the Paths document
|
||||
| <<SecurityDocumentExtension>> | io.github.swagger2markup.spi.SecurityDocumentExtension | Can be used to extend the content of the Security document
|
||||
| <<DefinitionsDocumentExtension>> | io.github.swagger2markup.spi.DefinitionsDocumentExtension | Can be used to extend the content of the Definitions document
|
||||
| <<SwaggerModelExtension>> | io.github.swagger2markup.spi.SwaggerModelExtension | Can be used to modify the Swagger model before it is converted
|
||||
|====
|
||||
|
||||
=== Creation of an extension
|
||||
|
||||
To create a custom extension, you have to create a class (e.g. `io.myname.MyExtension`) which extends an extension, e.g. `io.github.swagger2markup.spi.DefinitionsDocumentExtension`. Every extension point provides two methods which must be implemented:
|
||||
|
||||
* `init`: This method is invoked once and can be used to initialize the extension.
|
||||
* `apply`: This method is invoked multiple times depending on the type of the extension. The `Position` can be retrieved from the `Context` and can be used to extend the document at specific extension points.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::../../test/java/io/github/swagger2markup/builder/MyExtension.java[tags=MyExtension]
|
||||
----
|
||||
1. You can retrieve extension properties from the config to configure the extension.
|
||||
2. You can retrieve a `MarkupDocBuilder` from the `Context`.
|
||||
3. You can retrieve the current `Position` from the Context.
|
||||
4. You can use a `MarkupDocBuilder` to add Markup using a fluent API or import Markup from files.
|
||||
|
||||
=== Registration of an extension
|
||||
|
||||
Swagger2Markup extensions must be registered in the `Swagger2MarkupExtensionRegistry`. The default `Swagger2MarkupExtensionRegistry` of Swagger2Markup uses the `java.util.ServiceLoader` to load and register Swagger2Markup extensions automatically.
|
||||
|
||||
==== Automatic registration
|
||||
|
||||
To register your extension automatically, the following steps are required:
|
||||
|
||||
* Create a file called `META-INF/services/io.github.swagger2markup.spi.DefinitionsDocumentExtension` which contains your extensions’s full qualified name, e.g. `io.myname.MyExtension`.
|
||||
|
||||
* When a `.jar` file containing your extension is added to the classpath of Swagger2Markup, the extensions will be automatically registered.
|
||||
|
||||
==== Manual registration
|
||||
|
||||
To register your extension manually, you have to use the `Swagger2MarkupExtensionRegistryBuilder`.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupExtensionRegistryBuilder]
|
||||
----
|
||||
1. Create a ``Swagger2MarkupExtensionRegistryBuilder`` using the default constructor
|
||||
2. Register your custom extension
|
||||
3. Build an instance of `Swagger2MarkupExtensionRegistry`
|
||||
4. Use the custom Swagger2MarkupExtensionRegistry
|
||||
|
||||
=== Extensions points
|
||||
|
||||
==== OverviewDocumentExtension
|
||||
|
||||
The OverviewDocumentExtension allows to extend the overview document at positions :
|
||||
|
||||
* DOCUMENT_BEFORE: Before the document title (title level offset = 0)
|
||||
* DOCUMENT_BEGIN: After the document title (title level offset = 1)
|
||||
* DOCUMENT_END: At the end of the document (title level offset = 1)
|
||||
* DOCUMENT_AFTER: At the very end of the document (title level offset = 0)
|
||||
|
||||
NOTE: Extension content titles must always start from level *1*. The title level will be adapted depending on position.
|
||||
|
||||
==== PathsDocumentExtension
|
||||
|
||||
The PathsDocumentExtension allows to extend the paths document at positions :
|
||||
|
||||
* DOCUMENT_BEFORE: Before the document title (title level offset = 0)
|
||||
* DOCUMENT_BEGIN: After the document title (title level offset = 1)
|
||||
* OPERATION_BEFORE: Before each operation title (title level offset = 1)
|
||||
* OPERATION_BEGIN: After each operation title (title level offset = 2)
|
||||
* OPERATION_END: At the end of each operation (title level offset = 2)
|
||||
* OPERATION_AFTER: At the very end of each operation (title level offset = 1)
|
||||
* DOCUMENT_END: At the end of the document (title level offset = 1)
|
||||
* DOCUMENT_AFTER: At the very end of the document (title level offset = 0)
|
||||
|
||||
Moreover, the PathsDocumentExtension allows to extend operation sections at positions :
|
||||
|
||||
* OPERATION_DESCRIPTION_BEFORE: Before each description section title (title level offset = 2)
|
||||
* OPERATION_DESCRIPTION_BEGIN: After each description section title (title level offset = 3)
|
||||
* OPERATION_DESCRIPTION_END: At the end of each description section (title level offset = 3)
|
||||
* OPERATION_DESCRIPTION_AFTER: At the very end of each description section (title level offset = 2)
|
||||
|
||||
* OPERATION_PARAMETERS_BEFORE: Before each parameters section title (title level offset = 2)
|
||||
* OPERATION_PARAMETERS_BEGIN: After each parameters section title (title level offset = 3)
|
||||
* OPERATION_PARAMETERS_END: At the end of each parameters section (title level offset = 3)
|
||||
* OPERATION_PARAMETERS_AFTER: At the very end of each parameters section (title level offset = 2)
|
||||
|
||||
* OPERATION_RESPONSES_BEFORE: Before each responses section title (title level offset = 2)
|
||||
* OPERATION_RESPONSES_BEGIN: After each responses section title (title level offset = 3)
|
||||
* OPERATION_RESPONSES_END: At the end of each responses section (title level offset = 3)
|
||||
* OPERATION_RESPONSES_AFTER: At the very end of each responses section (title level offset = 2)
|
||||
|
||||
* OPERATION_SECURITY_BEFORE: Before each security section title (title level offset = 2)
|
||||
* OPERATION_SECURITY_BEGIN: After each security section title (title level offset = 3)
|
||||
* OPERATION_SECURITY_END: At the end of each security section (title level offset = 3)
|
||||
* OPERATION_SECURITY_AFTER: At the very end of each security section (title level offset = 2)
|
||||
|
||||
NOTE: Extension content titles must always start from level *1*. The title level will be adapted depending on position.
|
||||
|
||||
==== SecurityDocumentExtension
|
||||
|
||||
The SecurityDocumentExtension allows to extend the security document at positions :
|
||||
|
||||
* DOCUMENT_BEFORE: Before the document title (title level offset = 0)
|
||||
* DOCUMENT_BEGIN: After the document title (title level offset = 1)
|
||||
* SECURITY_SCHEME_BEFORE: Before each security scheme title (title level offset = 1)
|
||||
* SECURITY_SCHEME_BEGIN: After each security scheme title (title level offset = 2)
|
||||
* SECURITY_SCHEME_END: At the end of each security scheme (title level offset = 2)
|
||||
* SECURITY_SCHEME_AFTER: At the very end of each security scheme (title level offset = 1)
|
||||
* DOCUMENT_END: At the end of the document (title level offset = 1)
|
||||
* DOCUMENT_AFTER: At the very end of the document (title level offset = 0)
|
||||
|
||||
NOTE: Extension content titles must always start from level *1*. The title level will be adapted depending on position.
|
||||
|
||||
==== DefinitionsDocumentExtension
|
||||
|
||||
The DefinitionsDocumentExtension allows to extend the definitions document at positions :
|
||||
|
||||
* DOCUMENT_BEFORE: Before the document title (title level offset = 0)
|
||||
* DOCUMENT_BEGIN: After the document title (title level offset = 1)
|
||||
* DEFINITION_BEFORE: Before each definition title (title level offset = 1)
|
||||
* DEFINITION_BEGIN: After each definition title (title level offset = 2)
|
||||
* DEFINITION_END: At the end of each definition (title level offset = 2)
|
||||
* DEFINITION_AFTER: At the very end of each definition (title level offset = 1)
|
||||
* DOCUMENT_END: At the end of the document (title level offset = 1)
|
||||
* DOCUMENT_AFTER: At the very end of the document (title level offset = 0)
|
||||
|
||||
NOTE: Extension content titles must always start from level *1*. The title level will be adapted depending on position.
|
||||
|
||||
==== SwaggerModelExtension
|
||||
|
||||
The SwaggerModelExtension allows to modify the Swagger model before it is processed by Swagger2Markup. For example, you could use this extension to delete Paths from the Swagger model which should not be rendered.
|
||||
|
||||
Example:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::../../test/java/io/github/swagger2markup/builder/MySwaggerModelExtension.java[tags=MySwaggerModelExtension]
|
||||
----
|
||||
1. You can change any Swagger model property
|
||||
2. You could even remove elements from the Swagger model
|
||||
|
||||
[[extension_commons_content_markup]]
|
||||
=== Content markup language
|
||||
|
||||
Most content extensions supports to provide content in any markup language which will be *converted, if needed, to configured Swagger2Markup converter markup language* at import.
|
||||
|
||||
The content files markup language can be any https://github.com/Swagger2Markup/markup-document-builder[markup-document-builder] supported language :
|
||||
|
||||
* ASCIIDOC : AsciiDoc. Mandatory content file extension : `adoc`
|
||||
|
||||
* MARKDOWN : Github Flavored Markdown. Mandatory content file extension : `md`
|
||||
|
||||
* CONFLUENCE_MARKUP : Confluence Wiki markup. Mandatory content file extension : `txt`
|
||||
|
||||
[IMPORTANT]
|
||||
====
|
||||
Currently supported conversions are :
|
||||
|
||||
* Markdown -> AsciiDoc
|
||||
====
|
||||
|
||||
=== Provided Extensions
|
||||
|
||||
Swagger2Markup provides some extensions which can be used out-of-the-box. You just have to add the extension to your classpath.
|
||||
|
||||
[options="header"]
|
||||
.Swagger2Markup extensions
|
||||
|====
|
||||
| Name | Description
|
||||
| <<extension_import_files,Dynamic file import extension>> | Allows to dynamically import Markup from files.
|
||||
| <<extension_spring_restdocs,Spring RestDocs extension>> | Allows to import Curl, HTTP request and response snippets from https://github.com/spring-projects/spring-restdocs[Spring Rest Docs].
|
||||
| <<extension_import_schemas,Schema file import extension>> | Allows to import JSON or XML Schema files.
|
||||
|====
|
||||
|
||||
include::extensions/import_files.adoc[leveloffset=+2]
|
||||
|
||||
include::extensions/spring_restdocs.adoc[leveloffset=+2]
|
||||
|
||||
include::extensions/import_schemas.adoc[leveloffset=+2]
|
||||
117
src/docs/asciidoc/extensions/import_files.adoc
Normal file
@@ -0,0 +1,117 @@
|
||||
[[extension_import_files]]
|
||||
== Dynamic file import extension
|
||||
|
||||
=== Usage guide
|
||||
|
||||
[source,groovy, subs="attributes"]
|
||||
----
|
||||
repositories {
|
||||
jCenter()
|
||||
}
|
||||
|
||||
compile "io.github.swagger2markup:swagger2markup-import-files-ext:{project-version}"
|
||||
----
|
||||
|
||||
The extension searches for markup files in configurable paths to append the markup to the documents at supported positions.
|
||||
|
||||
The markup files must conform to a naming convention to be found. The files must start with the position where the document should be extended and end with the markup file extension (e.g `adoc` or `md`).
|
||||
|
||||
See documentation of <<Extensions points>>.
|
||||
|
||||
Here the list of all document naming conventions for each position. You have to replace `*` with an arbitrary, meaningful, identifier.
|
||||
|
||||
NOTE: You can provide multiple contents for the same position, just specify different identifiers in place of `*` in the file name. The concurrent contents for a given position will all be added to the document in a determinist order, sorting content file by natural order.
|
||||
|
||||
All extensions, relatively to each extension contentPath :
|
||||
|
||||
* DOCUMENT_BEFORE : `document-before-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* DOCUMENT_BEGIN : `document-begin-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* DOCUMENT_END : `document-end-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* DOCUMENT_AFTER : `document-after-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
|
||||
Paths extensions, relatively to each extension contentPath :
|
||||
|
||||
* OPERATION_BEFORE : `<<swagger_operationId,<operationId> >>/operation-before-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_BEGIN : `<<swagger_operationId,<operationId> >>/operation-begin-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_END : `<<swagger_operationId,<operationId> >>/operation-end-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_AFTER : `<<swagger_operationId,<operationId> >>/operation-after-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
|
||||
* OPERATION_DESCRIPTION_BEFORE: `<<swagger_operationId,<operationId> >>/operation-description-before-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_DESCRIPTION_BEGIN: `<<swagger_operationId,<operationId> >>/operation-description-begin-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_DESCRIPTION_END: `<<swagger_operationId,<operationId> >>/operation-description-end-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_DESCRIPTION_AFTER: `<<swagger_operationId,<operationId> >>/operation-description-after-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
|
||||
* OPERATION_PARAMETERS_BEFORE: `<<swagger_operationId,<operationId> >>/operation-parameters-before-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_PARAMETERS_BEGIN: `<<swagger_operationId,<operationId> >>/operation-parameters-begin-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_PARAMETERS_END: `<<swagger_operationId,<operationId> >>/operation-parameters-end-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_PARAMETERS_AFTER: `<<swagger_operationId,<operationId> >>/operation-parameters-after-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
|
||||
* OPERATION_RESPONSES_BEFORE: `<<swagger_operationId,<operationId> >>/operation-responses-before-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_RESPONSES_BEGIN: `<<swagger_operationId,<operationId> >>/operation-responses-begin-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_RESPONSES_END: `<<swagger_operationId,<operationId> >>/operation-responses-end-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_RESPONSES_AFTER: `<<swagger_operationId,<operationId> >>/operation-responses-after-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
|
||||
* OPERATION_SECURITY_BEFORE: `<<swagger_operationId,<operationId> >>/operation-security-before-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_SECURITY_BEGIN: `<<swagger_operationId,<operationId> >>/operation-security-begin*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_SECURITY_END: `<<swagger_operationId,<operationId> >>/operation-security-end-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* OPERATION_SECURITY_AFTER: `<<swagger_operationId,<operationId> >>/operation-security-after-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
|
||||
Definitions extensions, relatively to each extension contentPath :
|
||||
|
||||
* DEFINITION_BEFORE : `<definitionName>/definition-before-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* DEFINITION_BEGIN : `<definitionName>/definition-begin-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* DEFINITION_END : `<definitionName>/definition-end-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* DEFINITION_AFTER : `<definitionName>/definition-after-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
|
||||
Security extensions, relatively to each extension contentPath :
|
||||
|
||||
* SECURITY_SCHEME_BEFORE : `<securitySchemeName>/security-scheme-before-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* SECURITY_SCHEME_BEGIN : `<securitySchemeName>/security-scheme-begin-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* SECURITY_SCHEME_END : `<securitySchemeName>/security-scheme-end-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
* SECURITY_SCHEME_AFTER : `<securitySchemeName>/security-scheme-after-*.<<extension_import_files_markup,<markup.ext> >>`
|
||||
|
||||
IMPORTANT: `<operationId>` value depends on Swagger specification. If you provided an `operationId` for operations in the Swagger document, the value will be used primarily. *It is highly recommended to set operationId for operations* : see <<swagger_operationId,Swagger operationId>>. In all cases, all placeholder values are case-sensitive.
|
||||
|
||||
NOTE: It's *highly recommended* to configure a different contentPath for each extension (dynamicOverview, dynamicDefinitions, etc...) because content files for DOCUMENT_* positions have the same naming convention.
|
||||
|
||||
.Example of provided content files for petstore Swagger sample
|
||||
====
|
||||
....
|
||||
overview/document-before-intro.adoc <1>
|
||||
paths/document-before-intro.adoc <2>
|
||||
paths/updatePet/operation-begin-description.adoc
|
||||
paths/updatePet/operation-end-example1.adoc
|
||||
paths/updatePet/operation-end-example2.adoc <3>
|
||||
definitions/Pet/definition-begin-description.adoc
|
||||
....
|
||||
1. "overview", "paths" and "definitions" are different configured contentPath for different extensions.
|
||||
2. the document name is the same but will be used only in Paths document because contentPath is different (cf 1.).
|
||||
3. both example1 and example2 content files will be added to "updatePet" operation. They'll be applied consecutively, with their names sorted by natural order.
|
||||
|
||||
====
|
||||
|
||||
[[extension_import_files_markup]]
|
||||
=== Content markup language
|
||||
|
||||
See <<extension_commons_content_markup,Extensions content markup language>>
|
||||
|
||||
By default, the markup language is set to *ASCIIDOC*. Set extension <<extension_import_files_configuration,Configuration>> to change content markup language.
|
||||
|
||||
[[extension_import_files_configuration]]
|
||||
=== Configuration
|
||||
|
||||
The extension adds the following properties to Swagger2Markup which must be configured:
|
||||
|
||||
[options="header"]
|
||||
.Extension properties
|
||||
|====
|
||||
| Name | Description | Default | Example
|
||||
| `swagger2markup.extensions.dynamicOverview.contentPath` | The path to the files which should be imported | - | `src/test/resources/docs/asciidoc/overview`
|
||||
| `swagger2markup.extensions.dynamicOverview.markupLanguage` | The markup language of the content files | `ASCIIDOC` | `MARKDOWN`
|
||||
| `swagger2markup.extensions.dynamicDefinitions.contentPath` | The path to the files which should be imported | - | `src/test/resources/docs/asciidoc/definitions`
|
||||
| `swagger2markup.extensions.dynamicDefinitions.markupLanguage` | The markup language of the content files | `ASCIIDOC` | `MARKDOWN`
|
||||
| `swagger2markup.extensions.dynamicPaths.contentPath` | The path to the files which should be imported | - | `src/test/resources/docs/asciidoc/paths`
|
||||
| `swagger2markup.extensions.dynamicPaths.markupLanguage` | The markup language of the content files | `ASCIIDOC` | `MARKDOWN`
|
||||
| `swagger2markup.extensions.dynamicSecurity.contentPath` | TThe path to the files which should be imported | - | `src/test/resources/docs/asciidoc/security`
|
||||
| `swagger2markup.extensions.dynamicSecurity.markupLanguage` | The markup language of the content files | `ASCIIDOC` | `MARKDOWN`
|
||||
|====
|
||||
29
src/docs/asciidoc/extensions/import_schemas.adoc
Normal file
@@ -0,0 +1,29 @@
|
||||
[[extension_import_schemas]]
|
||||
== Schema file import extension
|
||||
|
||||
=== Usage guide
|
||||
|
||||
[source,groovy, subs="attributes"]
|
||||
----
|
||||
repositories {
|
||||
jCenter()
|
||||
}
|
||||
|
||||
compile "io.github.swagger2markup:swagger2markup-import-schemas-ext:{project-version}"
|
||||
----
|
||||
|
||||
The extension searches for Schema files in a configurable path to append the Schema file content at the end of a definition section. The Schema files must conform to a naming convention to be found. The files must be called `schema.xsd` or `schema.json` and must be stored in a folder which matches the name of a definition.
|
||||
|
||||
Example: `/schemas/Pet/schema.json`.
|
||||
|
||||
|
||||
=== Configuration
|
||||
|
||||
The extension adds the following properties to Swagger2Markup which must be configured:
|
||||
|
||||
[options="header"]
|
||||
.Extension properties
|
||||
|====
|
||||
| Name | Description | Example
|
||||
| `swagger2markup.extensions.schema.schemaBaseUri` | The path to the schema files | `src/test/resources/docs/asciidoc/schemas`
|
||||
|====
|
||||
74
src/docs/asciidoc/extensions/spring_restdocs.adoc
Normal file
@@ -0,0 +1,74 @@
|
||||
[[extension_spring_restdocs]]
|
||||
== Spring RestDocs extension
|
||||
|
||||
Swagger2Markup can be used together with https://github.com/spring-projects/spring-restdocs[spring-restdocs]. Swagger2Markup can include the generated CURL request, HTTP request and HTTP response example snippets from spring-restdocs into the generated Markup documents. See spring-restdocs how to configure it.
|
||||
|
||||
=== Usage guide
|
||||
|
||||
[source,groovy,subs="attributes"]
|
||||
----
|
||||
repositories {
|
||||
jCenter()
|
||||
}
|
||||
|
||||
compile "io.github.swagger2markup:swagger2markup-spring-restdocs-ext:{project-version}"
|
||||
----
|
||||
|
||||
The extension searches for https://github.com/spring-projects/spring-restdocs[Spring RestDocs] snippet files in a configurable path to append the snippets at the end of a path operation section. By default the following snippets are searched :
|
||||
|
||||
* `<<swagger_operationId,<operationId> >>/http-request.<<extension_spring_restdocs_markup,<markup.ext> >>`
|
||||
* `<<swagger_operationId,<operationId> >>/http-response.<<extension_spring_restdocs_markup,<markup.ext> >>`
|
||||
* `<<swagger_operationId,<operationId> >>/curl-request.<<extension_spring_restdocs_markup,<markup.ext> >>`
|
||||
|
||||
IMPORTANT: `<operationId>` value depends on Swagger specification. If you provided an `operationId` for operations in the Swagger document, the value will be used primarily. *It is highly recommended to set operationId for operations* : see <<swagger_operationId,Swagger operationId>>. In all cases, `<operationId>` is case-sensitive.
|
||||
|
||||
Swagger Example:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
paths:
|
||||
/pets:
|
||||
post:
|
||||
summary: Add a new pet to the store
|
||||
operationId: addPet
|
||||
...
|
||||
----
|
||||
|
||||
The following Unit Test uses Spring RestDocs to tests the `/pets` endoint and writes the example files into the ``build/snippets`` folder. Have a look at the <<Spring Boot and Springfox>> chapter for a full example using https://github.com/spring-projects/spring-boot[Spring Boot], https://github.com/springfox/springfox[Springfox] and Spring RestDocs.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@Rule
|
||||
public final RestDocumentation restDocumentation = new RestDocumentation("build/snippets");
|
||||
|
||||
@Test
|
||||
public void addAPetToTheStore() throws Exception {
|
||||
this.mockMvc.perform(post("/pets/").content(createPet())
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(document("addPet", preprocessResponse(prettyPrint())))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
----
|
||||
|
||||
Example: `build/snippets/addPet/http-request.adoc`.
|
||||
|
||||
[[extension_spring_restdocs_markup]]
|
||||
=== Content markup language
|
||||
|
||||
See <<extension_commons_content_markup,Extensions content markup language>>
|
||||
|
||||
By default, the markup language is set to *ASCIIDOC*. Set extension <<extension_spring_restdocs_configuration,Configuration>> to change content markup language.
|
||||
|
||||
[[extension_spring_restdocs_configuration]]
|
||||
=== Configuration
|
||||
|
||||
The extension adds the following properties to Swagger2Markup which must be configured:
|
||||
|
||||
[options="header"]
|
||||
.Extension properties
|
||||
|====
|
||||
| Name | Description | Default | Example
|
||||
| `swagger2markup.extensions.springRestDocs.snippetBaseUri` | The path to the Spring RestDocs snippets | - | `src/test/resources/docs/asciidoc/paths`
|
||||
| `swagger2markup.extensions.springRestDocs.markupLanguage` | The markup language of the content files | `ASCIIDOC` | `MARKDOWN`
|
||||
| `swagger2markup.extensions.springRestDocs.defaultSnippets` | Boolean value. Set to false to disable default snippet files | `true` | `false`
|
||||
|====
|
||||
71
src/docs/asciidoc/getting_started.adoc
Normal file
@@ -0,0 +1,71 @@
|
||||
== Getting started
|
||||
|
||||
Swagger2Markup is a standard .jar file. To start using it, you need to add the library to your project’s classpath. Swagger2Markup is published in JCenter and Maven Central. The artifacts can be viewed at the following locations:
|
||||
|
||||
* Releases: https://jcenter.bintray.com/io/github/swagger2markup/swagger2markup/
|
||||
|
||||
* Snapshots: https://oss.jfrog.org/simple/oss-snapshot-local/io/github/swagger2markup/swagger2markup/
|
||||
|
||||
If you use Gradle or Maven, you can include Swagger2Markup as follows.
|
||||
|
||||
WARNING: The *groupId* has been changed from *io.github.robwin* to *io.github.swagger2markup*
|
||||
|
||||
=== Gradle
|
||||
|
||||
==== Release
|
||||
[source,groovy, subs="attributes"]
|
||||
----
|
||||
repositories {
|
||||
jCenter()
|
||||
}
|
||||
|
||||
compile "io.github.swagger2markup:swagger2markup:{release-version}"
|
||||
----
|
||||
|
||||
==== Snapshot
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
repositories {
|
||||
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
|
||||
}
|
||||
----
|
||||
|
||||
=== Maven
|
||||
==== Release
|
||||
|
||||
[source,xml, subs="specialcharacters,attributes"]
|
||||
----
|
||||
<repositories>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>jcenter-releases</id>
|
||||
<name>jcenter</name>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.swagger2markup</groupId>
|
||||
<artifactId>swagger2markup</artifactId>
|
||||
<version>{release-version}</version>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
==== Snapshot
|
||||
|
||||
[source,java]
|
||||
----
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jcenter-snapshots</id>
|
||||
<name>jcenter</name>
|
||||
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
----
|
||||
|
||||
|
||||
|
||||
62
src/docs/asciidoc/gradle_plugin.adoc
Normal file
@@ -0,0 +1,62 @@
|
||||
== Gradle Plugin
|
||||
|
||||
Swagger2Markup provides a Gradle plugin. The Gradle plugin is published in JCenter and Maven Central.
|
||||
|
||||
NOTE: The Gradle Plugin requires at least JDK 8.
|
||||
|
||||
=== Usage guide
|
||||
|
||||
Add the following snippet to your Gradle build file:
|
||||
|
||||
[source,java]
|
||||
[source,groovy, subs="attributes"]
|
||||
----
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'io.github.swagger2markup:swagger2markup-gradle-plugin:{release-version}'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'io.github.swagger2markup'
|
||||
----
|
||||
|
||||
The plugin adds a new task named ``convertSwagger2markup``. You can run the task as follows:
|
||||
|
||||
`gradlew convertSwagger2markup`
|
||||
|
||||
=== Configuration
|
||||
|
||||
You can customize the task by configuring a Map of <<Swagger2Markup properties>>.
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
convertSwagger2markup {
|
||||
swaggerInput file("src/docs/swagger/swagger_petstore.yaml").getAbsolutePath()
|
||||
outputDir file("${buildDir}/asciidoc")
|
||||
config = ['swagger2markup.markupLanguage' : 'ASCIIDOC',
|
||||
'swagger2markup.pathsGroupedBy' : 'TAGS']
|
||||
}
|
||||
|
||||
----
|
||||
|
||||
[options="header"]
|
||||
.Gradle Plugin properties
|
||||
|====
|
||||
| Name | Description | Type | Example
|
||||
| swaggerInput | The URL or file path to the Swagger specification | String | `file("src/docs/swagger/swagger_petstore.yaml").getAbsolutePath()` or `http://petstore.swagger.io/v2/swagger.json`
|
||||
| outputDir | The directory where the output should be stored. | File | `file("${buildDir}/asciidoc")`
|
||||
| outputFile | The file path (without extension) where the output should be stored. | File | `file("${buildDir}/asciidoc/swagger")`
|
||||
| config | The Swagger2Markup properties to configure the converter | Map | |
|
||||
|====
|
||||
|
||||
=== Example
|
||||
|
||||
You can copy the template project from GitHub to get started.
|
||||
|
||||
https://github.com/Swagger2Markup/swagger2markup-gradle-project-template
|
||||
|
||||
BIN
src/docs/asciidoc/images/Swagger2Markup.PNG
Normal file
|
After Width: | Height: | Size: 130 KiB |
BIN
src/docs/asciidoc/images/Swagger2Markup_definitions.PNG
Normal file
|
After Width: | Height: | Size: 116 KiB |
BIN
src/docs/asciidoc/images/confluence_petstore_screenshot_1024.png
Normal file
|
After Width: | Height: | Size: 133 KiB |
BIN
src/docs/asciidoc/images/overview_extension_points.png
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
src/docs/asciidoc/images/titledSwagger.png
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
src/docs/asciidoc/images/untitledSwagger.png
Normal file
|
After Width: | Height: | Size: 35 KiB |
@@ -1,9 +1,36 @@
|
||||
:doctype: book
|
||||
= Swagger2Markup Documentation
|
||||
Robert Winkler
|
||||
:toc: left
|
||||
:toclevels: 2
|
||||
:toclevels: 3
|
||||
:source-highlighter: coderay
|
||||
:numbered:
|
||||
:sectlinks:
|
||||
:sectanchors:
|
||||
:hardbreaks:
|
||||
:revnumber: {release-version}
|
||||
:revdate: {localdate}
|
||||
:icons: font
|
||||
:pagenums:
|
||||
|
||||
include::introduction.adoc[]
|
||||
|
||||
include::getting_started.adoc[]
|
||||
|
||||
include::usage_guide.adoc[]
|
||||
|
||||
include::advanced_usage.adoc[]
|
||||
|
||||
include::extension_spi.adoc[]
|
||||
|
||||
include::gradle_plugin.adoc[]
|
||||
|
||||
include::maven_plugin.adoc[]
|
||||
|
||||
include::command_line_interface.adoc[]
|
||||
|
||||
include::docker.adoc[]
|
||||
|
||||
include::demo.adoc[]
|
||||
|
||||
include::contributing.adoc[]
|
||||
|
||||
include::license.adoc[]
|
||||
|
||||
include::paths.adoc[]
|
||||
include::definitions.adoc[]
|
||||
23
src/docs/asciidoc/introduction.adoc
Normal file
@@ -0,0 +1,23 @@
|
||||
== Introduction
|
||||
|
||||
The primary goal of this project is to **simplify the generation of an up-to-date RESTful API documentation by combining documentation that's been hand-written with auto-generated API documentation** produced by https://github.com/swagger-api[Swagger]. The result is intended to be an **up-to-date, easy-to-read, on- and offline user guide**. The output of Swagger2Markup can be used as an alternative to https://github.com/swagger-api/swagger-ui[swagger-ui] and can be served as static content.
|
||||
|
||||
NOTE: The Swagger Specification has been donated to to the https://openapis.org/[Open API Initiative (OAI)] and has been renamed to https://github.com/OAI/OpenAPI-Specification[OpenAPI Specification].
|
||||
|
||||
Swagger2Markup converts a Swagger JSON or YAML specification into either **AsciiDoc**, **GitHub Flavored Markdown** or *Atlassian Confluence Wiki* documents which can be combined with hand-written Markup documentation. The Swagger source file can be located locally or remotely via HTTP. Internally Swagger2Markup uses the __official__ https://github.com/swagger-api/swagger-parser[swagger-parser] and https://github.com/Swagger2Markup/markup-document-builder[markup-document-builder].
|
||||
|
||||
You can use Swagger2Markup to convert your contract-first Swagger YAML file into Markup. As an alternative, you can choose the code-first approach and use Swagger2Markup together with https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X[Swagger JAX-RS], https://github.com/springfox/springfox[Springfox] or https://github.com/spring-projects/spring-restdocs[spring-restdocs]. If you are are Gradle or Maven user, you can also use the https://github.com/Swagger2Markup/swagger2markup-gradle-plugin[Swagger2Markup Gradle Plugin] or https://github.com/redowl/swagger2markup-maven-plugin[Swagger2markup Maven Plugin].
|
||||
|
||||
NOTE: The project requires at least JDK 8.
|
||||
|
||||
=== AsciiDoc
|
||||
|
||||
http://asciidoctor.org/docs/asciidoc-writers-guide/[AsciiDoc] is preferable to Markdown as it has more features. AsciiDoc is a text document format for writing documentation, articles, books, ebooks, slideshows, web pages and blogs. AsciiDoc files can be converted to **HTML**, **PDF** and **EPUB**. AsciiDoc is much better suited for describing public APIs than **JavaDoc** or **Annotations**.
|
||||
|
||||
You can generate your HTML5, PDF and EPUB documentation via https://github.com/asciidoctor/asciidoctorj[asciidoctorj] or even better via the https://github.com/asciidoctor/asciidoctor-gradle-plugin[asciidoctor-gradle-plugin] or https://github.com/asciidoctor/asciidoctor-maven-plugin[asciidoctor-maven-plugin].
|
||||
|
||||
.HTML example using AsciiDoctor - path section
|
||||
image::images/Swagger2Markup.PNG[]
|
||||
|
||||
.HTML example using AsciiDoctor - definition section
|
||||
image::images/Swagger2Markup_definitions.PNG[]
|
||||
9
src/docs/asciidoc/license.adoc
Normal file
@@ -0,0 +1,9 @@
|
||||
== License
|
||||
|
||||
Copyright 2016 Robert Winkler
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
86
src/docs/asciidoc/maven_plugin.adoc
Normal file
@@ -0,0 +1,86 @@
|
||||
== Maven Plugin
|
||||
|
||||
Swagger2Markup provides a Maven plugin. The Maven plugin is published in JCenter and Maven Central.
|
||||
|
||||
NOTE: The Maven Plugin requires at least JDK 8.
|
||||
|
||||
=== Usage guide
|
||||
|
||||
Add the following snippet to your Maven POM file:
|
||||
|
||||
[source,xml, subs="specialcharacters,attributes"]
|
||||
----
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>jcenter-snapshots</id>
|
||||
<name>jcenter</name>
|
||||
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>jcenter-releases</id>
|
||||
<name>jcenter</name>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.github.swagger2markup</groupId>
|
||||
<artifactId>swagger2markup-maven-plugin</artifactId>
|
||||
<version>{release-version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
----
|
||||
|
||||
The plugin adds a new task goal `swagger2markup:convertSwagger2markup`. You can run the goal as follows:
|
||||
|
||||
`mvn swagger2markup:convertSwagger2markup`
|
||||
|
||||
=== Configuration
|
||||
|
||||
You can customize the task by configuring a Map of <<Swagger2Markup properties>>.
|
||||
|
||||
[source,xml, subs="specialcharacters,attributes"]
|
||||
----
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.github.swagger2markup</groupId>
|
||||
<artifactId>swagger2markup-maven-plugin</artifactId>
|
||||
<version>{release-version}</version>
|
||||
<configuration>
|
||||
<swaggerInput>${project.basedir}/src/docs/swagger/swagger_petstore.yaml</swaggerInput>
|
||||
<outputDir>${project.build.directory}/asciidoc</outputDir>
|
||||
<config>
|
||||
<swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
|
||||
</config>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
----
|
||||
|
||||
|
||||
[options="header"]
|
||||
.Maven Plugin properties
|
||||
|====
|
||||
| Name | Description | Type | Example
|
||||
| swaggerInput | The URL or file path to the Swagger specification | String | `${project.basedir}/src/docs/swagger/swagger_petstore.yaml` or `http://petstore.swagger.io/v2/swagger.json`
|
||||
| outputDir | The directory where the output should be stored. | File | `${project.build.directory}/asciidoc`
|
||||
| outputFile | The file path (without extension) where the output should be stored. | File | `${project.build.directory}/asciidoc/swagger`
|
||||
| config | The Swagger2Markup properties to configure the converter | Map | |
|
||||
|====
|
||||
|
||||
=== Example
|
||||
|
||||
You can copy the template project from GitHub to get started.
|
||||
|
||||
https://github.com/Swagger2Markup/swagger2markup-maven-project-template
|
||||
|
||||
|
||||
|
||||
@@ -1,582 +0,0 @@
|
||||
= Swagger Petstore
|
||||
|
||||
This is a sample server Petstore server.
|
||||
|
||||
[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.
|
||||
|
||||
For this sample, you can use the api key `special-key` to test the authorization filters
|
||||
|
||||
Version: 1.0.0
|
||||
Contact: apiteam@wordnik.com
|
||||
License: Apache 2.0
|
||||
License URL: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
Terms of service: http://helloreverb.com/terms/
|
||||
|
||||
Host: petstore.swagger.wordnik.com
|
||||
BasePath: /v2
|
||||
Schemes: HTTP
|
||||
|
||||
== Paths
|
||||
=== Update an existing pet
|
||||
----
|
||||
PUT /pets
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|<<Pet>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Pet not found|No Content
|
||||
|405|Validation exception|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Add a new pet to the store
|
||||
----
|
||||
POST /pets
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|<<Pet>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|405|Invalid input|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Finds Pets by status
|
||||
----
|
||||
GET /pets/findByStatus
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Multiple status values can be provided with comma seperated strings
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|status|Status values that need to be considered for filter|false|multi string array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>> array
|
||||
|400|Invalid status value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Finds Pets by tags
|
||||
----
|
||||
GET /pets/findByTags
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|tags|Tags to filter by|false|multi string array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>> array
|
||||
|400|Invalid tag value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Find pet by ID
|
||||
----
|
||||
GET /pets/{petId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|petId|ID of pet that needs to be fetched|true|integer (int64)
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>>
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Pet not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Deletes a pet
|
||||
----
|
||||
DELETE /pets/{petId}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|HeaderParameter|api_key||true|string
|
||||
|PathParameter|petId|Pet id to delete|true|integer (int64)
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid pet value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Updates a pet in the store with form data
|
||||
----
|
||||
POST /pets/{petId}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|petId|ID of pet that needs to be updated|true|string
|
||||
|FormDataParameter|name|Updated name of the pet|true|string
|
||||
|FormDataParameter|status|Updated status of the pet|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|405|Invalid input|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/x-www-form-urlencoded
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Place an order for a pet
|
||||
----
|
||||
POST /stores/order
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|order placed for purchasing the pet|false|<<Order>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Order>>
|
||||
|400|Invalid Order|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Find purchase order by ID
|
||||
----
|
||||
GET /stores/order/{orderId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|orderId|ID of pet that needs to be fetched|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Order>>
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Order not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Delete purchase order by ID
|
||||
----
|
||||
DELETE /stores/order/{orderId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|orderId|ID of the order that needs to be deleted|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Order not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Create user
|
||||
----
|
||||
POST /users
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Created user object|false|<<User>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Creates list of users with given input array
|
||||
----
|
||||
POST /users/createWithArray
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|List of user object|false|<<User>> array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Creates list of users with given input array
|
||||
----
|
||||
POST /users/createWithList
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|List of user object|false|<<User>> array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Logs user into the system
|
||||
----
|
||||
GET /users/login
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|username|The user name for login|false|string
|
||||
|QueryParameter|password|The password for login in clear text|false|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|string
|
||||
|400|Invalid username/password supplied|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Logs out current logged in user session
|
||||
----
|
||||
GET /users/logout
|
||||
----
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Get user by user name
|
||||
----
|
||||
GET /users/{username}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|The name that needs to be fetched. Use user1 for testing.|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<User>>
|
||||
|400|Invalid username supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Updated user
|
||||
----
|
||||
PUT /users/{username}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|name that need to be deleted|true|string
|
||||
|BodyParameter|body|Updated user object|false|<<User>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid user supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Delete user
|
||||
----
|
||||
DELETE /users/{username}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|The name that needs to be deleted|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid username supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
198
src/docs/asciidoc/usage_guide.adoc
Normal file
@@ -0,0 +1,198 @@
|
||||
== Swagger2Markup API
|
||||
|
||||
=== Usage guide
|
||||
|
||||
Swagger2Markup converts a Swagger JSON or YAML specification into either **AsciiDoc**, **GitHub Flavored Markdown** or **Atlassian Confluence Wiki** documents. By default the Swagger2Markup converts a Swagger specification into four AsciiDoc files: __overview.adoc__, __paths.adoc__ , __security.adoc__ and __definitions.adoc__. But you can also convert a Swagger specification into only one file or a String.
|
||||
|
||||
|
||||
==== Conversion of a local Swagger file
|
||||
|
||||
The entry point of the Swagger2Markup API is the ``Swagger2MarkupConverter`` class. This class provides static factory methods to create a `Swagger2MarkupConverter.Builder`.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=localSwaggerSpec]
|
||||
----
|
||||
|
||||
1. Create a ``Swagger2MarkupConverter.Builder`` by specifying the Path to the local file
|
||||
2. Build an instance of the ``Swagger2MarkupConverter``
|
||||
3. Invoke ``toFolder`` by specifying the output directory
|
||||
|
||||
|
||||
==== Conversion of a remote Swagger file
|
||||
|
||||
You can convert a remote Swagger specification which must be accessible via HTTP.
|
||||
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=remoteSwaggerSpec]
|
||||
----
|
||||
|
||||
1. Create a ``Swagger2MarkupConverter.Builder`` by specifying the URL to the remote file
|
||||
2. Build an instance of the ``Swagger2MarkupConverter``
|
||||
3. Invoke ``toFolder`` by specifying the output directory
|
||||
|
||||
|
||||
==== Conversion into a file
|
||||
|
||||
You can convert the Swagger specification into a file.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=convertIntoOneFile]
|
||||
----
|
||||
|
||||
==== Conversion to a String
|
||||
|
||||
You can convert the Swagger specification to a String.
|
||||
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=convertIntoString]
|
||||
----
|
||||
|
||||
=== Configuration
|
||||
|
||||
Swagger2Markup provides several options to configure the Swagger2MarkupConverter:
|
||||
|
||||
* Using system properties
|
||||
* Using a fluent API
|
||||
* Using a properties file
|
||||
* Using a Java Map
|
||||
* Using Apache Commons Configuration
|
||||
|
||||
==== Configuration using the Builder
|
||||
|
||||
You can configure the Swagger2MarkupConverter by using the `Swagger2MarkupConfigBuilder` to build a custom `Swagger2MarkupConfig`. The `Swagger2MarkupConfigBuilder` can be used to define Swagger2Markup properties with a fluent API.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigBuilder]
|
||||
----
|
||||
|
||||
1. Create a `Swagger2MarkupConfigBuilder` using the default constructor.
|
||||
2. Configure the output `MarkupLanguage`
|
||||
3. Configure the output `Language`
|
||||
4. Configure additional Swagger2Markup properties
|
||||
5. Build an instance of the `Swagger2MarkupConfig`
|
||||
6. Use the custom Swagger2MarkupConfig
|
||||
|
||||
You can also create a `Swagger2MarkupConfig` from a Properties file, a `Map` or a Apache Commons Configuration.
|
||||
|
||||
==== Configuration from a Properties file
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigFromProperties]
|
||||
----
|
||||
1. Load a `Properties` file from the classpath or local filesystem.
|
||||
2. Create a `Swagger2MarkupConfigBuilder` using the proper constructor.
|
||||
|
||||
==== Configuration from a Map
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigFromMap]
|
||||
----
|
||||
|
||||
1. Create a `Map` and configure the `Swagger2MarkupProperties`.
|
||||
2. Create a `Swagger2MarkupConfigBuilder` using the proper constructor.
|
||||
|
||||
|
||||
==== Configuration from a Apache Commons Configuration
|
||||
|
||||
Configuration parameters may be loaded from the following sources using Apache Commons Configuration:
|
||||
|
||||
* Properties files
|
||||
* XML documents
|
||||
* Property list files (plist)
|
||||
* JDBC Datasource
|
||||
* Servlet parameters
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=swagger2MarkupConfigFromCommonsConfiguration]
|
||||
----
|
||||
|
||||
1. Create an Apache Commons `Configuration` object using the proper ConfigurationBuilder.
|
||||
2. Create a `Swagger2MarkupConfigBuilder` using the proper constructor.
|
||||
|
||||
==== Swagger2Markup properties
|
||||
|
||||
The properties of Swagger2Markup are defined in the class `io.github.swagger2markup.Swagger2MarkupProperties`.
|
||||
The properties are considered in the following order:
|
||||
|
||||
1. Java System properties
|
||||
2. Custom properties
|
||||
3. Default properties (included in Swagger2Markup)
|
||||
|
||||
The following tables list all available properties of Swagger2Markup:
|
||||
|
||||
[options="header"]
|
||||
.Mostly used properties
|
||||
|===
|
||||
|Name | Description | Possible Values | Default
|
||||
|swagger2markup.markupLanguage| Specifies the markup language which should be used to generate the files. | ASCIIDOC, MARKDOWN, CONFLUENCE_MARKUP | ASCIIDOC
|
||||
|swagger2markup.swaggerMarkupLanguage| Specifies the markup language used in Swagger descriptions. | ASCIIDOC, MARKDOWN, CONFLUENCE_MARKUP | MARKDOWN
|
||||
|swagger2markup.pathsGroupedBy| Specifies how the paths should be grouped | AS_IS, TAGS | AS_IS
|
||||
|swagger2markup.outputLanguage| Specifies the language of the labels | EN, DE, FR, RU | EN
|
||||
|swagger2markup.lineSeparator| Specifies the line separator which should be used | UNIX, WINDOWS, MAC | <System-dependent>
|
||||
|swagger2markup.generatedExamplesEnabled| Specifies if HTTP request and response examples should be generated | true, false | false
|
||||
|swagger2markup.flatBodyEnabled| Optionally isolate the body parameter, if any, from other parameters | true, false | false
|
||||
|swagger2markup.pathSecuritySectionEnabled| Optionally disable the security section for path sections | true, false | true
|
||||
|swagger2markup.anchorPrefix| Optionally prefix all anchors for uniqueness if you want to include generated documents into a global documentation | Any String |
|
||||
|swagger2markup.basePathPrefixEnabled| Prepend the basePath to all paths | true, false | false
|
||||
|===
|
||||
|
||||
[options="header"]
|
||||
.Properties which configure the order of Swagger Objects
|
||||
|===
|
||||
|Name | Description | Possible Values | Default
|
||||
|swagger2markup.tagOrderBy| Specifies the order of global tags | AS_IS, NATURAL, CUSTOM | NATURAL
|
||||
|swagger2markup.operationOrderBy| Specifies the order of path operations | AS_IS, NATURAL, CUSTOM | NATURAL
|
||||
|swagger2markup.definitionOrderBy| Specifies the order of definitions | AS_IS, NATURAL, CUSTOM | NATURAL
|
||||
|swagger2markup.parameterOrderBy| Specifies the order of operation parameters | AS_IS, NATURAL, CUSTOM | NATURAL
|
||||
|swagger2markup.propertyOrderBy | Specifies the order of definition properties | AS_IS, NATURAL, CUSTOM | NATURAL
|
||||
|swagger2markup.responseOrderBy| Specifies the order of responses | AS_IS, NATURAL, CUSTOM | NATURAL
|
||||
|===
|
||||
|
||||
[options="header"]
|
||||
.Properties which configure document file names
|
||||
|===
|
||||
|Name | Description | Possible Values | Default
|
||||
|swagger2markup.overviewDocument| Specifies the file name of the overview document | Any String | "overview"
|
||||
|swagger2markup.pathsDocument| Specifies the file name of the paths document | Any String | "paths"
|
||||
|swagger2markup.definitionsDocument| Specifies the file name of the definitions document | Any String | "definitions"
|
||||
|swagger2markup.securityDocument| Specifies the file name of the security document | Any String | "security"
|
||||
|===
|
||||
|
||||
[options="header"]
|
||||
.Properties which configure the generation of separate files
|
||||
|===
|
||||
|Name | Description | Possible Values | Default
|
||||
|swagger2markup.separatedDefinitionsEnabled| In addition to the Definitions file, also create separate definition files for each model definition | true, false | false
|
||||
|swagger2markup.separatedOperationsEnabled| In addition to the Paths file, also create separate operation files for each operation | true, false | false
|
||||
|swagger2markup.separatedOperationsFolder| Specifies the target folder path for definition files| Any valid folder name | "operations"
|
||||
|swagger2markup.separatedDefinitionsFolder| Specifies the target folder path for operation files | Any valid folder name | "definitions"
|
||||
|===
|
||||
|
||||
[options="header"]
|
||||
.Properties which configure inter-document cross references
|
||||
|===
|
||||
|Name | Description | Possible Values | Default
|
||||
|swagger2markup.interDocumentCrossReferencesEnabled| Enable use of inter-document cross-references when needed | true, false | false
|
||||
|swagger2markup.interDocumentCrossReferencesPrefix| Specifies a prefix for all inter-document cross-references for advanced usage | Any String |
|
||||
|===
|
||||
|
||||
[options="header"]
|
||||
.Properties which configure inline schema rendering
|
||||
|===
|
||||
|Name | Description | Possible Values | Default
|
||||
|swagger2markup.inlineSchemaEnabled| Enable inline object schema support | true, false | true
|
||||
|===
|
||||
|
||||
=== Logging
|
||||
|
||||
Swagger2Markup uses http://www.slf4j.org/[SLF4J] for all internal logging, but leaves the underlying log implementation open. To change the log level, you have the set the log level of the `io.github.swagger2markup` package.
|
||||
@@ -1,637 +0,0 @@
|
||||
= Swagger Petstore
|
||||
|
||||
This is a sample server Petstore server.
|
||||
|
||||
[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.
|
||||
|
||||
For this sample, you can use the api key `special-key` to test the authorization filters
|
||||
|
||||
Version: 1.0.0
|
||||
Contact: apiteam@wordnik.com
|
||||
License: Apache 2.0
|
||||
License URL: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
Terms of service: http://helloreverb.com/terms/
|
||||
|
||||
Host: petstore.swagger.wordnik.com
|
||||
BasePath: /v2
|
||||
Schemes: HTTP
|
||||
|
||||
== Paths
|
||||
=== Update an existing pet
|
||||
----
|
||||
PUT /pets
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|<<Pet>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Pet not found|No Content
|
||||
|405|Validation exception|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Add a new pet to the store
|
||||
----
|
||||
POST /pets
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|<<Pet>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|405|Invalid input|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Finds Pets by status
|
||||
----
|
||||
GET /pets/findByStatus
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Multiple status values can be provided with comma seperated strings
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|status|Status values that need to be considered for filter|false|multi string array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>> array
|
||||
|400|Invalid status value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Finds Pets by tags
|
||||
----
|
||||
GET /pets/findByTags
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|tags|Tags to filter by|false|multi string array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>> array
|
||||
|400|Invalid tag value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Find pet by ID
|
||||
----
|
||||
GET /pets/{petId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|petId|ID of pet that needs to be fetched|true|integer (int64)
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Pet>>
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Pet not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Deletes a pet
|
||||
----
|
||||
DELETE /pets/{petId}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|HeaderParameter|api_key||true|string
|
||||
|PathParameter|petId|Pet id to delete|true|integer (int64)
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid pet value|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Updates a pet in the store with form data
|
||||
----
|
||||
POST /pets/{petId}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|petId|ID of pet that needs to be updated|true|string
|
||||
|FormDataParameter|name|Updated name of the pet|true|string
|
||||
|FormDataParameter|status|Updated status of the pet|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|405|Invalid input|No Content
|
||||
|===
|
||||
|
||||
==== Consumes
|
||||
|
||||
* application/x-www-form-urlencoded
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* pet
|
||||
|
||||
=== Place an order for a pet
|
||||
----
|
||||
POST /stores/order
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|order placed for purchasing the pet|false|<<Order>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Order>>
|
||||
|400|Invalid Order|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Find purchase order by ID
|
||||
----
|
||||
GET /stores/order/{orderId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|orderId|ID of pet that needs to be fetched|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<Order>>
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Order not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Delete purchase order by ID
|
||||
----
|
||||
DELETE /stores/order/{orderId}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|orderId|ID of the order that needs to be deleted|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid ID supplied|No Content
|
||||
|404|Order not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* store
|
||||
|
||||
=== Create user
|
||||
----
|
||||
POST /users
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|Created user object|false|<<User>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Creates list of users with given input array
|
||||
----
|
||||
POST /users/createWithArray
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|List of user object|false|<<User>> array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Creates list of users with given input array
|
||||
----
|
||||
POST /users/createWithList
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|BodyParameter|body|List of user object|false|<<User>> array
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Logs user into the system
|
||||
----
|
||||
GET /users/login
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|QueryParameter|username|The user name for login|false|string
|
||||
|QueryParameter|password|The password for login in clear text|false|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|string
|
||||
|400|Invalid username/password supplied|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Logs out current logged in user session
|
||||
----
|
||||
GET /users/logout
|
||||
----
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|default|successful operation|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Get user by user name
|
||||
----
|
||||
GET /users/{username}
|
||||
----
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|The name that needs to be fetched. Use user1 for testing.|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|200|successful operation|<<User>>
|
||||
|400|Invalid username supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Updated user
|
||||
----
|
||||
PUT /users/{username}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|name that need to be deleted|true|string
|
||||
|BodyParameter|body|Updated user object|false|<<User>>
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid user supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
=== Delete user
|
||||
----
|
||||
DELETE /users/{username}
|
||||
----
|
||||
|
||||
==== Description
|
||||
:hardbreaks:
|
||||
This can only be done by the logged in user.
|
||||
|
||||
==== Parameters
|
||||
[options="header"]
|
||||
|===
|
||||
|Type|Name|Description|Required|Schema
|
||||
|PathParameter|username|The name that needs to be deleted|true|string
|
||||
|===
|
||||
|
||||
==== Responses
|
||||
[options="header"]
|
||||
|===
|
||||
|HTTP Code|Description|Schema
|
||||
|400|Invalid username supplied|No Content
|
||||
|404|User not found|No Content
|
||||
|===
|
||||
|
||||
==== Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
==== Tags
|
||||
|
||||
* user
|
||||
|
||||
== Definitions
|
||||
=== User
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|username||string|false
|
||||
|firstName||string|false
|
||||
|lastName||string|false
|
||||
|email||string|false
|
||||
|password||string|false
|
||||
|phone||string|false
|
||||
|userStatus|User Status|integer (int32)|false
|
||||
|===
|
||||
|
||||
=== Category
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|name||string|false
|
||||
|===
|
||||
|
||||
=== Pet
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|category||<<Category>>|false
|
||||
|name||string|true
|
||||
|photoUrls||string array|true
|
||||
|tags||<<Tag>> array|false
|
||||
|status|pet status in the store|string|false
|
||||
|===
|
||||
|
||||
=== Tag
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|name||string|false
|
||||
|===
|
||||
|
||||
=== Order
|
||||
[options="header"]
|
||||
|===
|
||||
|Name|Description|Schema|Required
|
||||
|id||integer (int64)|false
|
||||
|petId||integer (int64)|false
|
||||
|quantity||integer (int32)|false
|
||||
|shipDate||string (date-time)|false
|
||||
|status|Order Status|string|false
|
||||
|complete||boolean|false
|
||||
|===
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
## Definitions
|
||||
### User
|
||||
|Name|Description|Schema|Required|
|
||||
|----|----|----|----|
|
||||
|id||integer (int64)|false|
|
||||
|username||string|false|
|
||||
|firstName||string|false|
|
||||
|lastName||string|false|
|
||||
|email||string|false|
|
||||
|password||string|false|
|
||||
|phone||string|false|
|
||||
|userStatus|User Status|integer (int32)|false|
|
||||
|
||||
|
||||
### Category
|
||||
|Name|Description|Schema|Required|
|
||||
|----|----|----|----|
|
||||
|id||integer (int64)|false|
|
||||
|name||string|false|
|
||||
|
||||
|
||||
### Pet
|
||||
|Name|Description|Schema|Required|
|
||||
|----|----|----|----|
|
||||
|id||integer (int64)|false|
|
||||
|category||Category|false|
|
||||
|name||string|true|
|
||||
|photoUrls||string array|true|
|
||||
|tags||Tag array|false|
|
||||
|status|pet status in the store|string|false|
|
||||
|
||||
|
||||
### Tag
|
||||
|Name|Description|Schema|Required|
|
||||
|----|----|----|----|
|
||||
|id||integer (int64)|false|
|
||||
|name||string|false|
|
||||
|
||||
|
||||
### Order
|
||||
|Name|Description|Schema|Required|
|
||||
|----|----|----|----|
|
||||
|id||integer (int64)|false|
|
||||
|petId||integer (int64)|false|
|
||||
|quantity||integer (int32)|false|
|
||||
|shipDate||string (date-time)|false|
|
||||
|status|Order Status|string|false|
|
||||
|complete||boolean|false|
|
||||
|
||||
|
||||
@@ -1,547 +0,0 @@
|
||||
# Swagger Petstore
|
||||
|
||||
This is a sample server Petstore server.
|
||||
|
||||
[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net.
|
||||
|
||||
For this sample, you can use the api key `special-key` to test the authorization filters
|
||||
|
||||
Version: 1.0.0
|
||||
Contact: apiteam@wordnik.com
|
||||
License: Apache 2.0
|
||||
License URL: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
Terms of service: http://helloreverb.com/terms/
|
||||
|
||||
Host: petstore.swagger.wordnik.com
|
||||
BasePath: /v2
|
||||
Schemes: HTTP
|
||||
|
||||
## Paths
|
||||
### Update an existing pet
|
||||
```
|
||||
PUT /pets
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|Pet|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|400|Invalid ID supplied|No Content|
|
||||
|404|Pet not found|No Content|
|
||||
|405|Validation exception|No Content|
|
||||
|
||||
|
||||
### Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Add a new pet to the store
|
||||
```
|
||||
POST /pets
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|Pet object that needs to be added to the store|false|Pet|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|405|Invalid input|No Content|
|
||||
|
||||
|
||||
### Consumes
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Finds Pets by status
|
||||
```
|
||||
GET /pets/findByStatus
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
Multiple status values can be provided with comma seperated strings
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|QueryParameter|status|Status values that need to be considered for filter|false|multi string array|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|Pet array|
|
||||
|400|Invalid status value|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Finds Pets by tags
|
||||
```
|
||||
GET /pets/findByTags
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|QueryParameter|tags|Tags to filter by|false|multi string array|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|Pet array|
|
||||
|400|Invalid tag value|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Find pet by ID
|
||||
```
|
||||
GET /pets/{petId}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|petId|ID of pet that needs to be fetched|true|integer (int64)|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|Pet|
|
||||
|400|Invalid ID supplied|No Content|
|
||||
|404|Pet not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Deletes a pet
|
||||
```
|
||||
DELETE /pets/{petId}
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|HeaderParameter|api_key||true|string|
|
||||
|PathParameter|petId|Pet id to delete|true|integer (int64)|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|400|Invalid pet value|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Updates a pet in the store with form data
|
||||
```
|
||||
POST /pets/{petId}
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|petId|ID of pet that needs to be updated|true|string|
|
||||
|FormDataParameter|name|Updated name of the pet|true|string|
|
||||
|FormDataParameter|status|Updated status of the pet|true|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|405|Invalid input|No Content|
|
||||
|
||||
|
||||
### Consumes
|
||||
|
||||
* application/x-www-form-urlencoded
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* pet
|
||||
|
||||
### Place an order for a pet
|
||||
```
|
||||
POST /stores/order
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|order placed for purchasing the pet|false|Order|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|Order|
|
||||
|400|Invalid Order|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* store
|
||||
|
||||
### Find purchase order by ID
|
||||
```
|
||||
GET /stores/order/{orderId}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|orderId|ID of pet that needs to be fetched|true|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|Order|
|
||||
|400|Invalid ID supplied|No Content|
|
||||
|404|Order not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* store
|
||||
|
||||
### Delete purchase order by ID
|
||||
```
|
||||
DELETE /stores/order/{orderId}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|orderId|ID of the order that needs to be deleted|true|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|400|Invalid ID supplied|No Content|
|
||||
|404|Order not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* store
|
||||
|
||||
### Create user
|
||||
```
|
||||
POST /users
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|Created user object|false|User|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|default|successful operation|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Creates list of users with given input array
|
||||
```
|
||||
POST /users/createWithArray
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|List of user object|false|User array|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|default|successful operation|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Creates list of users with given input array
|
||||
```
|
||||
POST /users/createWithList
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|BodyParameter|body|List of user object|false|User array|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|default|successful operation|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Logs user into the system
|
||||
```
|
||||
GET /users/login
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|QueryParameter|username|The user name for login|false|string|
|
||||
|QueryParameter|password|The password for login in clear text|false|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|string|
|
||||
|400|Invalid username/password supplied|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Logs out current logged in user session
|
||||
```
|
||||
GET /users/logout
|
||||
```
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|default|successful operation|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Get user by user name
|
||||
```
|
||||
GET /users/{username}
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|username|The name that needs to be fetched. Use user1 for testing.|true|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|200|successful operation|User|
|
||||
|400|Invalid username supplied|No Content|
|
||||
|404|User not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Updated user
|
||||
```
|
||||
PUT /users/{username}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|username|name that need to be deleted|true|string|
|
||||
|BodyParameter|body|Updated user object|false|User|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|400|Invalid user supplied|No Content|
|
||||
|404|User not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
### Delete user
|
||||
```
|
||||
DELETE /users/{username}
|
||||
```
|
||||
|
||||
### Description
|
||||
|
||||
This can only be done by the logged in user.
|
||||
|
||||
### Parameters
|
||||
|Type|Name|Description|Required|Schema|
|
||||
|----|----|----|----|----|
|
||||
|PathParameter|username|The name that needs to be deleted|true|string|
|
||||
|
||||
|
||||
### Responses
|
||||
|HTTP Code|Description|Schema|
|
||||
|----|----|----|
|
||||
|400|Invalid username supplied|No Content|
|
||||
|404|User not found|No Content|
|
||||
|
||||
|
||||
### Produces
|
||||
|
||||
* application/json
|
||||
* application/xml
|
||||
|
||||
### Tags
|
||||
|
||||
* user
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
package io.github.robwin.swagger2markup;
|
||||
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.builder.document.DefinitionsDocument;
|
||||
import io.github.robwin.swagger2markup.builder.document.PathsDocument;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class Swagger2MarkupConverter {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Swagger2MarkupConverter.class);
|
||||
|
||||
private final Swagger swagger;
|
||||
private final MarkupLanguage markupLanguage;
|
||||
private final String examplesFolderPath;
|
||||
private final String schemasFolderPath;
|
||||
private static final String PATHS_DOCUMENT = "paths";
|
||||
private static final String DEFINITIONS_DOCUMENT = "definitions";
|
||||
|
||||
/**
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @param swagger the Swagger object
|
||||
* @param examplesFolderPath the folderPath where examples are stored
|
||||
* @param schemasFolderPath the folderPath where (XML, JSON)-Schema files are stored
|
||||
*/
|
||||
Swagger2MarkupConverter(MarkupLanguage markupLanguage, Swagger swagger, String examplesFolderPath, String schemasFolderPath){
|
||||
this.markupLanguage = markupLanguage;
|
||||
this.swagger = swagger;
|
||||
this.examplesFolderPath = examplesFolderPath;
|
||||
this.schemasFolderPath = schemasFolderPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder using a given Swagger source.
|
||||
*
|
||||
* @param swaggerSource the Swagger source. Can be a HTTP url or a path to a local file.
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(String swaggerSource){
|
||||
Validate.notEmpty(swaggerSource, "swaggerSource must not be empty!");
|
||||
return new Builder(swaggerSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder from a given Swagger model.
|
||||
*
|
||||
* @param swagger the Swagger source.
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(Swagger swagger){
|
||||
Validate.notNull(swagger, "swagger must not be null!");
|
||||
return new Builder(swagger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the document with the given markup language and stores
|
||||
* the files in the given folder.
|
||||
*
|
||||
* @param targetFolderPath the target folder
|
||||
* @throws IOException if the files cannot be written
|
||||
*/
|
||||
public void intoFolder(String targetFolderPath) throws IOException {
|
||||
Validate.notEmpty(targetFolderPath, "folderPath must not be null!");
|
||||
buildDocuments(targetFolderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the document with the given markup language and returns it as a String
|
||||
*
|
||||
* @return a the document as a String
|
||||
*/
|
||||
public String asString() throws IOException{
|
||||
return buildDocuments();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a file for the Paths (API) and a file for the Definitions (Model)
|
||||
|
||||
* @param directory the directory where the generated file should be stored
|
||||
* @throws IOException if a file cannot be written
|
||||
*/
|
||||
private void buildDocuments(String directory) throws IOException {
|
||||
new PathsDocument(swagger, markupLanguage, examplesFolderPath).build().writeToFile(directory, PATHS_DOCUMENT, StandardCharsets.UTF_8);
|
||||
new DefinitionsDocument(swagger, markupLanguage, schemasFolderPath).build().writeToFile(directory, DEFINITIONS_DOCUMENT, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file for the Paths (API) and a file for the Definitions (Model)
|
||||
|
||||
* @return a the document as a String
|
||||
*/
|
||||
private String buildDocuments() throws IOException {
|
||||
return new PathsDocument(swagger, markupLanguage, examplesFolderPath).build().toString()
|
||||
.concat(new DefinitionsDocument(swagger, markupLanguage, schemasFolderPath).build().toString());
|
||||
}
|
||||
|
||||
|
||||
public static class Builder{
|
||||
private final Swagger swagger;
|
||||
private String examplesFolderPath;
|
||||
private String schemasFolderPath;
|
||||
private MarkupLanguage markupLanguage = MarkupLanguage.ASCIIDOC;
|
||||
|
||||
/**
|
||||
* Creates a Builder using a given Swagger source.
|
||||
*
|
||||
* @param swaggerSource the Swagger source. Can be a HTTP url or a path to a local file.
|
||||
*/
|
||||
Builder(String swaggerSource){
|
||||
swagger = new SwaggerParser().read(swaggerSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Builder using a given Swagger model.
|
||||
*
|
||||
* @param swagger the Swagger source.
|
||||
*/
|
||||
Builder(Swagger swagger){
|
||||
this.swagger = swagger;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Swagger2MarkupConverter build(){
|
||||
return new Swagger2MarkupConverter(markupLanguage, swagger, examplesFolderPath, schemasFolderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the markup language which should be used to generate the files
|
||||
*
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withMarkupLanguage(MarkupLanguage markupLanguage){
|
||||
this.markupLanguage = markupLanguage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include examples into the Paths document
|
||||
*
|
||||
* @param examplesFolderPath the path to the folder where the example documents reside
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withExamples(String examplesFolderPath){
|
||||
this.examplesFolderPath = examplesFolderPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include (JSON, XML) schemas into the Definitions document
|
||||
*
|
||||
* @param schemasFolderPath the path to the folder where the schema documents reside
|
||||
* @return the Swagger2MarkupConverter.Builder
|
||||
*/
|
||||
public Builder withSchemas(String schemasFolderPath){
|
||||
this.schemasFolderPath = schemasFolderPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import com.wordnik.swagger.models.Model;
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import com.wordnik.swagger.models.properties.AbstractProperty;
|
||||
import com.wordnik.swagger.models.properties.Property;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.utils.PropertyUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class DefinitionsDocument extends MarkupDocument {
|
||||
|
||||
private static final String DEFINITIONS = "Definitions";
|
||||
private static final List<String> IGNORED_DEFINITIONS = Arrays.asList("Void");
|
||||
private static final String JSON_SCHEMA = "JSON Schema";
|
||||
private static final String XML_SCHEMA = "XML Schema";
|
||||
public static final String JSON_SCHEMA_EXTENSION = ".json";
|
||||
public static final String XML_SCHEMA_EXTENSION = ".xsd";
|
||||
public static final String JSON = "json";
|
||||
public static final String XML = "xml";
|
||||
private boolean schemasEnabled;
|
||||
private String schemasFolderPath;
|
||||
|
||||
public DefinitionsDocument(Swagger swagger, MarkupLanguage markupLanguage, String schemasFolderPath){
|
||||
super(swagger, markupLanguage);
|
||||
if(StringUtils.isNotBlank(schemasFolderPath)){
|
||||
this.schemasEnabled = true;
|
||||
this.schemasFolderPath = schemasFolderPath;
|
||||
}
|
||||
if(schemasEnabled){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include schemas is enabled.");
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include schemas is disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocument build() throws IOException {
|
||||
definitions(swagger.getDefinitions());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Swagger definitions.
|
||||
*
|
||||
* @param definitions the Swagger definitions
|
||||
*/
|
||||
private void definitions(Map<String, Model> definitions) throws IOException {
|
||||
if(MapUtils.isNotEmpty(definitions)){
|
||||
this.markupDocBuilder.sectionTitleLevel1(DEFINITIONS);
|
||||
for(Map.Entry<String, Model> definitionsEntry : definitions.entrySet()){
|
||||
String definitionName = definitionsEntry.getKey();
|
||||
if(StringUtils.isNotBlank(definitionName)) {
|
||||
if (checkThatDefinitionIsNotInIgnoreList(definitionName)) {
|
||||
definition(definitionName, definitionsEntry.getValue());
|
||||
definitionSchema(definitionName);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Definition processed: {}", definitionName);
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Definition was ignored: {}", definitionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the definition is not in the list of ignored definitions.
|
||||
*
|
||||
* @param definitionName the name of the definition
|
||||
* @return true if the definition can be processed
|
||||
*/
|
||||
private boolean checkThatDefinitionIsNotInIgnoreList(String definitionName) {
|
||||
return !IGNORED_DEFINITIONS.contains(definitionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a concrete definition
|
||||
*
|
||||
* @param definitionName the name of the definition
|
||||
* @param model the Swagger Model of the definition
|
||||
*/
|
||||
private void definition(String definitionName, Model model) {
|
||||
this.markupDocBuilder.sectionTitleLevel2(definitionName);
|
||||
Map<String, Property> properties = model.getProperties();
|
||||
List<String> headerAndContent = new ArrayList<>();
|
||||
List<String> header = Arrays.asList(NAME_COLUMN, DESCRIPTION_COLUMN, SCHEMA_COLUMN, REQUIRED_COLUMN);
|
||||
headerAndContent.add(StringUtils.join(header, DELIMITER));
|
||||
if(MapUtils.isNotEmpty(properties)){
|
||||
for (Map.Entry<String, Property> propertyEntry : properties.entrySet()) {
|
||||
Property property = propertyEntry.getValue();
|
||||
String description = "";
|
||||
if(property instanceof AbstractProperty){
|
||||
if(StringUtils.isNotBlank(property.getDescription())){
|
||||
description = property.getDescription();
|
||||
}
|
||||
}
|
||||
String type = PropertyUtils.getType(property, markupLanguage);
|
||||
List<String> content = Arrays.asList(propertyEntry.getKey(), description, type, Boolean.toString(property.getRequired()));
|
||||
headerAndContent.add(StringUtils.join(content, DELIMITER));
|
||||
}
|
||||
this.markupDocBuilder.tableWithHeaderRow(headerAndContent);
|
||||
}
|
||||
}
|
||||
|
||||
private void definitionSchema(String definitionName) throws IOException {
|
||||
if(schemasEnabled) {
|
||||
if (StringUtils.isNotBlank(definitionName)) {
|
||||
schema(JSON_SCHEMA, schemasFolderPath, definitionName + JSON_SCHEMA_EXTENSION, JSON);
|
||||
schema(XML_SCHEMA, schemasFolderPath, definitionName + XML_SCHEMA_EXTENSION, XML);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void schema(String title, String schemasFolderPath, String schemaName, String language) throws IOException {
|
||||
java.nio.file.Path path = Paths.get(schemasFolderPath, schemaName);
|
||||
if (Files.isReadable(path)) {
|
||||
this.markupDocBuilder.sectionTitleLevel3(title);
|
||||
this.markupDocBuilder.source(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim(), language);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Schema file processed: {}", path);
|
||||
}
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Schema file is not readable: {}", path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilder;
|
||||
import io.github.robwin.markup.builder.MarkupDocBuilders;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public abstract class MarkupDocument {
|
||||
|
||||
protected static final String DELIMITER = "|";
|
||||
protected static final String REQUIRED_COLUMN = "Required";
|
||||
protected static final String SCHEMA_COLUMN = "Schema";
|
||||
protected static final String NAME_COLUMN = "Name";
|
||||
protected static final String DESCRIPTION_COLUMN = "Description";
|
||||
protected static final String DESCRIPTION = DESCRIPTION_COLUMN;
|
||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected Swagger swagger;
|
||||
protected MarkupLanguage markupLanguage;
|
||||
protected MarkupDocBuilder markupDocBuilder;
|
||||
|
||||
MarkupDocument(Swagger swagger, MarkupLanguage markupLanguage){
|
||||
this.swagger = swagger;
|
||||
this.markupLanguage = markupLanguage;
|
||||
this.markupDocBuilder = MarkupDocBuilders.documentBuilder(markupLanguage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the MarkupDocument.
|
||||
*
|
||||
* @return the built MarkupDocument
|
||||
* @throws IOException if the files to include are not readable
|
||||
*/
|
||||
public abstract MarkupDocument build() throws IOException ;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the document.
|
||||
*/
|
||||
public String toString(){
|
||||
return markupDocBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the builder to a file and clears the builder.
|
||||
*
|
||||
* @param directory the directory where the generated file should be stored
|
||||
* @param fileName the name of the file
|
||||
* @param charset the the charset to use for encoding
|
||||
* @throws IOException if the file cannot be written
|
||||
*/
|
||||
public void writeToFile(String directory, String fileName, Charset charset) throws IOException{
|
||||
markupDocBuilder.writeToFile(directory, fileName, charset);
|
||||
}
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
package io.github.robwin.swagger2markup.builder.document;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.parameters.Parameter;
|
||||
import com.wordnik.swagger.models.properties.Property;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import io.github.robwin.swagger2markup.utils.ParameterUtils;
|
||||
import io.github.robwin.swagger2markup.utils.PropertyUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class PathsDocument extends MarkupDocument {
|
||||
|
||||
private static final String PATHS = "Paths";
|
||||
private static final String VERSION = "Version: ";
|
||||
private static final String CONTACT_NAME = "Contact: ";
|
||||
private static final String CONTACT_EMAIL = "Contact Email: ";
|
||||
private static final String LICENSE = "License: ";
|
||||
private static final String LICENSE_URL = "License URL: ";
|
||||
private static final String TERMS_OF_SERVICE = "Terms of service: ";
|
||||
private static final String HOST = "Host: ";
|
||||
private static final String BASE_PATH = "BasePath: ";
|
||||
private static final String SCHEMES = "Schemes: ";
|
||||
private static final String PARAMETERS = "Parameters";
|
||||
private static final String PRODUCES = "Produces";
|
||||
private static final String CONSUMES = "Consumes";
|
||||
private static final String TAGS = "Tags";
|
||||
private static final String RESPONSES = "Responses";
|
||||
private static final String EXAMPLE_REQUEST = "Example request";
|
||||
private static final String EXAMPLE_RESPONSE = "Example response";
|
||||
private static final String TYPE_COLUMN = "Type";
|
||||
private static final String HTTP_CODE_COLUMN = "HTTP Code";
|
||||
private static final String REQUEST_EXAMPLE_FILE_NAME = "request";
|
||||
private static final String RESPONSE_EXAMPLE_FILE_NAME = "response";
|
||||
|
||||
private boolean examplesEnabled;
|
||||
private String examplesFolderPath;
|
||||
|
||||
public PathsDocument(Swagger swagger, MarkupLanguage markupLanguage, String examplesFolderPath){
|
||||
super(swagger, markupLanguage);
|
||||
if(StringUtils.isNotBlank(examplesFolderPath)){
|
||||
this.examplesEnabled = true;
|
||||
this.examplesFolderPath = examplesFolderPath;
|
||||
}
|
||||
if(examplesEnabled){
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include examples is enabled.");
|
||||
}
|
||||
}else{
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Include examples is disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocument build() throws IOException {
|
||||
documentHeader();
|
||||
paths();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the document header of the swagger model
|
||||
*/
|
||||
private void documentHeader() {
|
||||
Info info = swagger.getInfo();
|
||||
this.markupDocBuilder.documentTitle(info.getTitle());
|
||||
if(StringUtils.isNotBlank(info.getDescription())){
|
||||
this.markupDocBuilder.textLine(info.getDescription());
|
||||
}
|
||||
if(StringUtils.isNotBlank(info.getVersion())){
|
||||
this.markupDocBuilder.textLine(VERSION + info.getVersion());
|
||||
}
|
||||
Contact contact = info.getContact();
|
||||
if(contact != null){
|
||||
if(StringUtils.isNotBlank(contact.getName())){
|
||||
this.markupDocBuilder.textLine(CONTACT_NAME + contact.getName());
|
||||
}
|
||||
if(StringUtils.isNotBlank(contact.getEmail())){
|
||||
this.markupDocBuilder.textLine(CONTACT_EMAIL + contact.getEmail());
|
||||
}
|
||||
}
|
||||
License license = info.getLicense();
|
||||
if(license != null) {
|
||||
if (StringUtils.isNotBlank(license.getName())) {
|
||||
this.markupDocBuilder.textLine(LICENSE + license.getName());
|
||||
}
|
||||
if (StringUtils.isNotBlank(license.getUrl())) {
|
||||
this.markupDocBuilder.textLine(LICENSE_URL + license.getUrl());
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(info.getTermsOfService())){
|
||||
this.markupDocBuilder.textLine(TERMS_OF_SERVICE + info.getTermsOfService());
|
||||
}
|
||||
this.markupDocBuilder.newLine();
|
||||
|
||||
if(StringUtils.isNotBlank(swagger.getHost())){
|
||||
this.markupDocBuilder.textLine(HOST + swagger.getHost());
|
||||
}
|
||||
if(StringUtils.isNotBlank(swagger.getBasePath())){
|
||||
this.markupDocBuilder.textLine(BASE_PATH + swagger.getBasePath());
|
||||
}
|
||||
if(CollectionUtils.isNotEmpty(swagger.getSchemes())){
|
||||
List<String> schemes = new ArrayList<>();
|
||||
for(Scheme scheme : swagger.getSchemes()){
|
||||
schemes.add(scheme.toString());
|
||||
}
|
||||
this.markupDocBuilder.textLine(SCHEMES + StringUtils.join(schemes, ", "));
|
||||
}
|
||||
this.markupDocBuilder.newLine();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds all paths of the Swagger model
|
||||
*/
|
||||
private void paths() throws IOException {
|
||||
Map<String, Path> paths = swagger.getPaths();
|
||||
if(MapUtils.isNotEmpty(paths)) {
|
||||
this.markupDocBuilder.sectionTitleLevel1(PATHS);
|
||||
for (Map.Entry<String, Path> entry : paths.entrySet()) {
|
||||
Path path = entry.getValue();
|
||||
if(path != null) {
|
||||
path("GET", entry.getKey(), path.getGet());
|
||||
path("PUT", entry.getKey(), path.getPut());
|
||||
path("DELETE", entry.getKey(), path.getDelete());
|
||||
path("POST", entry.getKey(), path.getPost());
|
||||
path("PATCH", entry.getKey(), path.getPatch());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a path
|
||||
*
|
||||
* @param httpMethod the HTTP method of the path
|
||||
* @param resourcePath the URL of the path
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void path(String httpMethod, String resourcePath, Operation operation) throws IOException {
|
||||
if(operation != null){
|
||||
pathTitle(httpMethod, resourcePath, operation);
|
||||
descriptionSection(operation);
|
||||
parametersSection(operation);
|
||||
responsesSection(operation);
|
||||
consumesSection(operation);
|
||||
producesSection(operation);
|
||||
tagsSection(operation);
|
||||
examplesSection(operation);
|
||||
}
|
||||
}
|
||||
|
||||
private void pathTitle(String httpMethod, String resourcePath, Operation operation) {
|
||||
String summary = operation.getSummary();
|
||||
String title;
|
||||
if(StringUtils.isNotBlank(summary)) {
|
||||
title = summary;
|
||||
this.markupDocBuilder.sectionTitleLevel2(title);
|
||||
this.markupDocBuilder.listing(httpMethod + " " + resourcePath);
|
||||
}else{
|
||||
title = httpMethod + " " + resourcePath;
|
||||
this.markupDocBuilder.sectionTitleLevel2(title);
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Path processed: {}", title);
|
||||
}
|
||||
}
|
||||
|
||||
private void descriptionSection(Operation operation) {
|
||||
String description = operation.getDescription();
|
||||
if(StringUtils.isNotBlank(description)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(DESCRIPTION);
|
||||
this.markupDocBuilder.paragraph(description);
|
||||
}
|
||||
}
|
||||
|
||||
private void parametersSection(Operation operation) {
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
if(CollectionUtils.isNotEmpty(parameters)){
|
||||
List<String> headerAndContent = new ArrayList<>();
|
||||
// Table header row
|
||||
List<String> header = Arrays.asList(TYPE_COLUMN, NAME_COLUMN, DESCRIPTION_COLUMN, REQUIRED_COLUMN, SCHEMA_COLUMN);
|
||||
headerAndContent.add(StringUtils.join(header, DELIMITER));
|
||||
for(Parameter parameter : parameters){
|
||||
String type = ParameterUtils.getType(parameter, markupLanguage);
|
||||
String parameterType = WordUtils.capitalize(parameter.getIn() + "Parameter");
|
||||
// Table content row
|
||||
List<String> content = Arrays.asList(parameterType, parameter.getName(), parameter.getDescription(), Boolean.toString(parameter.getRequired()), type);
|
||||
headerAndContent.add(StringUtils.join(content, DELIMITER));
|
||||
}
|
||||
this.markupDocBuilder.sectionTitleLevel3(PARAMETERS);
|
||||
this.markupDocBuilder.tableWithHeaderRow(headerAndContent);
|
||||
}
|
||||
}
|
||||
|
||||
private void consumesSection(Operation operation) {
|
||||
List<String> consumes = operation.getConsumes();
|
||||
if(CollectionUtils.isNotEmpty(consumes)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(CONSUMES);
|
||||
this.markupDocBuilder.unorderedList(consumes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void producesSection(Operation operation) {
|
||||
List<String> produces = operation.getProduces();
|
||||
if(CollectionUtils.isNotEmpty(produces)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(PRODUCES);
|
||||
this.markupDocBuilder.unorderedList(produces);
|
||||
}
|
||||
}
|
||||
|
||||
private void tagsSection(Operation operation) {
|
||||
List<String> tags = operation.getTags();
|
||||
if(CollectionUtils.isNotEmpty(tags)){
|
||||
this.markupDocBuilder.sectionTitleLevel3(TAGS);
|
||||
this.markupDocBuilder.unorderedList(tags);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the example section of a Swagger Operation
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @throws IOException if the example file is not readable
|
||||
*/
|
||||
private void examplesSection(Operation operation) throws IOException {
|
||||
if(examplesEnabled){
|
||||
String summary = operation.getSummary();
|
||||
if(StringUtils.isNotBlank(summary)) {
|
||||
String exampleFolder = summary.replace(".", "").replace(" ", "_").toLowerCase();
|
||||
example(EXAMPLE_REQUEST, exampleFolder, REQUEST_EXAMPLE_FILE_NAME);
|
||||
example(EXAMPLE_RESPONSE, exampleFolder, RESPONSE_EXAMPLE_FILE_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a concrete example
|
||||
*
|
||||
* @param title the title of the example
|
||||
* @param exampleFolder the name of the folder where the example file resides
|
||||
* @param exampleFileName the name of the example file
|
||||
* @throws IOException
|
||||
*/
|
||||
private void example(String title, String exampleFolder, String exampleFileName) throws IOException {
|
||||
for (String fileNameExtension : markupLanguage.getFileNameExtensions()) {
|
||||
java.nio.file.Path path = Paths.get(examplesFolderPath, exampleFolder, exampleFileName + fileNameExtension);
|
||||
if (Files.isReadable(path)) {
|
||||
this.markupDocBuilder.sectionTitleLevel3(title);
|
||||
this.markupDocBuilder.paragraph(FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8).trim());
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Example file processed: {}", path);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Example file is not readable: {}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void responsesSection(Operation operation) {
|
||||
Map<String, Response> responses = operation.getResponses();
|
||||
if(MapUtils.isNotEmpty(responses)){
|
||||
List<String> csvContent = new ArrayList<>();
|
||||
csvContent.add(HTTP_CODE_COLUMN + DELIMITER + DESCRIPTION_COLUMN + DELIMITER + SCHEMA_COLUMN);
|
||||
for(Map.Entry<String, Response> entry : responses.entrySet()){
|
||||
Response response = entry.getValue();
|
||||
if(response.getSchema() != null){
|
||||
Property property = response.getSchema();
|
||||
String type = PropertyUtils.getType(property, markupLanguage);
|
||||
csvContent.add(entry.getKey() + DELIMITER + response.getDescription() + DELIMITER + type);
|
||||
}else{
|
||||
csvContent.add(entry.getKey() + DELIMITER + response.getDescription() + DELIMITER + "No Content");
|
||||
}
|
||||
}
|
||||
this.markupDocBuilder.sectionTitleLevel3(RESPONSES);
|
||||
this.markupDocBuilder.tableWithHeaderRow(csvContent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
import com.wordnik.swagger.models.ArrayModel;
|
||||
import com.wordnik.swagger.models.Model;
|
||||
import com.wordnik.swagger.models.ModelImpl;
|
||||
import com.wordnik.swagger.models.RefModel;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
public final class ModelUtils {
|
||||
|
||||
public static String getType(Model model, MarkupLanguage markupLanguage) {
|
||||
Validate.notNull(model, "model must not be null!");
|
||||
if (model instanceof ModelImpl) {
|
||||
return ((ModelImpl) model).getType();
|
||||
} else if (model instanceof RefModel) {
|
||||
switch (markupLanguage){
|
||||
case ASCIIDOC: return "<<" + ((RefModel) model).getSimpleRef() + ">>";
|
||||
default: return ((RefModel) model).getSimpleRef();
|
||||
}
|
||||
} else if (model instanceof ArrayModel) {
|
||||
ArrayModel arrayModel = ((ArrayModel) model);
|
||||
return PropertyUtils.getType(arrayModel.getItems(), markupLanguage) + " " + arrayModel.getType();
|
||||
}
|
||||
return "NOT FOUND";
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
import com.wordnik.swagger.models.Model;
|
||||
import com.wordnik.swagger.models.parameters.*;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
public final class ParameterUtils {
|
||||
|
||||
public static String getType(Parameter parameter, MarkupLanguage markupLanguage){
|
||||
Validate.notNull(parameter, "property must not be null!");
|
||||
String type = "NOT FOUND";
|
||||
if(parameter instanceof BodyParameter){
|
||||
BodyParameter bodyParameter = (BodyParameter)parameter;
|
||||
Model model = bodyParameter.getSchema();
|
||||
type = ModelUtils.getType(model, markupLanguage);
|
||||
}
|
||||
else if(parameter instanceof PathParameter){
|
||||
PathParameter pathParameter = (PathParameter)parameter;
|
||||
type = getTypeWithFormat(pathParameter.getType(), pathParameter.getFormat());
|
||||
}
|
||||
else if(parameter instanceof QueryParameter){
|
||||
QueryParameter queryParameter = (QueryParameter)parameter;
|
||||
type = getTypeWithFormat(queryParameter.getType(), queryParameter.getFormat());
|
||||
if(type.equals("array")){
|
||||
String collectionFormat = queryParameter.getCollectionFormat();
|
||||
type = collectionFormat + " " + PropertyUtils.getType(queryParameter.getItems(), markupLanguage) + " " + type;
|
||||
}
|
||||
}
|
||||
else if(parameter instanceof HeaderParameter){
|
||||
HeaderParameter headerParameter = (HeaderParameter)parameter;
|
||||
type = getTypeWithFormat(headerParameter.getType(), headerParameter.getFormat());
|
||||
}
|
||||
else if(parameter instanceof FormParameter){
|
||||
FormParameter formParameter = (FormParameter)parameter;
|
||||
type = formParameter.getType();
|
||||
}
|
||||
else if(parameter instanceof CookieParameter){
|
||||
CookieParameter cookieParameter = (CookieParameter)parameter;
|
||||
type = getTypeWithFormat(cookieParameter.getType(), cookieParameter.getFormat());
|
||||
}
|
||||
else if(parameter instanceof RefParameter){
|
||||
RefParameter refParameter = (RefParameter)parameter;
|
||||
switch (markupLanguage){
|
||||
case ASCIIDOC: return "<<" + refParameter.getSimpleRef() + ">>";
|
||||
default: return refParameter.getSimpleRef();
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
private static String getTypeWithFormat(String typeWithoutFormat, String format) {
|
||||
String type;
|
||||
if(StringUtils.isNotBlank(format)){
|
||||
type = typeWithoutFormat + " (" + format + ")";
|
||||
}else{
|
||||
type = typeWithoutFormat;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package io.github.robwin.swagger2markup.utils;
|
||||
|
||||
import com.wordnik.swagger.models.properties.ArrayProperty;
|
||||
import com.wordnik.swagger.models.properties.Property;
|
||||
import com.wordnik.swagger.models.properties.RefProperty;
|
||||
import com.wordnik.swagger.models.properties.StringProperty;
|
||||
import io.github.robwin.markup.builder.MarkupLanguage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class PropertyUtils {
|
||||
|
||||
public static String getType(Property property, MarkupLanguage markupLanguage){
|
||||
Validate.notNull(property, "property must not be null!");
|
||||
String type;
|
||||
if(property instanceof RefProperty){
|
||||
RefProperty refProperty = (RefProperty)property;
|
||||
switch (markupLanguage){
|
||||
case ASCIIDOC: return "<<" + refProperty.getSimpleRef() + ">>";
|
||||
default: return refProperty.getSimpleRef();
|
||||
}
|
||||
}else if(property instanceof ArrayProperty){
|
||||
ArrayProperty arrayProperty = (ArrayProperty)property;
|
||||
Property items = arrayProperty.getItems();
|
||||
type = getType(items, markupLanguage) + " " + arrayProperty.getType();
|
||||
}else if(property instanceof StringProperty){
|
||||
StringProperty stringProperty = (StringProperty)property;
|
||||
List<String> enums = stringProperty.getEnum();
|
||||
if(CollectionUtils.isNotEmpty(enums)){
|
||||
type = "enum" + " (" + StringUtils.join(enums, ", ") + ")";
|
||||
}else{
|
||||
type = property.getType();
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(StringUtils.isNotBlank(property.getFormat())){
|
||||
type = property.getType() + " (" + property.getFormat() + ")";
|
||||
}else{
|
||||
type = property.getType();
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
||||
21
src/main/java/io/github/swagger2markup/GroupBy.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
public enum GroupBy {
|
||||
AS_IS,
|
||||
TAGS
|
||||
}
|
||||
109
src/main/java/io/github/swagger2markup/Labels.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Labels {
|
||||
|
||||
public static final String DEFAULT_COLUMN = "default_column";
|
||||
public static final String MAXLENGTH_COLUMN = "maxlength_column";
|
||||
public static final String MINLENGTH_COLUMN = "minlength_column";
|
||||
public static final String LENGTH_COLUMN = "length_column";
|
||||
public static final String PATTERN_COLUMN = "pattern_column";
|
||||
public static final String MINVALUE_COLUMN = "minvalue_column";
|
||||
public static final String MINVALUE_EXCLUSIVE_COLUMN = "minvalue_exclusive_column";
|
||||
public static final String MAXVALUE_COLUMN = "maxvalue_column";
|
||||
public static final String MAXVALUE_EXCLUSIVE_COLUMN = "maxvalue_exclusive_column";
|
||||
public static final String EXAMPLE_COLUMN = "example_column";
|
||||
public static final String SCHEMA_COLUMN = "schema_column";
|
||||
public static final String NAME_COLUMN = "name_column";
|
||||
public static final String DESCRIPTION_COLUMN = "description_column";
|
||||
public static final String SCOPES_COLUMN = "scopes_column";
|
||||
public static final String DESCRIPTION = DESCRIPTION_COLUMN;
|
||||
public static final String PRODUCES = "produces";
|
||||
public static final String CONSUMES = "consumes";
|
||||
public static final String TAGS = "tags";
|
||||
public static final String NO_CONTENT = "no_content";
|
||||
public static final String FLAGS_COLUMN = "flags.column";
|
||||
public static final String FLAGS_REQUIRED = "flags.required";
|
||||
public static final String FLAGS_OPTIONAL = "flags.optional";
|
||||
public static final String FLAGS_READ_ONLY = "flags.read_only";
|
||||
|
||||
// Overview Document
|
||||
public static final String CONTACT_INFORMATION ="contact_information";
|
||||
public static final String CONTACT_NAME = "contact_name";
|
||||
public static final String CONTACT_EMAIL = "contact_email";
|
||||
public static final String LICENSE_INFORMATION = "license_information";
|
||||
public static final String LICENSE = "license";
|
||||
public static final String LICENSE_URL = "license_url";
|
||||
public static final String TERMS_OF_SERVICE = "terms_of_service";
|
||||
public static final String CURRENT_VERSION = "current_version";
|
||||
public static final String VERSION = "version";
|
||||
public static final String OVERVIEW = "overview";
|
||||
public static final String URI_SCHEME = "uri_scheme";
|
||||
public static final String HOST = "host";
|
||||
public static final String BASE_PATH = "base_path";
|
||||
public static final String SCHEMES = "schemes";
|
||||
|
||||
//Security Document
|
||||
public static final String SECURITY = "security";
|
||||
public static final String TYPE = "security_type";
|
||||
public static final String NAME = "security_name";
|
||||
public static final String IN = "security_in";
|
||||
public static final String FLOW = "security_flow";
|
||||
public static final String AUTHORIZATION_URL = "security_authorizationUrl";
|
||||
public static final String TOKEN_URL = "security_tokenUrl";
|
||||
|
||||
//Definitions Document
|
||||
public static final String DEFINITIONS = "definitions";
|
||||
public static final String POLYMORPHISM_COLUMN = "polymorphism.column";
|
||||
public static final String POLYMORPHISM_DISCRIMINATOR_COLUMN = "polymorphism.discriminator";
|
||||
public static final String TYPE_COLUMN = "type_column";
|
||||
public static final String POLYMORPHISM_NATURE_COMPOSITION = "polymorphism.nature.COMPOSITION";
|
||||
public static final String POLYMORPHISM_NATURE_INHERITANCE = "polymorphism.nature.INHERITANCE";
|
||||
|
||||
//Paths Document
|
||||
public static final String RESPONSE = "response";
|
||||
public static final String REQUEST = "request";
|
||||
public static final String PATHS = "paths";
|
||||
public static final String RESOURCES = "resources";
|
||||
public static final String PARAMETERS = "parameters";
|
||||
public static final String BODY_PARAMETER = "body_parameter";
|
||||
public static final String RESPONSES = "responses";
|
||||
public static final String HEADERS_COLUMN = "headers_column";
|
||||
public static final String EXAMPLE_REQUEST = "example_request";
|
||||
public static final String EXAMPLE_RESPONSE = "example_response";
|
||||
public static final String HTTP_CODE_COLUMN = "http_code_column";
|
||||
public static final String DEPRECATED_OPERATION = "operation.deprecated";
|
||||
public static final String UNKNOWN = "unknown";
|
||||
|
||||
private ResourceBundle resourceBundle;
|
||||
|
||||
public Labels(Swagger2MarkupConfig config) {
|
||||
this.resourceBundle = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getOutputLanguage().toLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a label for the given key from this resource bundle.
|
||||
*
|
||||
* @param key the key for the desired label
|
||||
* @return the label for the given key
|
||||
*/
|
||||
public String getLabel(String key){
|
||||
return resourceBundle.getString(key);
|
||||
}
|
||||
}
|
||||
44
src/main/java/io/github/swagger2markup/Language.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.swagger2markup;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author Maksim Myshkin
|
||||
*/
|
||||
public enum Language {
|
||||
EN(Locale.ENGLISH),
|
||||
RU(new Locale("ru")),
|
||||
FR(Locale.FRENCH),
|
||||
DE(Locale.GERMAN),
|
||||
TR(new Locale("tr")),
|
||||
ZH(Locale.CHINESE),
|
||||
ES(new Locale("es")),
|
||||
BR(new Locale("pt", "BR")),
|
||||
JA(Locale.JAPANESE);
|
||||
|
||||
private final Locale lang;
|
||||
|
||||
Language(final Locale lang) {
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public Locale toLocale() {
|
||||
return lang;
|
||||
}
|
||||
}
|
||||
22
src/main/java/io/github/swagger2markup/OrderBy.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
public enum OrderBy {
|
||||
AS_IS,
|
||||
NATURAL,
|
||||
CUSTOM
|
||||
}
|
||||
216
src/main/java/io/github/swagger2markup/Swagger2MarkupConfig.java
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.LineSeparator;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Swagger2Markup configuration interface.
|
||||
*/
|
||||
public interface Swagger2MarkupConfig {
|
||||
|
||||
/**
|
||||
* Specifies the markup language which should be used to generate the files.
|
||||
*/
|
||||
MarkupLanguage getMarkupLanguage();
|
||||
|
||||
/**
|
||||
* Specifies the markup language used in Swagger descriptions.<br>
|
||||
* By default, {@link io.github.swagger2markup.markup.builder.MarkupLanguage#MARKDOWN} is assumed.
|
||||
*/
|
||||
MarkupLanguage getSwaggerMarkupLanguage();
|
||||
|
||||
/**
|
||||
* Include generated examples into the documents.
|
||||
*/
|
||||
boolean isGeneratedExamplesEnabled();
|
||||
|
||||
/**
|
||||
* Prepend the base path to all paths.
|
||||
*/
|
||||
boolean isBasePathPrefixEnabled();
|
||||
|
||||
/**
|
||||
* In addition to the Definitions file, also create separate definition files for each model definition.
|
||||
*/
|
||||
boolean isSeparatedDefinitionsEnabled();
|
||||
|
||||
/**
|
||||
* In addition to the Paths file, also create separate operation files for each operation.
|
||||
*/
|
||||
boolean isSeparatedOperationsEnabled();
|
||||
|
||||
/**
|
||||
* Specifies if the operations should be grouped by tags or stay as-is.
|
||||
*/
|
||||
GroupBy getPathsGroupedBy();
|
||||
|
||||
/**
|
||||
* Specifies labels language of output files.
|
||||
*/
|
||||
Language getOutputLanguage();
|
||||
|
||||
/**
|
||||
* Specifies if inline schemas are detailed
|
||||
*/
|
||||
boolean isInlineSchemaEnabled();
|
||||
|
||||
/**
|
||||
* Specifies tag ordering.
|
||||
*/
|
||||
OrderBy getTagOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order tags.
|
||||
*/
|
||||
Comparator<String> getTagOrdering();
|
||||
|
||||
/**
|
||||
* Specifies operation ordering.
|
||||
*/
|
||||
OrderBy getOperationOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order operations.
|
||||
*/
|
||||
Comparator<PathOperation> getOperationOrdering();
|
||||
|
||||
/**
|
||||
* Specifies definition ordering.
|
||||
*/
|
||||
OrderBy getDefinitionOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order definitions.
|
||||
*/
|
||||
Comparator<String> getDefinitionOrdering();
|
||||
|
||||
/**
|
||||
* Specifies parameter ordering.
|
||||
*/
|
||||
OrderBy getParameterOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order parameters.
|
||||
*/
|
||||
Comparator<Parameter> getParameterOrdering();
|
||||
|
||||
/**
|
||||
* Specifies property ordering.
|
||||
*/
|
||||
OrderBy getPropertyOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order properties.
|
||||
*/
|
||||
Comparator<String> getPropertyOrdering();
|
||||
|
||||
/**
|
||||
* Specifies response ordering.
|
||||
*/
|
||||
OrderBy getResponseOrderBy();
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order responses.
|
||||
*/
|
||||
Comparator<String> getResponseOrdering();
|
||||
|
||||
/**
|
||||
* Enable use of inter-document cross-references when needed.
|
||||
*/
|
||||
boolean isInterDocumentCrossReferencesEnabled();
|
||||
|
||||
/**
|
||||
* Inter-document cross-references optional prefix.
|
||||
*/
|
||||
String getInterDocumentCrossReferencesPrefix();
|
||||
|
||||
/**
|
||||
* Optionally isolate the body parameter, if any, from other parameters.
|
||||
*/
|
||||
boolean isFlatBodyEnabled();
|
||||
|
||||
/**
|
||||
* Optionally disable the security section for path sections
|
||||
*/
|
||||
boolean isPathSecuritySectionEnabled();
|
||||
|
||||
/**
|
||||
* Optionally prefix all anchors for uniqueness.
|
||||
*/
|
||||
String getAnchorPrefix();
|
||||
|
||||
/**
|
||||
* Overview document name (without extension).
|
||||
*
|
||||
* @return the overview document name (without extension)
|
||||
*/
|
||||
String getOverviewDocument();
|
||||
|
||||
/**
|
||||
* Paths document name (without extension).
|
||||
*
|
||||
* @return the paths document name (without extension)
|
||||
*/
|
||||
String getPathsDocument();
|
||||
|
||||
/**
|
||||
* Definitions document name (without extension).
|
||||
*
|
||||
* @return the definitions document name (without extension)
|
||||
*/
|
||||
String getDefinitionsDocument();
|
||||
|
||||
/**
|
||||
* Security document name (without extension).
|
||||
*
|
||||
* @return the security document name (without extension)
|
||||
*/
|
||||
String getSecurityDocument();
|
||||
|
||||
/**
|
||||
* Separated operations sub-folder name.
|
||||
*
|
||||
* @return the operations sub-folder name
|
||||
*/
|
||||
String getSeparatedOperationsFolder();
|
||||
|
||||
/**
|
||||
* Separated definitions sub-folder name.
|
||||
*
|
||||
* @return the definitions sub-folder name
|
||||
*/
|
||||
String getSeparatedDefinitionsFolder();
|
||||
|
||||
/**
|
||||
* Specifies the line separator which should be used.
|
||||
*
|
||||
* @return the line separator
|
||||
*/
|
||||
LineSeparator getLineSeparator();
|
||||
|
||||
/**
|
||||
* Returns properties for extensions.
|
||||
*
|
||||
* @return the extension properties
|
||||
*/
|
||||
Swagger2MarkupProperties getExtensionsProperties();
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
|
||||
import io.github.swagger2markup.builder.Swagger2MarkupExtensionRegistryBuilder;
|
||||
import io.github.swagger2markup.internal.document.DefinitionsDocument;
|
||||
import io.github.swagger2markup.internal.document.OverviewDocument;
|
||||
import io.github.swagger2markup.internal.document.PathsDocument;
|
||||
import io.github.swagger2markup.internal.document.SecurityDocument;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilders;
|
||||
import io.github.swagger2markup.utils.URIUtils;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class Swagger2MarkupConverter {
|
||||
|
||||
private final Context context;
|
||||
private final OverviewDocument overviewDocument;
|
||||
private final PathsDocument pathsDocument;
|
||||
private final DefinitionsDocument definitionsDocument;
|
||||
private final SecurityDocument securityDocument;
|
||||
|
||||
public Swagger2MarkupConverter(Context context) {
|
||||
this.context = context;
|
||||
this.overviewDocument = new OverviewDocument(context);
|
||||
this.pathsDocument = new PathsDocument(context);
|
||||
this.definitionsDocument = new DefinitionsDocument(context);
|
||||
this.securityDocument = new SecurityDocument(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the global Context
|
||||
*
|
||||
* @return the global Context
|
||||
*/
|
||||
public Context getContext(){
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder from a URI.
|
||||
*
|
||||
* @param swaggerUri the URI
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(URI swaggerUri) {
|
||||
Validate.notNull(swaggerUri, "swaggerUri must not be null");
|
||||
String scheme = swaggerUri.getScheme();
|
||||
if(scheme != null && swaggerUri.getScheme().startsWith("http")){
|
||||
try {
|
||||
return from(swaggerUri.toURL());
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
throw new RuntimeException("Failed to convert URI to URL", e);
|
||||
}
|
||||
} else if(scheme != null && swaggerUri.getScheme().startsWith("file")){
|
||||
return from(Paths.get(swaggerUri));
|
||||
}
|
||||
else {
|
||||
return from(URIUtils.convertUriWithoutSchemeToFileScheme(swaggerUri));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder using a remote URL.
|
||||
*
|
||||
* @param swaggerURL the remote URL
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(URL swaggerURL){
|
||||
Validate.notNull(swaggerURL, "swaggerURL must not be null");
|
||||
return new Builder(swaggerURL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder using a local Path.
|
||||
*
|
||||
* @param swaggerPath the local Path
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(Path swaggerPath) {
|
||||
Validate.notNull(swaggerPath, "swaggerPath must not be null");
|
||||
if(Files.notExists(swaggerPath)){
|
||||
throw new IllegalArgumentException(String.format("swaggerPath does not exist: %s", swaggerPath));
|
||||
}
|
||||
try {
|
||||
if(Files.isHidden(swaggerPath)){
|
||||
throw new IllegalArgumentException("swaggerPath must not be a hidden file");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to check if swaggerPath is a hidden file", e);
|
||||
}
|
||||
return new Builder(swaggerPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder from a given Swagger model.
|
||||
*
|
||||
* @param swagger the Swagger source.
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(Swagger swagger) {
|
||||
Validate.notNull(swagger, "swagger must not be null");
|
||||
return new Builder(swagger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder from a given Swagger YAML or JSON String.
|
||||
*
|
||||
* @param swaggerString the Swagger YAML or JSON String.
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(String swaggerString) {
|
||||
Validate.notEmpty(swaggerString, "swaggerString must not be null");
|
||||
return from(new StringReader(swaggerString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Swagger2MarkupConverter.Builder from a given Swagger YAML or JSON reader.
|
||||
*
|
||||
* @param swaggerReader the Swagger YAML or JSON reader.
|
||||
* @return a Swagger2MarkupConverter
|
||||
*/
|
||||
public static Builder from(Reader swaggerReader) {
|
||||
Validate.notNull(swaggerReader, "swaggerReader must not be null");
|
||||
Swagger swagger;
|
||||
try {
|
||||
swagger = new SwaggerParser().parse(IOUtils.toString(swaggerReader));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Swagger source can not be parsed", e);
|
||||
}
|
||||
if (swagger == null)
|
||||
throw new IllegalArgumentException("Swagger source is in a wrong format");
|
||||
|
||||
return new Builder(swagger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Swagger specification into the given {@code outputDirectory}.
|
||||
*
|
||||
* @param outputDirectory the output directory path
|
||||
*/
|
||||
public void toFolder(Path outputDirectory){
|
||||
Validate.notNull(outputDirectory, "outputDirectory must not be null");
|
||||
|
||||
context.setOutputPath(outputDirectory);
|
||||
|
||||
applyOverviewDocument()
|
||||
.writeToFile(outputDirectory.resolve(context.config.getOverviewDocument()), StandardCharsets.UTF_8);
|
||||
applyPathsDocument()
|
||||
.writeToFile(outputDirectory.resolve(context.config.getPathsDocument()), StandardCharsets.UTF_8);
|
||||
applyDefinitionsDocument()
|
||||
.writeToFile(outputDirectory.resolve(context.config.getDefinitionsDocument()), StandardCharsets.UTF_8);
|
||||
applySecurityDocument()
|
||||
.writeToFile(outputDirectory.resolve(context.config.getSecurityDocument()), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applyOverviewDocument() {
|
||||
return overviewDocument.apply(
|
||||
context.createMarkupDocBuilder(),
|
||||
OverviewDocument.parameters(context.getSwagger()));
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applyPathsDocument() {
|
||||
return pathsDocument.apply(
|
||||
context.createMarkupDocBuilder(),
|
||||
PathsDocument.parameters(context.getSwagger().getPaths()));
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applyDefinitionsDocument() {
|
||||
return definitionsDocument.apply(
|
||||
context.createMarkupDocBuilder(),
|
||||
DefinitionsDocument.parameters(context.getSwagger().getDefinitions()));
|
||||
}
|
||||
|
||||
private MarkupDocBuilder applySecurityDocument() {
|
||||
return securityDocument.apply(
|
||||
context.createMarkupDocBuilder(),
|
||||
SecurityDocument.parameters(context.getSwagger().getSecurityDefinitions()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Swagger specification into the {@code outputPath} which can be either a directory (e.g /tmp) or a file without extension (e.g /tmp/swagger).
|
||||
* Internally the method invokes either {@code toFolder} or {@code toFile}. If the {@code outputPath} is a directory, the directory must exist.
|
||||
* Otherwise it cannot be determined if the {@code outputPath} is a directory or not.
|
||||
*
|
||||
* @param outputPath the output path
|
||||
*/
|
||||
public void toPath(Path outputPath) {
|
||||
Validate.notNull(outputPath, "outputPath must not be null");
|
||||
if (Files.isDirectory(outputPath)) {
|
||||
toFolder(outputPath);
|
||||
} else {
|
||||
toFile(outputPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Swagger specification the given {@code outputFile}.<br>
|
||||
* An extension identifying the markup language will be automatically added to file name.
|
||||
*
|
||||
* @param outputFile the output file
|
||||
*/
|
||||
public void toFile(Path outputFile) {
|
||||
Validate.notNull(outputFile, "outputFile must not be null");
|
||||
|
||||
applyOverviewDocument().writeToFile(outputFile, StandardCharsets.UTF_8);
|
||||
applyPathsDocument().writeToFile(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
applyDefinitionsDocument().writeToFile(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
applySecurityDocument().writeToFile(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Swagger specification the given {@code outputFile}.
|
||||
*
|
||||
* @param outputFile the output file
|
||||
*/
|
||||
public void toFileWithoutExtension(Path outputFile){
|
||||
Validate.notNull(outputFile, "outputFile must not be null");
|
||||
|
||||
applyOverviewDocument().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8);
|
||||
applyPathsDocument().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
applyDefinitionsDocument().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
applySecurityDocument().writeToFileWithoutExtension(outputFile, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the document returns it as a String.
|
||||
*
|
||||
* @return the document as a String
|
||||
*/
|
||||
public String toString() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(applyOverviewDocument() .toString());
|
||||
sb.append(applyPathsDocument().toString());
|
||||
sb.append(applyDefinitionsDocument().toString());
|
||||
sb.append(applySecurityDocument().toString());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final Swagger swagger;
|
||||
private final URI swaggerLocation;
|
||||
private Swagger2MarkupConfig config;
|
||||
private Swagger2MarkupExtensionRegistry extensionRegistry;
|
||||
|
||||
/**
|
||||
* Creates a Builder from a remote URL.
|
||||
*
|
||||
* @param swaggerUrl the remote URL
|
||||
*/
|
||||
Builder(URL swaggerUrl) {
|
||||
try {
|
||||
this.swaggerLocation = swaggerUrl.toURI();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("swaggerURL is in a wrong format", e);
|
||||
}
|
||||
this.swagger = readSwagger(swaggerUrl.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Builder from a local Path.
|
||||
*
|
||||
* @param swaggerPath the local Path
|
||||
*/
|
||||
Builder(Path swaggerPath) {
|
||||
this.swaggerLocation = swaggerPath.toAbsolutePath().toUri();
|
||||
this.swagger = readSwagger(swaggerPath.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Builder using a given Swagger model.
|
||||
*
|
||||
* @param swagger the Swagger source.
|
||||
*/
|
||||
Builder(Swagger swagger) {
|
||||
this.swagger = swagger;
|
||||
this.swaggerLocation = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the SwaggerParser to read the Swagger source.
|
||||
*
|
||||
* @param swaggerLocation the location of the Swagger source
|
||||
* @return the Swagger model
|
||||
*/
|
||||
private Swagger readSwagger(String swaggerLocation){
|
||||
Swagger swagger = new SwaggerParser().read(swaggerLocation);
|
||||
if (swagger == null) {
|
||||
throw new IllegalArgumentException("Failed to read the Swagger source");
|
||||
}
|
||||
return swagger;
|
||||
}
|
||||
|
||||
public Builder withConfig(Swagger2MarkupConfig config) {
|
||||
Validate.notNull(config, "config must not be null");
|
||||
this.config = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withExtensionRegistry(Swagger2MarkupExtensionRegistry registry) {
|
||||
Validate.notNull(registry, "registry must not be null");
|
||||
this.extensionRegistry = registry;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Swagger2MarkupConverter build() {
|
||||
if (config == null)
|
||||
config = new Swagger2MarkupConfigBuilder().build();
|
||||
|
||||
if (extensionRegistry == null)
|
||||
extensionRegistry = new Swagger2MarkupExtensionRegistryBuilder().build();
|
||||
|
||||
Context context = new Context(config, extensionRegistry, swagger, swaggerLocation);
|
||||
|
||||
initExtensions(context);
|
||||
|
||||
applySwaggerExtensions(context);
|
||||
|
||||
return new Swagger2MarkupConverter(context);
|
||||
}
|
||||
|
||||
private void initExtensions(Context context) {
|
||||
extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.setGlobalContext(context));
|
||||
extensionRegistry.getOverviewDocumentExtensions().forEach(extension -> extension.setGlobalContext(context));
|
||||
extensionRegistry.getDefinitionsDocumentExtensions().forEach(extension -> extension.setGlobalContext(context));
|
||||
extensionRegistry.getPathsDocumentExtensions().forEach(extension -> extension.setGlobalContext(context));
|
||||
extensionRegistry.getSecurityDocumentExtensions().forEach(extension -> extension.setGlobalContext(context));
|
||||
}
|
||||
|
||||
private void applySwaggerExtensions(Context context) {
|
||||
extensionRegistry.getSwaggerModelExtensions().forEach(extension -> extension.apply(context.getSwagger()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Context {
|
||||
private final Swagger2MarkupConfig config;
|
||||
private final Swagger swagger;
|
||||
private final URI swaggerLocation;
|
||||
private final Swagger2MarkupExtensionRegistry extensionRegistry;
|
||||
private final Labels labels;
|
||||
private Path outputPath;
|
||||
|
||||
public Context(Swagger2MarkupConfig config,
|
||||
Swagger2MarkupExtensionRegistry extensionRegistry,
|
||||
Swagger swagger,
|
||||
URI swaggerLocation) {
|
||||
this.config = config;
|
||||
this.extensionRegistry = extensionRegistry;
|
||||
this.swagger = swagger;
|
||||
this.swaggerLocation = swaggerLocation;
|
||||
this.labels = new Labels(config);
|
||||
}
|
||||
|
||||
public Swagger2MarkupConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public Swagger getSwagger() {
|
||||
return swagger;
|
||||
}
|
||||
|
||||
public URI getSwaggerLocation() {
|
||||
return swaggerLocation;
|
||||
}
|
||||
|
||||
public Swagger2MarkupExtensionRegistry getExtensionRegistry() {
|
||||
return extensionRegistry;
|
||||
}
|
||||
|
||||
public Labels getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public MarkupDocBuilder createMarkupDocBuilder(){
|
||||
return MarkupDocBuilders.documentBuilder(config.getMarkupLanguage(),
|
||||
config.getLineSeparator()).withAnchorPrefix(config.getAnchorPrefix());
|
||||
}
|
||||
|
||||
public Path getOutputPath() {
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
public void setOutputPath(Path outputPath) {
|
||||
this.outputPath = outputPath;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
import io.github.swagger2markup.spi.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Extension points registry interface.
|
||||
*/
|
||||
public interface Swagger2MarkupExtensionRegistry {
|
||||
/**
|
||||
* SwaggerModelExtension extension point can be used to preprocess the Swagger model.
|
||||
* @return registered extensions extending SwaggerModelExtension extension point
|
||||
*/
|
||||
List<SwaggerModelExtension> getSwaggerModelExtensions();
|
||||
|
||||
/**
|
||||
* OverviewDocumentExtension extension point can be used to extend the overview document content.
|
||||
* @return registered extensions extending OverviewDocumentExtension extension point
|
||||
*/
|
||||
List<OverviewDocumentExtension> getOverviewDocumentExtensions();
|
||||
|
||||
/**
|
||||
* DefinitionsDocumentExtension extension point can be used to extend the definitions document content.
|
||||
* @return registered extensions extending DefinitionsDocumentExtension extension point
|
||||
*/
|
||||
List<DefinitionsDocumentExtension> getDefinitionsDocumentExtensions();
|
||||
|
||||
/**
|
||||
* SecurityContentExtension extension point can be used to extend the security document content.
|
||||
* @return registered extensions extending SecurityContentExtension extension point
|
||||
*/
|
||||
List<SecurityDocumentExtension> getSecurityDocumentExtensions();
|
||||
|
||||
/**
|
||||
* PathsDocumentExtension extension point can be used to extend the paths document content.
|
||||
* @return registered extensions extending PathsDocumentExtension extension point
|
||||
*/
|
||||
List<PathsDocumentExtension> getPathsDocumentExtensions();
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.utils.URIUtils;
|
||||
import org.apache.commons.collections4.IteratorUtils;
|
||||
import org.apache.commons.configuration2.Configuration;
|
||||
import org.apache.commons.configuration2.ConfigurationConverter;
|
||||
import org.apache.commons.configuration2.MapConfiguration;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Swagger2MarkupProperties {
|
||||
|
||||
/**
|
||||
* Prefix for Swagger2Markup properties
|
||||
*/
|
||||
public static final String PROPERTIES_PREFIX = "swagger2markup";
|
||||
|
||||
public static final String MARKUP_LANGUAGE = PROPERTIES_PREFIX + ".markupLanguage";
|
||||
public static final String SWAGGER_MARKUP_LANGUAGE = PROPERTIES_PREFIX + ".swaggerMarkupLanguage";
|
||||
public static final String GENERATED_EXAMPLES_ENABLED = PROPERTIES_PREFIX + ".generatedExamplesEnabled";
|
||||
public static final String BASE_PATH_PREFIX_ENABLED = PROPERTIES_PREFIX + ".basePathPrefixEnabled";
|
||||
public static final String SEPARATED_DEFINITIONS_ENABLED = PROPERTIES_PREFIX + ".separatedDefinitionsEnabled";
|
||||
public static final String SEPARATED_OPERATIONS_ENABLED = PROPERTIES_PREFIX + ".separatedOperationsEnabled";
|
||||
public static final String PATHS_GROUPED_BY = PROPERTIES_PREFIX + ".pathsGroupedBy";
|
||||
public static final String OUTPUT_LANGUAGE = PROPERTIES_PREFIX + ".outputLanguage";
|
||||
public static final String INLINE_SCHEMA_ENABLED = PROPERTIES_PREFIX + ".inlineSchemaEnabled";
|
||||
public static final String INTER_DOCUMENT_CROSS_REFERENCES_ENABLED = PROPERTIES_PREFIX + ".interDocumentCrossReferencesEnabled";
|
||||
public static final String INTER_DOCUMENT_CROSS_REFERENCES_PREFIX = PROPERTIES_PREFIX + ".interDocumentCrossReferencesPrefix";
|
||||
public static final String FLAT_BODY_ENABLED = PROPERTIES_PREFIX + ".flatBodyEnabled";
|
||||
public static final String PATH_SECURITY_SECTION_ENABLED = PROPERTIES_PREFIX + ".pathSecuritySectionEnabled";
|
||||
public static final String ANCHOR_PREFIX = PROPERTIES_PREFIX + ".anchorPrefix";
|
||||
public static final String OVERVIEW_DOCUMENT = PROPERTIES_PREFIX + ".overviewDocument";
|
||||
public static final String PATHS_DOCUMENT = PROPERTIES_PREFIX + ".pathsDocument";
|
||||
public static final String DEFINITIONS_DOCUMENT = PROPERTIES_PREFIX + ".definitionsDocument";
|
||||
public static final String SECURITY_DOCUMENT = PROPERTIES_PREFIX + ".securityDocument";
|
||||
public static final String SEPARATED_OPERATIONS_FOLDER = PROPERTIES_PREFIX + ".separatedOperationsFolder";
|
||||
public static final String SEPARATED_DEFINITIONS_FOLDER = PROPERTIES_PREFIX + ".separatedDefinitionsFolder";
|
||||
public static final String TAG_ORDER_BY = PROPERTIES_PREFIX + ".tagOrderBy";
|
||||
public static final String OPERATION_ORDER_BY = PROPERTIES_PREFIX + ".operationOrderBy";
|
||||
public static final String DEFINITION_ORDER_BY = PROPERTIES_PREFIX + ".definitionOrderBy";
|
||||
public static final String PARAMETER_ORDER_BY = PROPERTIES_PREFIX + ".parameterOrderBy";
|
||||
public static final String PROPERTY_ORDER_BY = PROPERTIES_PREFIX + ".propertyOrderBy";
|
||||
public static final String RESPONSE_ORDER_BY = PROPERTIES_PREFIX + ".responseOrderBy";
|
||||
public static final String LINE_SEPARATOR = PROPERTIES_PREFIX + ".lineSeparator";
|
||||
|
||||
/**
|
||||
* Prefix for Swagger2Markup extension properties
|
||||
*/
|
||||
public static final String EXTENSION_PREFIX = "extensions";
|
||||
|
||||
private final Configuration configuration;
|
||||
|
||||
public Swagger2MarkupProperties(Properties properties) {
|
||||
this(ConfigurationConverter.getConfiguration(properties));
|
||||
}
|
||||
|
||||
public Swagger2MarkupProperties(Map<String, String> map) {
|
||||
this(new MapConfiguration(map));
|
||||
}
|
||||
|
||||
public Swagger2MarkupProperties(Configuration configuration){
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an optional String property value associated with the given key.
|
||||
* @param key the property name to resolve
|
||||
*
|
||||
* @return The string property
|
||||
*/
|
||||
public Optional<String> getString(String key){
|
||||
return Optional.ofNullable(configuration.getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
* @param key the property name to resolve
|
||||
* @param defaultValue the default value to return if no value is found
|
||||
*
|
||||
* @return The string property
|
||||
*/
|
||||
public String getString(String key, String defaultValue){
|
||||
return configuration.getString(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the int property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
* @param key the property name to resolve
|
||||
* @param defaultValue the default value to return if no value is found
|
||||
*
|
||||
* @return The int property
|
||||
*/
|
||||
public int getInt(String key, int defaultValue){
|
||||
return configuration.getInt(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an optional Integer property value associated with the given key.
|
||||
* @param key the property name to resolve
|
||||
*
|
||||
* @return An optional Integer property
|
||||
*/
|
||||
public Optional<Integer> getInteger(String key){
|
||||
return Optional.ofNullable(configuration.getInteger(key, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the int property value associated with the given key (never {@code null}).
|
||||
* @throws IllegalStateException if the key cannot be
|
||||
*
|
||||
* @return The int property
|
||||
*/
|
||||
public int getRequiredInt(String key){
|
||||
Optional<Integer> value = getInteger(key);
|
||||
if(value.isPresent()){
|
||||
return value.get();
|
||||
}
|
||||
throw new IllegalStateException(String.format("required key [%s] not found", key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the boolean property value associated with the given key (never {@code null}).
|
||||
* @throws IllegalStateException if the key cannot be resolved
|
||||
*
|
||||
* @return The boolean property
|
||||
*/
|
||||
public boolean getRequiredBoolean(String key){
|
||||
Boolean value = configuration.getBoolean(key, null);
|
||||
if(value != null){
|
||||
return value;
|
||||
}else{
|
||||
throw new IllegalStateException(String.format("required key [%s] not found", key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the boolean property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
* @param key the property name to resolve
|
||||
* @param defaultValue the default value to return if no value is found
|
||||
*
|
||||
* @return The boolean property
|
||||
*/
|
||||
public boolean getBoolean(String key, boolean defaultValue){
|
||||
return configuration.getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the URI property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
* @param key the property name to resolve
|
||||
* @throws IllegalStateException if the value cannot be mapped to the enum
|
||||
*
|
||||
* @return The URI property
|
||||
*/
|
||||
public Optional<URI> getURI(String key){
|
||||
Optional<String> property = getString(key);
|
||||
if(property.isPresent()){
|
||||
return Optional.of(URIUtils.create(property.get()));
|
||||
}else{
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the URI property value associated with the given key (never {@code null}).
|
||||
* @throws IllegalStateException if the key cannot be resolved
|
||||
*
|
||||
* @return The URI property
|
||||
*/
|
||||
public URI getRequiredURI(String key){
|
||||
Optional<String> property = getString(key);
|
||||
if(property.isPresent()){
|
||||
return URIUtils.create(property.get());
|
||||
}else{
|
||||
throw new IllegalStateException(String.format("required key [%s] not found", key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Path property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
* @param key the property name to resolve
|
||||
* @throws IllegalStateException if the value cannot be mapped to the enum
|
||||
*
|
||||
* @return The Path property
|
||||
*/
|
||||
public Optional<Path> getPath(String key){
|
||||
Optional<String> property = getString(key);
|
||||
if(property.isPresent()){
|
||||
return Optional.of(Paths.get(property.get()));
|
||||
}else{
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Path property value associated with the given key (never {@code null}).
|
||||
* @throws IllegalStateException if the key cannot be resolved
|
||||
*
|
||||
* @return The Path property
|
||||
*/
|
||||
public Path getRequiredPath(String key){
|
||||
Optional<String> property = getString(key);
|
||||
if(property.isPresent()){
|
||||
return Paths.get(property.get());
|
||||
}else{
|
||||
throw new IllegalStateException(String.format("required key [%s] not found", key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MarkupLanguage property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
* @param key the property name to resolve
|
||||
*
|
||||
* @return The MarkupLanguage property
|
||||
*/
|
||||
public Optional<MarkupLanguage> getMarkupLanguage(String key){
|
||||
Optional<String> property = getString(key);
|
||||
if(property.isPresent()){
|
||||
return Optional.of(MarkupLanguage.valueOf(property.get()));
|
||||
}else{
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MarkupLanguage property value associated with the given key (never {@code null}).
|
||||
* @throws IllegalStateException if the key cannot be resolved
|
||||
*
|
||||
* @return The MarkupLanguage property
|
||||
*/
|
||||
public MarkupLanguage getRequiredMarkupLanguage(String key){
|
||||
return MarkupLanguage.valueOf(configuration.getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Language property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
* @param key the property name to resolve
|
||||
*
|
||||
* @return The Language property
|
||||
*/
|
||||
public Language getLanguage(String key){
|
||||
return Language.valueOf(configuration.getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the GroupBy property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
* @param key the property name to resolve
|
||||
* @throws IllegalStateException if the value cannot be mapped to the enum
|
||||
*
|
||||
* @return The GroupBy property
|
||||
*/
|
||||
public GroupBy getGroupBy(String key){
|
||||
return GroupBy.valueOf(configuration.getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the OrderBy property value associated with the given key, or
|
||||
* {@code defaultValue} if the key cannot be resolved.
|
||||
* @param key the property name to resolve
|
||||
* @throws IllegalStateException if the value cannot be mapped to the enum
|
||||
*
|
||||
* @return The OrderBy property
|
||||
*/
|
||||
public OrderBy getOrderBy(String key){
|
||||
return OrderBy.valueOf(configuration.getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String property value associated with the given key (never {@code null}).
|
||||
* @throws IllegalStateException if the key cannot be resolved
|
||||
*
|
||||
* @return The String property
|
||||
*/
|
||||
public String getRequiredString(String key) throws IllegalStateException{
|
||||
Optional<String> property = getString(key);
|
||||
if(property.isPresent()){
|
||||
return property.get();
|
||||
}else{
|
||||
throw new IllegalStateException(String.format("required key [%s] not found", key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of keys.
|
||||
*
|
||||
* @return the list of keys.
|
||||
*/
|
||||
public List<String> getKeys(){
|
||||
return IteratorUtils.toList(configuration.getKeys());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of the keys contained in the configuration that match the
|
||||
* specified prefix. For instance, if the configuration contains the
|
||||
* following keys:<br>
|
||||
* {@code swagger2markup.extensions.folder1, swagger2markup.extensions.folder2, swagger2markup.folder3},<br>
|
||||
* an invocation of {@code getKeys("swagger2markup.extensions");}<br>
|
||||
* will return the key below:<br>
|
||||
* {@code swagger2markup.extensions.folder1, swagger2markup.extensions.folder2}.<br>
|
||||
* Note that the prefix itself is included in the result set if there is a
|
||||
* matching key. The exact behavior - how the prefix is actually
|
||||
* interpreted - depends on a concrete implementation.
|
||||
*
|
||||
* @param prefix The prefix to test against.
|
||||
*
|
||||
* @return the list of keys.
|
||||
*/
|
||||
public List<String> getKeys(String prefix){
|
||||
return IteratorUtils.toList(configuration.getKeys(prefix));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,707 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.builder;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import io.github.swagger2markup.*;
|
||||
import io.github.swagger2markup.markup.builder.LineSeparator;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.swagger.models.HttpMethod;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import org.apache.commons.configuration2.*;
|
||||
import org.apache.commons.configuration2.builder.fluent.Configurations;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
import static io.github.swagger2markup.Swagger2MarkupProperties.*;
|
||||
|
||||
public class Swagger2MarkupConfigBuilder {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Swagger2MarkupConfigBuilder.class);
|
||||
|
||||
private static final String PROPERTIES_DEFAULT = "io/github/swagger2markup/config/default.properties";
|
||||
|
||||
static final Ordering<PathOperation> OPERATION_METHOD_NATURAL_ORDERING = Ordering
|
||||
.explicit(HttpMethod.POST, HttpMethod.GET, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.PATCH, HttpMethod.HEAD, HttpMethod.OPTIONS)
|
||||
.onResultOf(PathOperation::getMethod);
|
||||
|
||||
static final Ordering<PathOperation> OPERATION_PATH_NATURAL_ORDERING = Ordering
|
||||
.natural()
|
||||
.onResultOf(PathOperation::getPath);
|
||||
|
||||
static final Ordering<Parameter> PARAMETER_IN_NATURAL_ORDERING = Ordering
|
||||
.explicit("header", "path", "query", "formData", "body")
|
||||
.onResultOf(Parameter::getIn);
|
||||
|
||||
static final Ordering<Parameter> PARAMETER_NAME_NATURAL_ORDERING = Ordering
|
||||
.natural()
|
||||
.onResultOf(Parameter::getName);
|
||||
|
||||
DefaultSwagger2MarkupConfig config = new DefaultSwagger2MarkupConfig();
|
||||
|
||||
public Swagger2MarkupConfigBuilder() {
|
||||
this(new PropertiesConfiguration());
|
||||
}
|
||||
|
||||
public Swagger2MarkupConfigBuilder(Properties properties) {
|
||||
this(ConfigurationConverter.getConfiguration(properties));
|
||||
}
|
||||
|
||||
public Swagger2MarkupConfigBuilder(Map<String, String> map) {
|
||||
this(new MapConfiguration(map));
|
||||
}
|
||||
|
||||
public Swagger2MarkupConfigBuilder(Configuration configuration) {
|
||||
CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
|
||||
compositeConfiguration.addConfiguration(new SystemConfiguration());
|
||||
compositeConfiguration.addConfiguration(configuration);
|
||||
compositeConfiguration.addConfiguration(getDefaultConfiguration());
|
||||
|
||||
Swagger2MarkupProperties swagger2MarkupProperties = new Swagger2MarkupProperties(compositeConfiguration);
|
||||
|
||||
config.markupLanguage = swagger2MarkupProperties.getRequiredMarkupLanguage(MARKUP_LANGUAGE);
|
||||
config.swaggerMarkupLanguage = swagger2MarkupProperties.getRequiredMarkupLanguage(SWAGGER_MARKUP_LANGUAGE);
|
||||
config.generatedExamplesEnabled = swagger2MarkupProperties.getRequiredBoolean(GENERATED_EXAMPLES_ENABLED);
|
||||
config.basePathPrefixEnabled = swagger2MarkupProperties.getRequiredBoolean(BASE_PATH_PREFIX_ENABLED);
|
||||
config.separatedDefinitionsEnabled = swagger2MarkupProperties.getRequiredBoolean(SEPARATED_DEFINITIONS_ENABLED);
|
||||
config.separatedOperationsEnabled = swagger2MarkupProperties.getRequiredBoolean(SEPARATED_OPERATIONS_ENABLED);
|
||||
config.pathsGroupedBy = swagger2MarkupProperties.getGroupBy(PATHS_GROUPED_BY);
|
||||
config.outputLanguage = swagger2MarkupProperties.getLanguage(OUTPUT_LANGUAGE);
|
||||
config.inlineSchemaEnabled = swagger2MarkupProperties.getRequiredBoolean(INLINE_SCHEMA_ENABLED);
|
||||
config.interDocumentCrossReferencesEnabled = swagger2MarkupProperties.getRequiredBoolean(INTER_DOCUMENT_CROSS_REFERENCES_ENABLED);
|
||||
config.interDocumentCrossReferencesPrefix = swagger2MarkupProperties.getString(INTER_DOCUMENT_CROSS_REFERENCES_PREFIX, null);
|
||||
config.flatBodyEnabled = swagger2MarkupProperties.getRequiredBoolean(FLAT_BODY_ENABLED);
|
||||
config.pathSecuritySectionEnabled = swagger2MarkupProperties.getRequiredBoolean(PATH_SECURITY_SECTION_ENABLED);
|
||||
config.anchorPrefix = swagger2MarkupProperties.getString(ANCHOR_PREFIX, null);
|
||||
config.overviewDocument = swagger2MarkupProperties.getRequiredString(OVERVIEW_DOCUMENT);
|
||||
config.pathsDocument = swagger2MarkupProperties.getRequiredString(PATHS_DOCUMENT);
|
||||
config.definitionsDocument = swagger2MarkupProperties.getRequiredString(DEFINITIONS_DOCUMENT);
|
||||
config.securityDocument = swagger2MarkupProperties.getRequiredString(SECURITY_DOCUMENT);
|
||||
config.separatedOperationsFolder = swagger2MarkupProperties.getRequiredString(SEPARATED_OPERATIONS_FOLDER);
|
||||
config.separatedDefinitionsFolder = swagger2MarkupProperties.getRequiredString(SEPARATED_DEFINITIONS_FOLDER);
|
||||
config.tagOrderBy = swagger2MarkupProperties.getOrderBy(TAG_ORDER_BY);
|
||||
config.operationOrderBy = swagger2MarkupProperties.getOrderBy(OPERATION_ORDER_BY);
|
||||
config.definitionOrderBy = swagger2MarkupProperties.getOrderBy(DEFINITION_ORDER_BY);
|
||||
config.parameterOrderBy = swagger2MarkupProperties.getOrderBy(PARAMETER_ORDER_BY);
|
||||
config.propertyOrderBy = swagger2MarkupProperties.getOrderBy(PROPERTY_ORDER_BY);
|
||||
config.responseOrderBy = swagger2MarkupProperties.getOrderBy(RESPONSE_ORDER_BY);
|
||||
Optional<String> lineSeparator = swagger2MarkupProperties.getString(LINE_SEPARATOR);
|
||||
if(lineSeparator.isPresent() && StringUtils.isNoneBlank(lineSeparator.get())){
|
||||
config.lineSeparator = LineSeparator.valueOf(lineSeparator.get());
|
||||
}
|
||||
|
||||
Configuration swagger2markupConfiguration = compositeConfiguration.subset(PROPERTIES_PREFIX);
|
||||
Configuration extensionsConfiguration = swagger2markupConfiguration.subset(EXTENSION_PREFIX);
|
||||
config.extensionsProperties = new Swagger2MarkupProperties(extensionsConfiguration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the default properties from the classpath.
|
||||
*
|
||||
* @return the default properties
|
||||
*/
|
||||
private Configuration getDefaultConfiguration() {
|
||||
Configurations configs = new Configurations();
|
||||
try {
|
||||
return configs.properties(PROPERTIES_DEFAULT);
|
||||
} catch (ConfigurationException e) {
|
||||
throw new RuntimeException(String.format("Can't load default properties '%s'", PROPERTIES_DEFAULT), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Swagger2MarkupConfig.
|
||||
*
|
||||
* @return the Swagger2MarkupConfig
|
||||
*/
|
||||
public Swagger2MarkupConfig build() {
|
||||
buildNaturalOrdering();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
private void buildNaturalOrdering() {
|
||||
if (config.tagOrderBy == OrderBy.NATURAL)
|
||||
config.tagOrdering = Ordering.natural();
|
||||
if (config.operationOrderBy == OrderBy.NATURAL)
|
||||
config.operationOrdering = OPERATION_PATH_NATURAL_ORDERING.compound(OPERATION_METHOD_NATURAL_ORDERING);
|
||||
if (config.definitionOrderBy == OrderBy.NATURAL)
|
||||
config.definitionOrdering = Ordering.natural();
|
||||
if (config.parameterOrderBy == OrderBy.NATURAL)
|
||||
config.parameterOrdering = PARAMETER_IN_NATURAL_ORDERING.compound(PARAMETER_NAME_NATURAL_ORDERING);
|
||||
if (config.propertyOrderBy == OrderBy.NATURAL)
|
||||
config.propertyOrdering = Ordering.natural();
|
||||
if (config.responseOrderBy == OrderBy.NATURAL)
|
||||
config.responseOrdering = Ordering.natural();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the markup language which should be used to generate the files.
|
||||
*
|
||||
* @param markupLanguage the markup language which is used to generate the files
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withMarkupLanguage(MarkupLanguage markupLanguage) {
|
||||
Validate.notNull(markupLanguage, "%s must not be null", "markupLanguage");
|
||||
config.markupLanguage = markupLanguage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the markup language used in Swagger descriptions.
|
||||
*
|
||||
* @param swaggerMarkupLanguage the markup language used in Swagger descriptions
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withSwaggerMarkupLanguage(MarkupLanguage swaggerMarkupLanguage) {
|
||||
Validate.notNull(swaggerMarkupLanguage, "%s must not be null", "swaggerMarkupLanguage");
|
||||
config.swaggerMarkupLanguage = swaggerMarkupLanguage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include generated examples into the documents.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withGeneratedExamples() {
|
||||
config.generatedExamplesEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* In addition to the Definitions file, also create separate definition files for each model definition.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withSeparatedDefinitions() {
|
||||
config.separatedDefinitionsEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* In addition to the Paths file, also create separate operation files for each operation.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withSeparatedOperations() {
|
||||
config.separatedOperationsEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specifies if the paths should be grouped by tags or stay as-is.
|
||||
*
|
||||
* @param pathsGroupedBy the GroupBy enum
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withPathsGroupedBy(GroupBy pathsGroupedBy) {
|
||||
Validate.notNull(pathsGroupedBy, "%s must not be null", "pathsGroupedBy");
|
||||
config.pathsGroupedBy = pathsGroupedBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies labels language of output files.
|
||||
*
|
||||
* @param language the enum
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withOutputLanguage(Language language) {
|
||||
Validate.notNull(language, "%s must not be null", "language");
|
||||
config.outputLanguage = language;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable inline schema support.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withoutInlineSchema() {
|
||||
config.inlineSchemaEnabled = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies tag ordering.<br>
|
||||
* By default tag ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
|
||||
* Use {@link #withTagOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy tag ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withTagOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.tagOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order tags.
|
||||
*
|
||||
* @param tagOrdering tag ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withTagOrdering(Comparator<String> tagOrdering) {
|
||||
Validate.notNull(tagOrdering, "%s must not be null", "tagOrdering");
|
||||
config.tagOrderBy = OrderBy.CUSTOM;
|
||||
config.tagOrdering = tagOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies operation ordering.<br>
|
||||
* By default operation ordering == {@link io.github.swagger2markup.OrderBy#AS_IS}.<br>
|
||||
* Use {@link #withOperationOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy operation ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withOperationOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.operationOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order operations.
|
||||
*
|
||||
* @param operationOrdering operation ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withOperationOrdering(Comparator<PathOperation> operationOrdering) {
|
||||
Validate.notNull(operationOrdering, "%s must not be null", "operationOrdering");
|
||||
config.operationOrderBy = OrderBy.CUSTOM;
|
||||
config.operationOrdering = operationOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies definition ordering.<br>
|
||||
* By default definition ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
|
||||
* Use {@link #withDefinitionOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy definition ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withDefinitionOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.definitionOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order definitions.
|
||||
*
|
||||
* @param definitionOrdering definition ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withDefinitionOrdering(Comparator<String> definitionOrdering) {
|
||||
Validate.notNull(definitionOrdering, "%s must not be null", "definitionOrdering");
|
||||
config.definitionOrderBy = OrderBy.CUSTOM;
|
||||
config.definitionOrdering = definitionOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies parameter ordering.<br>
|
||||
* By default parameter ordering == {@link OrderBy#NATURAL}.<br>
|
||||
* Use {@link #withParameterOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy parameter ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withParameterOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.parameterOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order parameters.
|
||||
*
|
||||
* @param parameterOrdering parameter ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withParameterOrdering(Comparator<Parameter> parameterOrdering) {
|
||||
Validate.notNull(parameterOrdering, "%s must not be null", "parameterOrdering");
|
||||
|
||||
config.parameterOrderBy = OrderBy.CUSTOM;
|
||||
config.parameterOrdering = parameterOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies property ordering.<br>
|
||||
* By default property ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
|
||||
* Use {@link #withPropertyOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy property ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withPropertyOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.propertyOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order properties.
|
||||
*
|
||||
* @param propertyOrdering property ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withPropertyOrdering(Comparator<String> propertyOrdering) {
|
||||
Validate.notNull(propertyOrdering, "%s must not be null", "propertyOrdering");
|
||||
|
||||
config.propertyOrderBy = OrderBy.CUSTOM;
|
||||
config.propertyOrdering = propertyOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies response ordering.<br>
|
||||
* By default response ordering == {@link io.github.swagger2markup.OrderBy#NATURAL}.<br>
|
||||
* Use {@link #withResponseOrdering(Comparator)} to set a custom ordering.
|
||||
*
|
||||
* @param orderBy response ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withResponseOrdering(OrderBy orderBy) {
|
||||
Validate.notNull(orderBy, "%s must not be null", "orderBy");
|
||||
Validate.isTrue(orderBy != OrderBy.CUSTOM, "You must provide a custom comparator if orderBy == OrderBy.CUSTOM");
|
||||
config.responseOrderBy = orderBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a custom comparator function to order responses.
|
||||
*
|
||||
* @param responseOrdering response ordering
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withResponseOrdering(Comparator<String> responseOrdering) {
|
||||
Validate.notNull(responseOrdering, "%s must not be null", "responseOrdering");
|
||||
|
||||
config.responseOrderBy = OrderBy.CUSTOM;
|
||||
config.responseOrdering = responseOrdering;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable use of inter-document cross-references when needed.
|
||||
*
|
||||
* @param prefix Prefix to document in all inter-document cross-references.
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withInterDocumentCrossReferences(String prefix) {
|
||||
Validate.notNull(prefix, "%s must not be null", "prefix");
|
||||
config.interDocumentCrossReferencesEnabled = true;
|
||||
config.interDocumentCrossReferencesPrefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable use of inter-document cross-references when needed.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withInterDocumentCrossReferences() {
|
||||
config.interDocumentCrossReferencesEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally isolate the body parameter, if any, from other parameters.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withFlatBody() {
|
||||
config.flatBodyEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally disable the security section for path sections
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withoutPathSecuritySection() {
|
||||
config.pathSecuritySectionEnabled = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend the base path to all paths.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withBasePathPrefix() {
|
||||
config.basePathPrefixEnabled = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally prefix all anchors for uniqueness.
|
||||
*
|
||||
* @param anchorPrefix anchor prefix.
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withAnchorPrefix(String anchorPrefix) {
|
||||
Validate.notNull(anchorPrefix, "%s must no be null", "anchorPrefix");
|
||||
config.anchorPrefix = anchorPrefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the line separator which should be used.
|
||||
*
|
||||
* @param lineSeparator the lineSeparator
|
||||
* @return this builder
|
||||
*/
|
||||
public Swagger2MarkupConfigBuilder withLineSeparator(LineSeparator lineSeparator) {
|
||||
Validate.notNull(lineSeparator, "%s must no be null", "lineSeparator");
|
||||
config.lineSeparator = lineSeparator;
|
||||
return this;
|
||||
}
|
||||
|
||||
static class DefaultSwagger2MarkupConfig implements Swagger2MarkupConfig{
|
||||
|
||||
private MarkupLanguage markupLanguage;
|
||||
private MarkupLanguage swaggerMarkupLanguage;
|
||||
private boolean generatedExamplesEnabled;
|
||||
private boolean basePathPrefixEnabled;
|
||||
private boolean separatedDefinitionsEnabled;
|
||||
private boolean separatedOperationsEnabled;
|
||||
private GroupBy pathsGroupedBy;
|
||||
private Language outputLanguage;
|
||||
private boolean inlineSchemaEnabled;
|
||||
private OrderBy tagOrderBy;
|
||||
private Comparator<String> tagOrdering;
|
||||
private OrderBy operationOrderBy;
|
||||
private Comparator<PathOperation> operationOrdering;
|
||||
private OrderBy definitionOrderBy;
|
||||
private Comparator<String> definitionOrdering;
|
||||
private OrderBy parameterOrderBy;
|
||||
private Comparator<Parameter> parameterOrdering;
|
||||
private OrderBy propertyOrderBy;
|
||||
private Comparator<String> propertyOrdering;
|
||||
private OrderBy responseOrderBy;
|
||||
private Comparator<String> responseOrdering;
|
||||
private boolean interDocumentCrossReferencesEnabled;
|
||||
private String interDocumentCrossReferencesPrefix;
|
||||
private boolean flatBodyEnabled;
|
||||
private boolean pathSecuritySectionEnabled;
|
||||
private String anchorPrefix;
|
||||
private LineSeparator lineSeparator;
|
||||
|
||||
private String overviewDocument;
|
||||
private String pathsDocument;
|
||||
private String definitionsDocument;
|
||||
private String securityDocument;
|
||||
private String separatedOperationsFolder;
|
||||
private String separatedDefinitionsFolder;
|
||||
|
||||
private Swagger2MarkupProperties extensionsProperties;
|
||||
|
||||
@Override
|
||||
public MarkupLanguage getMarkupLanguage() {
|
||||
return markupLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupLanguage getSwaggerMarkupLanguage() {
|
||||
return swaggerMarkupLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGeneratedExamplesEnabled() {
|
||||
return generatedExamplesEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSeparatedDefinitionsEnabled() {
|
||||
return separatedDefinitionsEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSeparatedOperationsEnabled() {
|
||||
return separatedOperationsEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupBy getPathsGroupedBy() {
|
||||
return pathsGroupedBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Language getOutputLanguage() {
|
||||
return outputLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInlineSchemaEnabled() {
|
||||
return inlineSchemaEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getTagOrderBy() {
|
||||
return tagOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<String> getTagOrdering() {
|
||||
return tagOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getOperationOrderBy() {
|
||||
return operationOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<PathOperation> getOperationOrdering() {
|
||||
return operationOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getDefinitionOrderBy() {
|
||||
return definitionOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<String> getDefinitionOrdering() {
|
||||
return definitionOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getParameterOrderBy() {
|
||||
return parameterOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<Parameter> getParameterOrdering() {
|
||||
return parameterOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getPropertyOrderBy() {
|
||||
return propertyOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<String> getPropertyOrdering() {
|
||||
return propertyOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy getResponseOrderBy() {
|
||||
return responseOrderBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<String> getResponseOrdering() {
|
||||
return responseOrdering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInterDocumentCrossReferencesEnabled() {
|
||||
return interDocumentCrossReferencesEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInterDocumentCrossReferencesPrefix() {
|
||||
return interDocumentCrossReferencesPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlatBodyEnabled() {
|
||||
return flatBodyEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPathSecuritySectionEnabled() {
|
||||
return pathSecuritySectionEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAnchorPrefix() {
|
||||
return anchorPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOverviewDocument() {
|
||||
return overviewDocument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPathsDocument() {
|
||||
return pathsDocument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefinitionsDocument() {
|
||||
return definitionsDocument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSecurityDocument() {
|
||||
return securityDocument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSeparatedOperationsFolder() {
|
||||
return separatedOperationsFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSeparatedDefinitionsFolder() {
|
||||
return separatedDefinitionsFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LineSeparator getLineSeparator() {
|
||||
return lineSeparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Swagger2MarkupProperties getExtensionsProperties() {
|
||||
return extensionsProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBasePathPrefixEnabled() {
|
||||
return basePathPrefixEnabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.swagger2markup.builder;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupExtensionRegistry;
|
||||
import io.github.swagger2markup.spi.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.ServiceLoader.load;
|
||||
import static org.apache.commons.collections4.IteratorUtils.toList;
|
||||
|
||||
public class Swagger2MarkupExtensionRegistryBuilder {
|
||||
|
||||
private final Context context;
|
||||
|
||||
public Swagger2MarkupExtensionRegistryBuilder() {
|
||||
List<SwaggerModelExtension> swaggerModelExtensions = toList(load(SwaggerModelExtension.class).iterator());
|
||||
List<OverviewDocumentExtension> overviewDocumentExtensions = toList(load(OverviewDocumentExtension.class).iterator());
|
||||
List<DefinitionsDocumentExtension> definitionsDocumentExtensions = toList(load(DefinitionsDocumentExtension.class).iterator());
|
||||
List<PathsDocumentExtension> pathsDocumentExtensions = toList(load(PathsDocumentExtension.class).iterator());
|
||||
List<SecurityDocumentExtension> securityDocumentExtensions = toList(load(SecurityDocumentExtension.class).iterator());
|
||||
context = new Context(
|
||||
swaggerModelExtensions,
|
||||
overviewDocumentExtensions,
|
||||
definitionsDocumentExtensions,
|
||||
pathsDocumentExtensions,
|
||||
securityDocumentExtensions);
|
||||
}
|
||||
|
||||
public Swagger2MarkupExtensionRegistry build() {
|
||||
return new DefaultSwagger2MarkupExtensionRegistry(context);
|
||||
}
|
||||
|
||||
public Swagger2MarkupExtensionRegistryBuilder withSwaggerModelExtension(SwaggerModelExtension extension) {
|
||||
context.swaggerModelExtensions.add(extension);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Swagger2MarkupExtensionRegistryBuilder withOverviewDocumentExtension(OverviewDocumentExtension extension) {
|
||||
context.overviewDocumentExtensions.add(extension);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Swagger2MarkupExtensionRegistryBuilder withDefinitionsDocumentExtension(DefinitionsDocumentExtension extension) {
|
||||
context.definitionsDocumentExtensions.add(extension);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Swagger2MarkupExtensionRegistryBuilder withPathsDocumentExtension(PathsDocumentExtension extension) {
|
||||
context.pathsDocumentExtensions.add(extension);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Swagger2MarkupExtensionRegistryBuilder withSecurityDocumentExtension(SecurityDocumentExtension extension) {
|
||||
context.securityDocumentExtensions.add(extension);
|
||||
return this;
|
||||
}
|
||||
|
||||
static class DefaultSwagger2MarkupExtensionRegistry implements Swagger2MarkupExtensionRegistry{
|
||||
|
||||
private Context context;
|
||||
|
||||
DefaultSwagger2MarkupExtensionRegistry(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwaggerModelExtension> getSwaggerModelExtensions(){
|
||||
return context.swaggerModelExtensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OverviewDocumentExtension> getOverviewDocumentExtensions(){
|
||||
return context.overviewDocumentExtensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DefinitionsDocumentExtension> getDefinitionsDocumentExtensions(){
|
||||
return context.definitionsDocumentExtensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SecurityDocumentExtension> getSecurityDocumentExtensions(){
|
||||
return context.securityDocumentExtensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PathsDocumentExtension> getPathsDocumentExtensions(){
|
||||
return context.pathsDocumentExtensions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Context {
|
||||
public final List<SwaggerModelExtension> swaggerModelExtensions;
|
||||
public final List<OverviewDocumentExtension> overviewDocumentExtensions;
|
||||
public final List<DefinitionsDocumentExtension> definitionsDocumentExtensions;
|
||||
public final List<PathsDocumentExtension> pathsDocumentExtensions;
|
||||
public final List<SecurityDocumentExtension> securityDocumentExtensions;
|
||||
|
||||
public Context(List<SwaggerModelExtension> swaggerModelExtensions,
|
||||
List<OverviewDocumentExtension> overviewDocumentExtensions,
|
||||
List<DefinitionsDocumentExtension> definitionsDocumentExtensions,
|
||||
List<PathsDocumentExtension> pathsDocumentExtensions,
|
||||
List<SecurityDocumentExtension> securityDocumentExtensions){
|
||||
this.swaggerModelExtensions = swaggerModelExtensions;
|
||||
this.overviewDocumentExtensions = overviewDocumentExtensions;
|
||||
this.definitionsDocumentExtensions = definitionsDocumentExtensions;
|
||||
this.pathsDocumentExtensions = pathsDocumentExtensions;
|
||||
this.securityDocumentExtensions = securityDocumentExtensions;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.adapter;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.github.swagger2markup.Swagger2MarkupConfig;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.*;
|
||||
import io.github.swagger2markup.internal.utils.InlineSchemaUtils;
|
||||
import io.github.swagger2markup.internal.utils.ModelUtils;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.parameters.AbstractSerializableParameter;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.parameters.RefParameter;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.*;
|
||||
|
||||
public class ParameterAdapter {
|
||||
|
||||
private final Parameter parameter;
|
||||
private Type type;
|
||||
private final List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
private final Swagger2MarkupConfig config;
|
||||
|
||||
public ParameterAdapter(Swagger2MarkupConverter.Context context,
|
||||
PathOperation operation,
|
||||
Parameter parameter,
|
||||
DocumentResolver definitionDocumentResolver){
|
||||
Validate.notNull(parameter, "parameter must not be null");
|
||||
this.parameter = parameter;
|
||||
type = getType(context.getSwagger().getDefinitions(), definitionDocumentResolver);
|
||||
config = context.getConfig();
|
||||
if (config.isInlineSchemaEnabled()){
|
||||
if(config.isFlatBodyEnabled()) {
|
||||
if (!(type instanceof ObjectType)){
|
||||
type = InlineSchemaUtils.createInlineType(type, parameter.getName(), operation.getId() + " " + parameter.getName(), inlineDefinitions);
|
||||
}
|
||||
}else{
|
||||
type = InlineSchemaUtils.createInlineType(type, parameter.getName(), operation.getId() + " " + parameter.getName(), inlineDefinitions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getAccess() {
|
||||
return parameter.getAccess();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return parameter.getName();
|
||||
}
|
||||
|
||||
public String getUniqueName() {
|
||||
return type.getUniqueName();
|
||||
}
|
||||
|
||||
public String displaySchema(MarkupDocBuilder docBuilder) {
|
||||
return type.displaySchema(docBuilder);
|
||||
}
|
||||
|
||||
public String displayDefaultValue(MarkupDocBuilder docBuilder) {
|
||||
return getDefaultValue().map(value -> literalText(docBuilder, Json.pretty(value))).orElse("");
|
||||
}
|
||||
|
||||
public String displayDescription(MarkupDocBuilder markupDocBuilder) {
|
||||
return markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, getDescription());
|
||||
}
|
||||
|
||||
public String displayType(MarkupDocBuilder markupDocBuilder) {
|
||||
return boldText(markupDocBuilder, getIn());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return parameter.getDescription();
|
||||
}
|
||||
|
||||
public boolean getRequired() {
|
||||
return parameter.getRequired();
|
||||
}
|
||||
|
||||
public String getPattern() {
|
||||
return parameter.getPattern();
|
||||
}
|
||||
|
||||
public Map<String, Object> getVendorExtensions() {
|
||||
return parameter.getVendorExtensions();
|
||||
}
|
||||
|
||||
public String getIn(){
|
||||
return WordUtils.capitalize(parameter.getIn());
|
||||
}
|
||||
|
||||
public Type getType(){
|
||||
return type;
|
||||
}
|
||||
|
||||
public List<ObjectType> getInlineDefinitions(){
|
||||
return inlineDefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the type of a parameter, or otherwise null
|
||||
*
|
||||
* @param definitionDocumentResolver the definition document resolver
|
||||
* @return the type of the parameter, or otherwise null
|
||||
*/
|
||||
private Type getType(Map<String, Model> definitions, DocumentResolver definitionDocumentResolver){
|
||||
Validate.notNull(parameter, "parameter must not be null!");
|
||||
Type type = null;
|
||||
|
||||
if(parameter instanceof BodyParameter){
|
||||
BodyParameter bodyParameter = (BodyParameter)parameter;
|
||||
Model model = bodyParameter.getSchema();
|
||||
|
||||
if(model != null){
|
||||
type = ModelUtils.getType(model, definitions, definitionDocumentResolver);
|
||||
}else{
|
||||
type = new BasicType("string", bodyParameter.getName());
|
||||
}
|
||||
|
||||
}
|
||||
else if(parameter instanceof AbstractSerializableParameter){
|
||||
AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter)parameter;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> enums = serializableParameter.getEnum();
|
||||
|
||||
if(CollectionUtils.isNotEmpty(enums)){
|
||||
type = new EnumType(serializableParameter.getName(), enums);
|
||||
}else{
|
||||
type = new BasicType(serializableParameter.getType(), serializableParameter.getName(), serializableParameter.getFormat());
|
||||
}
|
||||
if(serializableParameter.getType().equals("array")){
|
||||
String collectionFormat = serializableParameter.getCollectionFormat();
|
||||
|
||||
type = new ArrayType(serializableParameter.getName(), new PropertyAdapter(serializableParameter.getItems()).getType(definitionDocumentResolver), collectionFormat);
|
||||
}
|
||||
}
|
||||
else if(parameter instanceof RefParameter){
|
||||
String refName = ((RefParameter)parameter).getSimpleRef();
|
||||
|
||||
type = new RefType(definitionDocumentResolver.apply(refName), new ObjectType(refName, null /* FIXME, not used for now */));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default value of a parameter
|
||||
*
|
||||
* @return the default value of the parameter
|
||||
*/
|
||||
public Optional<String> getDefaultValue(){
|
||||
Validate.notNull(parameter, "parameter must not be null!");
|
||||
if(parameter instanceof AbstractSerializableParameter){
|
||||
AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter)parameter;
|
||||
return Optional.ofNullable(serializableParameter.getDefaultValue());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a default example value for parameter.
|
||||
*
|
||||
* @param parameter parameter
|
||||
* @return a generated example for the parameter
|
||||
*/
|
||||
public static Object generateExample(AbstractSerializableParameter parameter) {
|
||||
switch (parameter.getType()) {
|
||||
case "integer":
|
||||
return 0;
|
||||
case "number":
|
||||
return 0.0;
|
||||
case "boolean":
|
||||
return true;
|
||||
case "string":
|
||||
return "string";
|
||||
default:
|
||||
return parameter.getType();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.adapter;
|
||||
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.*;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.models.refs.RefFormat;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public final class PropertyAdapter {
|
||||
|
||||
private final Property property;
|
||||
|
||||
public PropertyAdapter(Property property){
|
||||
Validate.notNull(property, "property must not be null");
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the type and format of a property.
|
||||
*
|
||||
* @param definitionDocumentResolver the definition document resolver
|
||||
* @return the type of the property
|
||||
*/
|
||||
public Type getType(DocumentResolver definitionDocumentResolver) {
|
||||
Type type;
|
||||
if (property instanceof RefProperty) {
|
||||
RefProperty refProperty = (RefProperty) property;
|
||||
if (refProperty.getRefFormat() == RefFormat.RELATIVE)
|
||||
type = new ObjectType(refProperty.getTitle(), null); // FIXME : Workaround for https://github.com/swagger-api/swagger-parser/issues/177
|
||||
else
|
||||
type = new RefType(definitionDocumentResolver.apply(refProperty.getSimpleRef()), new ObjectType(refProperty.getSimpleRef(), null /* FIXME, not used for now */));
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
ArrayProperty arrayProperty = (ArrayProperty) property;
|
||||
Property items = arrayProperty.getItems();
|
||||
if (items == null)
|
||||
type = new ArrayType(arrayProperty.getTitle(), new ObjectType(null, null)); // FIXME : Workaround for Swagger parser issue with composed models (https://github.com/Swagger2Markup/swagger2markup/issues/150)
|
||||
else
|
||||
type = new ArrayType(arrayProperty.getTitle(), new PropertyAdapter(items).getType(definitionDocumentResolver));
|
||||
} else if (property instanceof MapProperty) {
|
||||
MapProperty mapProperty = (MapProperty) property;
|
||||
Property additionalProperties = mapProperty.getAdditionalProperties();
|
||||
if (additionalProperties == null)
|
||||
type = new MapType(mapProperty.getTitle(), new ObjectType(null, null)); // FIXME : Workaround for Swagger parser issue with composed models (https://github.com/Swagger2Markup/swagger2markup/issues/150)
|
||||
else
|
||||
type = new MapType(mapProperty.getTitle(), new PropertyAdapter(additionalProperties).getType(definitionDocumentResolver));
|
||||
} else if (property instanceof StringProperty) {
|
||||
StringProperty stringProperty = (StringProperty) property;
|
||||
List<String> enums = stringProperty.getEnum();
|
||||
if (CollectionUtils.isNotEmpty(enums)) {
|
||||
type = new EnumType(stringProperty.getTitle(), enums);
|
||||
} else if(isNotBlank(stringProperty.getFormat())) {
|
||||
type = new BasicType(stringProperty.getType(), stringProperty.getTitle(), stringProperty.getFormat());
|
||||
} else {
|
||||
type = new BasicType(stringProperty.getType(), stringProperty.getTitle());
|
||||
}
|
||||
} else if (property instanceof ObjectProperty) {
|
||||
type = new ObjectType(property.getTitle(), ((ObjectProperty) property).getProperties());
|
||||
} else {
|
||||
if (isNotBlank(property.getFormat())) {
|
||||
type = new BasicType(property.getType(), property.getTitle(), property.getFormat());
|
||||
} else {
|
||||
type = new BasicType(property.getType(), property.getTitle());
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default value of a property
|
||||
*
|
||||
* @return the default value of the property
|
||||
*/
|
||||
public Optional<Object> getDefaultValue() {
|
||||
if (property instanceof BooleanProperty) {
|
||||
BooleanProperty booleanProperty = (BooleanProperty) property;
|
||||
return Optional.ofNullable(booleanProperty.getDefault());
|
||||
} else if (property instanceof StringProperty) {
|
||||
StringProperty stringProperty = (StringProperty) property;
|
||||
return Optional.ofNullable(stringProperty.getDefault());
|
||||
} else if (property instanceof DoubleProperty) {
|
||||
DoubleProperty doubleProperty = (DoubleProperty) property;
|
||||
return Optional.ofNullable(doubleProperty.getDefault());
|
||||
} else if (property instanceof FloatProperty) {
|
||||
FloatProperty floatProperty = (FloatProperty) property;
|
||||
return Optional.ofNullable(floatProperty.getDefault());
|
||||
} else if (property instanceof IntegerProperty) {
|
||||
IntegerProperty integerProperty = (IntegerProperty) property;
|
||||
return Optional.ofNullable(integerProperty.getDefault());
|
||||
} else if (property instanceof LongProperty) {
|
||||
LongProperty longProperty = (LongProperty) property;
|
||||
return Optional.ofNullable(longProperty.getDefault());
|
||||
} else if (property instanceof UUIDProperty) {
|
||||
UUIDProperty uuidProperty = (UUIDProperty) property;
|
||||
return Optional.ofNullable(uuidProperty.getDefault());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the minLength of a property
|
||||
*
|
||||
* @return the minLength of the property
|
||||
*/
|
||||
public Optional<Integer> getMinlength() {
|
||||
if (property instanceof StringProperty) {
|
||||
StringProperty stringProperty = (StringProperty) property;
|
||||
return Optional.ofNullable(stringProperty.getMinLength());
|
||||
} else if (property instanceof UUIDProperty) {
|
||||
UUIDProperty uuidProperty = (UUIDProperty) property;
|
||||
return Optional.ofNullable(uuidProperty.getMinLength());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the maxLength of a property
|
||||
*
|
||||
* @return the maxLength of the property
|
||||
*/
|
||||
public Optional<Integer> getMaxlength() {
|
||||
if (property instanceof StringProperty) {
|
||||
StringProperty stringProperty = (StringProperty) property;
|
||||
return Optional.ofNullable(stringProperty.getMaxLength());
|
||||
} else if (property instanceof UUIDProperty) {
|
||||
UUIDProperty uuidProperty = (UUIDProperty) property;
|
||||
return Optional.ofNullable(uuidProperty.getMaxLength());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the pattern of a property
|
||||
*
|
||||
* @return the pattern of the property
|
||||
*/
|
||||
public Optional<String> getPattern() {
|
||||
if (property instanceof StringProperty) {
|
||||
StringProperty stringProperty = (StringProperty) property;
|
||||
return Optional.ofNullable(stringProperty.getPattern());
|
||||
} else if (property instanceof UUIDProperty) {
|
||||
UUIDProperty uuidProperty = (UUIDProperty) property;
|
||||
return Optional.ofNullable(uuidProperty.getPattern());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the minimum value of a property
|
||||
*
|
||||
* @return the minimum value of the property
|
||||
*/
|
||||
public Optional<Number> getMin() {
|
||||
if (property instanceof BaseIntegerProperty){
|
||||
BaseIntegerProperty integerProperty = (BaseIntegerProperty) property;
|
||||
return Optional.ofNullable(integerProperty.getMinimum() != null ? integerProperty.getMinimum().longValue() : null);
|
||||
} else if (property instanceof AbstractNumericProperty){
|
||||
AbstractNumericProperty numericProperty = (AbstractNumericProperty) property;
|
||||
return Optional.ofNullable(numericProperty.getMinimum());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the exclusiveMinimum value of a property
|
||||
*
|
||||
* @return the exclusiveMinimum value of the property
|
||||
*/
|
||||
public boolean getExclusiveMin() {
|
||||
if (property instanceof AbstractNumericProperty){
|
||||
AbstractNumericProperty numericProperty = (AbstractNumericProperty) property;
|
||||
return BooleanUtils.isTrue(numericProperty.getExclusiveMinimum());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the minimum value of a property
|
||||
*
|
||||
* @return the minimum value of the property
|
||||
*/
|
||||
public Optional<Number> getMax() {
|
||||
if (property instanceof BaseIntegerProperty){
|
||||
BaseIntegerProperty integerProperty = (BaseIntegerProperty) property;
|
||||
return Optional.ofNullable(integerProperty.getMaximum() != null ? integerProperty.getMaximum().longValue() : null);
|
||||
} else if (property instanceof AbstractNumericProperty){
|
||||
AbstractNumericProperty numericProperty = (AbstractNumericProperty) property;
|
||||
return Optional.ofNullable(numericProperty.getMaximum());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the exclusiveMaximum value of a property
|
||||
*
|
||||
* @return the exclusiveMaximum value of the property
|
||||
*/
|
||||
public boolean getExclusiveMax() {
|
||||
if (property instanceof AbstractNumericProperty){
|
||||
AbstractNumericProperty numericProperty = (AbstractNumericProperty) property;
|
||||
return BooleanUtils.isTrue((numericProperty.getExclusiveMaximum()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return example display string for the given {@code property}.
|
||||
*
|
||||
* @param generateMissingExamples specifies if missing examples should be generated
|
||||
* @param markupDocBuilder doc builder
|
||||
* @return property example display string
|
||||
*/
|
||||
public Optional<Object> getExample(boolean generateMissingExamples, MarkupDocBuilder markupDocBuilder) {
|
||||
if (property.getExample() != null) {
|
||||
return Optional.ofNullable(property.getExample());
|
||||
} else if (property instanceof MapProperty) {
|
||||
Property additionalProperty = ((MapProperty) property).getAdditionalProperties();
|
||||
if (additionalProperty.getExample() != null) {
|
||||
return Optional.ofNullable(additionalProperty.getExample());
|
||||
} else if (generateMissingExamples) {
|
||||
Map<String, Object> exampleMap = new HashMap<>();
|
||||
exampleMap.put("string", generateExample(additionalProperty, markupDocBuilder));
|
||||
return Optional.of(exampleMap);
|
||||
}
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
if (generateMissingExamples) {
|
||||
Property itemProperty = ((ArrayProperty) property).getItems();
|
||||
List<Object> exampleArray = new ArrayList<>();
|
||||
exampleArray.add(generateExample(itemProperty, markupDocBuilder));
|
||||
return Optional.of(exampleArray);
|
||||
}
|
||||
} else if (generateMissingExamples) {
|
||||
return Optional.of(generateExample(property, markupDocBuilder));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a default example value for property.
|
||||
*
|
||||
* @param property property
|
||||
* @param markupDocBuilder doc builder
|
||||
* @return a generated example for the property
|
||||
*/
|
||||
public static Object generateExample(Property property, MarkupDocBuilder markupDocBuilder) {
|
||||
switch (property.getType()) {
|
||||
case "integer":
|
||||
return 0;
|
||||
case "number":
|
||||
return 0.0;
|
||||
case "boolean":
|
||||
return true;
|
||||
case "string":
|
||||
return "string";
|
||||
case "ref":
|
||||
if (property instanceof RefProperty) {
|
||||
return markupDocBuilder.copy(false).crossReference(((RefProperty) property).getSimpleRef()).toString();
|
||||
}
|
||||
default:
|
||||
return property.getType();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string {@code value} to specified {@code type}.
|
||||
*
|
||||
* @param value value to convert
|
||||
* @param type target conversion type
|
||||
* @return converted value as object
|
||||
*/
|
||||
public static Object convertExample(String value, String type) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
switch (type) {
|
||||
case "integer":
|
||||
return Integer.valueOf(value);
|
||||
case "number":
|
||||
return Float.valueOf(value);
|
||||
case "boolean":
|
||||
return Boolean.valueOf(value);
|
||||
case "string":
|
||||
return value;
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new RuntimeException(String.format("Value '%s' cannot be converted to '%s'", value, type), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a property is read-only.
|
||||
*
|
||||
* @return true if the property is read-only
|
||||
*/
|
||||
public boolean getReadOnly() {
|
||||
return BooleanUtils.isTrue(property.getReadOnly());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.GroupBy;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.adapter.ParameterAdapter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.type.Type;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class BodyParameterComponent extends MarkupComponent<BodyParameterComponent.Parameters> {
|
||||
|
||||
private final DocumentResolver definitionDocumentResolver;
|
||||
private final PropertiesTableComponent propertiesTableComponent;
|
||||
|
||||
public BodyParameterComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionDocumentResolver){
|
||||
super(context);
|
||||
this.definitionDocumentResolver = Validate.notNull(definitionDocumentResolver, "DocumentResolver must not be null");
|
||||
this.propertiesTableComponent = new PropertiesTableComponent(context, definitionDocumentResolver);
|
||||
}
|
||||
|
||||
public static BodyParameterComponent.Parameters parameters(PathOperation operation,
|
||||
List<ObjectType> inlineDefinitions){
|
||||
return new BodyParameterComponent.Parameters(operation, inlineDefinitions);
|
||||
}
|
||||
|
||||
public static class Parameters{
|
||||
private PathOperation operation;
|
||||
private final List<ObjectType> inlineDefinitions;
|
||||
public Parameters(PathOperation operation,
|
||||
List<ObjectType> inlineDefinitions){
|
||||
Validate.notNull(operation, "Operation must not be null");
|
||||
this.operation = operation;
|
||||
this.inlineDefinitions = inlineDefinitions;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
PathOperation operation = params.operation;
|
||||
List<ObjectType> inlineDefinitions = params.inlineDefinitions;
|
||||
if (config.isFlatBodyEnabled()) {
|
||||
List<Parameter> parameters = operation.getOperation().getParameters();
|
||||
if (CollectionUtils.isNotEmpty(parameters)) {
|
||||
for (Parameter parameter : parameters) {
|
||||
if (StringUtils.equals(parameter.getIn(), "body")) {
|
||||
ParameterAdapter parameterAdapter = new ParameterAdapter(context,
|
||||
operation, parameter, definitionDocumentResolver);
|
||||
|
||||
Type type = parameterAdapter.getType();
|
||||
inlineDefinitions.addAll(parameterAdapter.getInlineDefinitions());
|
||||
|
||||
buildSectionTitle(markupDocBuilder, labels.getLabel(BODY_PARAMETER));
|
||||
String description = parameter.getDescription();
|
||||
if (isNotBlank(description)) {
|
||||
markupDocBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
|
||||
}
|
||||
|
||||
MarkupDocBuilder typeInfos = copyMarkupDocBuilder(markupDocBuilder);
|
||||
typeInfos.italicText(labels.getLabel(NAME_COLUMN)).textLine(COLON + parameter.getName());
|
||||
typeInfos.italicText(labels.getLabel(FLAGS_COLUMN)).textLine(COLON + (BooleanUtils.isTrue(parameter.getRequired()) ? labels.getLabel(FLAGS_REQUIRED).toLowerCase() : labels.getLabel(FLAGS_OPTIONAL).toLowerCase()));
|
||||
|
||||
if (!(type instanceof ObjectType)) {
|
||||
typeInfos.italicText(labels.getLabel(TYPE_COLUMN)).textLine(COLON + type.displaySchema(markupDocBuilder));
|
||||
}
|
||||
|
||||
markupDocBuilder.paragraph(typeInfos.toString(), true);
|
||||
|
||||
if (type instanceof ObjectType) {
|
||||
List<ObjectType> localDefinitions = new ArrayList<>();
|
||||
|
||||
propertiesTableComponent.apply(markupDocBuilder, PropertiesTableComponent.parameters(
|
||||
((ObjectType) type).getProperties(),
|
||||
operation.getId(),
|
||||
localDefinitions
|
||||
));
|
||||
|
||||
inlineDefinitions.addAll(localDefinitions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
private void buildSectionTitle(MarkupDocBuilder markupDocBuilder, String title) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
markupDocBuilder.sectionTitleLevel3(title);
|
||||
} else {
|
||||
markupDocBuilder.sectionTitleLevel4(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.literalText;
|
||||
|
||||
public class ConsumesComponent extends MarkupComponent<ConsumesComponent.Parameters> {
|
||||
|
||||
public ConsumesComponent(Swagger2MarkupConverter.Context context){
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final List<String> consumes;
|
||||
private final int titleLevel;
|
||||
public Parameters(List<String> consumes,
|
||||
int titleLevel){
|
||||
this.consumes = Validate.notNull(consumes, "Consumes must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public static ConsumesComponent.Parameters parameters(List<String> consumes,
|
||||
int titleLevel){
|
||||
return new ConsumesComponent.Parameters(consumes, titleLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.CONSUMES));
|
||||
markupDocBuilder.unorderedList(params.consumes.stream()
|
||||
.map(value -> literalText(markupDocBuilder, value)).collect(Collectors.toList()));
|
||||
return markupDocBuilder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Contact;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class ContactInfoComponent extends MarkupComponent<ContactInfoComponent.Parameters> {
|
||||
|
||||
public ContactInfoComponent(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final Contact contact;
|
||||
private final int titleLevel;
|
||||
public Parameters(Contact contact,
|
||||
int titleLevel){
|
||||
this.contact = Validate.notNull(contact, "Contact must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public static ContactInfoComponent.Parameters parameters(Contact contact,
|
||||
int titleLevel){
|
||||
return new ContactInfoComponent.Parameters(contact, titleLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
Contact contact = params.contact;
|
||||
if (isNotBlank(contact.getName()) || isNotBlank(contact.getEmail())){
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.CONTACT_INFORMATION));
|
||||
MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
if (isNotBlank(contact.getName())) {
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.CONTACT_NAME))
|
||||
.textLine(COLON + contact.getName());
|
||||
}
|
||||
if (isNotBlank(contact.getEmail())) {
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.CONTACT_EMAIL))
|
||||
.textLine(COLON + contact.getEmail());
|
||||
}
|
||||
markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
}
|
||||
return markupDocBuilder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.type.ObjectTypePolymorphism;
|
||||
import io.github.swagger2markup.internal.type.Type;
|
||||
import io.github.swagger2markup.internal.utils.ModelUtils;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.DefinitionsDocumentExtension;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Model;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.InlineSchemaUtils.createInlineType;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription;
|
||||
import static io.github.swagger2markup.spi.DefinitionsDocumentExtension.Position;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class DefinitionComponent extends MarkupComponent<DefinitionComponent.Parameters> {
|
||||
|
||||
/* Discriminator is only displayed for inheriting definitions */
|
||||
private static final boolean ALWAYS_DISPLAY_DISCRIMINATOR = false;
|
||||
|
||||
private final Map<String, Model> definitions;
|
||||
private final Map<ObjectTypePolymorphism.Nature, String> POLYMORPHISM_NATURE;
|
||||
private final DocumentResolver definitionsDocumentResolver;
|
||||
private PropertiesTableComponent propertiesTableComponent;
|
||||
|
||||
public DefinitionComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionsDocumentResolver) {
|
||||
super(context);
|
||||
this.definitions = context.getSwagger().getDefinitions();
|
||||
this.definitionsDocumentResolver = definitionsDocumentResolver;
|
||||
POLYMORPHISM_NATURE = new HashMap<ObjectTypePolymorphism.Nature, String>() {{
|
||||
put(ObjectTypePolymorphism.Nature.COMPOSITION, labels.getLabel(Labels.POLYMORPHISM_NATURE_COMPOSITION));
|
||||
put(ObjectTypePolymorphism.Nature.INHERITANCE, labels.getLabel(Labels.POLYMORPHISM_NATURE_INHERITANCE));
|
||||
}};
|
||||
propertiesTableComponent = new PropertiesTableComponent(context, definitionsDocumentResolver);
|
||||
}
|
||||
|
||||
public static DefinitionComponent.Parameters parameters(String definitionName,
|
||||
Model model,
|
||||
int titleLevel){
|
||||
return new DefinitionComponent.Parameters(definitionName, model, titleLevel);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final String definitionName;
|
||||
private final Model model;
|
||||
private final int titleLevel;
|
||||
|
||||
public Parameters(String definitionName,
|
||||
Model model,
|
||||
int titleLevel){
|
||||
this.definitionName = Validate.notBlank(definitionName, "DefinitionName must not be empty");
|
||||
this.model = Validate.notNull(model, "Model must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
String definitionName = params.definitionName;
|
||||
Model model = params.model;
|
||||
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_BEFORE, markupDocBuilder, definitionName, model));
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel(params.titleLevel, definitionName, definitionName);
|
||||
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_BEGIN, markupDocBuilder, definitionName, model));
|
||||
String description = model.getDescription();
|
||||
if (isNotBlank(description)) {
|
||||
markupDocBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
|
||||
}
|
||||
inlineDefinitions(markupDocBuilder, typeSection(markupDocBuilder, definitionName, model), definitionName);
|
||||
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_END, markupDocBuilder, definitionName, model));
|
||||
applyDefinitionsDocumentExtension(new DefinitionsDocumentExtension.Context(Position.DEFINITION_AFTER, markupDocBuilder, definitionName, model));
|
||||
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the title of an inline schema.
|
||||
* Inline definitions should never been referenced in TOC because they have no real existence, so they are just text.
|
||||
*
|
||||
* @param title inline schema title
|
||||
* @param anchor inline schema anchor
|
||||
* @param docBuilder the docbuilder do use for output
|
||||
*/
|
||||
private void addInlineDefinitionTitle(String title, String anchor, MarkupDocBuilder docBuilder) {
|
||||
docBuilder.anchor(anchor, null);
|
||||
docBuilder.newLine();
|
||||
docBuilder.boldTextLine(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds inline schema definitions
|
||||
*
|
||||
* @param markupDocBuilder the docbuilder do use for output
|
||||
* @param definitions all inline definitions to display
|
||||
* @param uniquePrefix unique prefix to prepend to inline object names to enforce unicity
|
||||
|
||||
*/
|
||||
private void inlineDefinitions(MarkupDocBuilder markupDocBuilder, List<ObjectType> definitions, String uniquePrefix) {
|
||||
if (CollectionUtils.isNotEmpty(definitions)) {
|
||||
for (ObjectType definition : definitions) {
|
||||
addInlineDefinitionTitle(definition.getName(), definition.getUniqueName(), markupDocBuilder);
|
||||
|
||||
List<ObjectType> localDefinitions = new ArrayList<>();
|
||||
propertiesTableComponent.apply(markupDocBuilder, new PropertiesTableComponent.Parameters(definition.getProperties(), uniquePrefix, localDefinitions));
|
||||
for (ObjectType localDefinition : localDefinitions)
|
||||
inlineDefinitions(markupDocBuilder, Collections.singletonList(localDefinition), localDefinition.getUniqueName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the type informations of a definition
|
||||
*
|
||||
* @param markupDocBuilder the docbuilder do use for output
|
||||
* @param definitionName name of the definition to display
|
||||
* @param model model of the definition to display
|
||||
|
||||
* @return a list of inlined types.
|
||||
*/
|
||||
private List<ObjectType> typeSection(MarkupDocBuilder markupDocBuilder, String definitionName, Model model) {
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
Type modelType = ModelUtils.resolveRefType(ModelUtils.getType(model, definitions, definitionsDocumentResolver));
|
||||
|
||||
if (!(modelType instanceof ObjectType)) {
|
||||
if (config.isInlineSchemaEnabled()) {
|
||||
modelType = createInlineType(modelType, definitionName, definitionName + " " + "inline", inlineDefinitions);
|
||||
}
|
||||
}
|
||||
|
||||
if (modelType instanceof ObjectType) {
|
||||
ObjectType objectType = (ObjectType) modelType;
|
||||
MarkupDocBuilder typeInfos = copyMarkupDocBuilder(markupDocBuilder);
|
||||
switch (objectType.getPolymorphism().getNature()) {
|
||||
case COMPOSITION:
|
||||
typeInfos.italicText(labels.getLabel(Labels.POLYMORPHISM_COLUMN)).textLine(COLON + POLYMORPHISM_NATURE.get(objectType.getPolymorphism().getNature()));
|
||||
break;
|
||||
case INHERITANCE:
|
||||
typeInfos.italicText(labels.getLabel(POLYMORPHISM_COLUMN)).textLine(COLON + POLYMORPHISM_NATURE.get(objectType.getPolymorphism().getNature()));
|
||||
typeInfos.italicText(labels.getLabel(POLYMORPHISM_DISCRIMINATOR_COLUMN)).textLine(COLON + objectType.getPolymorphism().getDiscriminator());
|
||||
break;
|
||||
case NONE:
|
||||
if (ALWAYS_DISPLAY_DISCRIMINATOR) {
|
||||
if (StringUtils.isNotBlank(objectType.getPolymorphism().getDiscriminator()))
|
||||
typeInfos.italicText(labels.getLabel(POLYMORPHISM_DISCRIMINATOR_COLUMN)).textLine(COLON + objectType.getPolymorphism().getDiscriminator());
|
||||
}
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
String typeInfosString = typeInfos.toString();
|
||||
if (StringUtils.isNotBlank(typeInfosString))
|
||||
markupDocBuilder.paragraph(typeInfosString, true);
|
||||
|
||||
propertiesTableComponent.apply(markupDocBuilder,
|
||||
PropertiesTableComponent.parameters(
|
||||
((ObjectType) modelType).getProperties(),
|
||||
definitionName,
|
||||
inlineDefinitions));
|
||||
} else if (modelType != null) {
|
||||
MarkupDocBuilder typeInfos = copyMarkupDocBuilder(markupDocBuilder);
|
||||
typeInfos.italicText(labels.getLabel(TYPE_COLUMN)).textLine(COLON + modelType.displaySchema(markupDocBuilder));
|
||||
|
||||
markupDocBuilder.paragraph(typeInfos.toString());
|
||||
}
|
||||
|
||||
return inlineDefinitions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply extension context to all DefinitionsContentExtension
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyDefinitionsDocumentExtension(DefinitionsDocumentExtension.Context context) {
|
||||
extensionRegistry.getDefinitionsDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Info;
|
||||
import io.swagger.models.License;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class LicenseInfoComponent extends MarkupComponent<LicenseInfoComponent.Parameters> {
|
||||
|
||||
public LicenseInfoComponent(Swagger2MarkupConverter.Context context){
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final int titleLevel;
|
||||
private final Info info;
|
||||
|
||||
public Parameters(Info info,
|
||||
int titleLevel){
|
||||
this.info = Validate.notNull(info, "Info must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public static LicenseInfoComponent.Parameters parameters(Info info,
|
||||
int titleLevel){
|
||||
return new LicenseInfoComponent.Parameters(info, titleLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
Info info = params.info;
|
||||
License license = info.getLicense();
|
||||
String termOfService = info.getTermsOfService();
|
||||
if((license != null && (isNotBlank(license.getName()) || isNotBlank(license.getUrl()))) || isNotBlank(termOfService)) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(LICENSE_INFORMATION));
|
||||
MarkupDocBuilder paragraph = copyMarkupDocBuilder(markupDocBuilder);
|
||||
if (license != null) {
|
||||
if (isNotBlank(license.getName())) {
|
||||
paragraph.italicText(labels.getLabel(LICENSE)).textLine(COLON + license.getName());
|
||||
}
|
||||
if (isNotBlank(license.getUrl())) {
|
||||
paragraph.italicText(labels.getLabel(LICENSE_URL)).textLine(COLON + license.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
paragraph.italicText(labels.getLabel(TERMS_OF_SERVICE)).textLine(COLON + termOfService);
|
||||
|
||||
markupDocBuilder.paragraph(paragraph.toString(), true);
|
||||
}
|
||||
|
||||
return markupDocBuilder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import ch.netzwerg.paleo.StringColumn;
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.adapter.ParameterAdapter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.PathsDocumentExtension;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static ch.netzwerg.paleo.ColumnIds.StringColumnId;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.*;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class ParameterTableComponent extends MarkupComponent<ParameterTableComponent.Parameters> {
|
||||
|
||||
|
||||
private final DocumentResolver definitionDocumentResolver;
|
||||
private final TableComponent tableComponent;
|
||||
|
||||
public ParameterTableComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionDocumentResolver){
|
||||
super(context);
|
||||
this.definitionDocumentResolver = Validate.notNull(definitionDocumentResolver, "DocumentResolver must not be null");
|
||||
this.tableComponent = new TableComponent(context);
|
||||
|
||||
}
|
||||
|
||||
public static ParameterTableComponent.Parameters parameters(PathOperation operation,
|
||||
List<ObjectType> inlineDefinitions,
|
||||
int titleLevel){
|
||||
return new ParameterTableComponent.Parameters(operation, inlineDefinitions, titleLevel);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final PathOperation operation;
|
||||
private final int titleLevel;
|
||||
private final List<ObjectType> inlineDefinitions;
|
||||
|
||||
public Parameters(PathOperation operation,
|
||||
List<ObjectType> inlineDefinitions,
|
||||
int titleLevel){
|
||||
this.operation = Validate.notNull(operation, "PathOperation must not be null");
|
||||
this.inlineDefinitions = Validate.notNull(inlineDefinitions, "InlineDefinitions must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
PathOperation operation = params.operation;
|
||||
List<ObjectType> inlineDefinitions = params.inlineDefinitions;
|
||||
List<Parameter> parameters = operation.getOperation().getParameters();
|
||||
if (config.getParameterOrdering() != null)
|
||||
Collections.sort(parameters, config.getParameterOrdering());
|
||||
|
||||
// Filter parameters to display in parameters section
|
||||
List<Parameter> filteredParameters = parameters.stream()
|
||||
.filter(this::filterParameter).collect(Collectors.toList());
|
||||
|
||||
MarkupDocBuilder parametersBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_DESCRIPTION_BEGIN, parametersBuilder, operation));
|
||||
if (CollectionUtils.isNotEmpty(filteredParameters)) {
|
||||
StringColumn.Builder typeColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(TYPE_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "2");
|
||||
StringColumn.Builder nameColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(NAME_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "3");
|
||||
StringColumn.Builder descriptionColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(DESCRIPTION_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "9")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
StringColumn.Builder schemaColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(SCHEMA_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "4")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
StringColumn.Builder defaultColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(DEFAULT_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "2")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
|
||||
for (Parameter parameter : filteredParameters) {
|
||||
ParameterAdapter parameterAdapter = new ParameterAdapter(context,
|
||||
operation, parameter, definitionDocumentResolver);
|
||||
|
||||
inlineDefinitions.addAll(parameterAdapter.getInlineDefinitions());
|
||||
|
||||
typeColumnBuilder.add(parameterAdapter.displayType(markupDocBuilder));
|
||||
nameColumnBuilder.add(getParameterNameColumnContent(markupDocBuilder, parameterAdapter));
|
||||
descriptionColumnBuilder.add(parameterAdapter.displayDescription(markupDocBuilder));
|
||||
schemaColumnBuilder.add(parameterAdapter.displaySchema(markupDocBuilder));
|
||||
defaultColumnBuilder.add(parameterAdapter.displayDefaultValue(markupDocBuilder));
|
||||
}
|
||||
|
||||
parametersBuilder = tableComponent.apply(parametersBuilder, TableComponent.parameters(
|
||||
typeColumnBuilder.build(),
|
||||
nameColumnBuilder.build(),
|
||||
descriptionColumnBuilder.build(),
|
||||
schemaColumnBuilder.build(),
|
||||
defaultColumnBuilder.build()));
|
||||
}
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_DESCRIPTION_END, parametersBuilder, operation));
|
||||
String parametersContent = parametersBuilder.toString();
|
||||
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_PARAMETERS_BEFORE, markupDocBuilder, operation));
|
||||
if (isNotBlank(parametersContent)) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.PARAMETERS));
|
||||
markupDocBuilder.text(parametersContent);
|
||||
}
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_PARAMETERS_AFTER, markupDocBuilder, operation));
|
||||
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
private String getParameterNameColumnContent(MarkupDocBuilder markupDocBuilder, ParameterAdapter parameter){
|
||||
MarkupDocBuilder parameterNameContent = copyMarkupDocBuilder(markupDocBuilder);
|
||||
|
||||
parameterNameContent.boldTextLine(parameter.getName(), true);
|
||||
if (parameter.getRequired())
|
||||
parameterNameContent.italicText(labels.getLabel(FLAGS_REQUIRED).toLowerCase());
|
||||
else
|
||||
parameterNameContent.italicText(labels.getLabel(FLAGS_OPTIONAL).toLowerCase());
|
||||
return parameterNameContent.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter parameters to display in parameters section
|
||||
*
|
||||
* @param parameter parameter to filter
|
||||
* @return true if parameter can be displayed
|
||||
*/
|
||||
private boolean filterParameter(Parameter parameter) {
|
||||
return (!config.isFlatBodyEnabled() || !StringUtils.equals(parameter.getIn(), "body"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all OperationsContentExtension.
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyPathsDocumentExtension(PathsDocumentExtension.Context context) {
|
||||
extensionRegistry.getPathsDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.GroupBy;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.utils.ExamplesUtil;
|
||||
import io.github.swagger2markup.markup.builder.MarkupAdmonition;
|
||||
import io.github.swagger2markup.markup.builder.MarkupBlockStyle;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.PathsDocumentExtension;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription;
|
||||
import static io.github.swagger2markup.spi.PathsDocumentExtension.Position;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class PathOperationComponent extends MarkupComponent<PathOperationComponent.Parameters> {
|
||||
|
||||
private final DocumentResolver definitionDocumentResolver;
|
||||
private final Map<String, Model> definitions;
|
||||
private final PropertiesTableComponent propertiesTableComponent;
|
||||
private final ParameterTableComponent parameterTableComponent;
|
||||
private final ConsumesComponent consumesComponent;
|
||||
private final ProducesComponent producesComponent;
|
||||
private final SecuritySchemeComponent securitySchemeComponent;
|
||||
private final BodyParameterComponent bodyParameterComponent;
|
||||
private final ResponseComponent responseComponent;
|
||||
|
||||
public PathOperationComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionDocumentResolver,
|
||||
DocumentResolver securityDocumentResolver){
|
||||
super(context);
|
||||
this.definitions = context.getSwagger().getDefinitions();
|
||||
this.definitionDocumentResolver = Validate.notNull(definitionDocumentResolver, "DocumentResolver must not be null");
|
||||
this.propertiesTableComponent = new PropertiesTableComponent(context, definitionDocumentResolver);
|
||||
this.parameterTableComponent = new ParameterTableComponent(context, definitionDocumentResolver);
|
||||
this.consumesComponent = new ConsumesComponent(context);
|
||||
this.producesComponent = new ProducesComponent(context);
|
||||
this.securitySchemeComponent = new SecuritySchemeComponent(context, securityDocumentResolver);
|
||||
this.bodyParameterComponent = new BodyParameterComponent(context, definitionDocumentResolver);
|
||||
this.responseComponent = new ResponseComponent(context, definitionDocumentResolver);
|
||||
}
|
||||
|
||||
public static PathOperationComponent.Parameters parameters(PathOperation operation){
|
||||
return new PathOperationComponent.Parameters(operation);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
|
||||
private final PathOperation operation;
|
||||
|
||||
public Parameters(PathOperation operation){
|
||||
this.operation = Validate.notNull(operation, "PathOperation must not be null");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
|
||||
PathOperation operation = params.operation;
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_BEFORE, markupDocBuilder, operation));
|
||||
buildOperationTitle(markupDocBuilder, operation);
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_BEGIN, markupDocBuilder, operation));
|
||||
buildDeprecatedSection(markupDocBuilder, operation);
|
||||
buildDescriptionSection(markupDocBuilder, operation);
|
||||
inlineDefinitions(markupDocBuilder, buildParametersSection(markupDocBuilder, operation), operation.getPath() + " " + operation.getMethod());
|
||||
inlineDefinitions(markupDocBuilder, buildBodyParameterSection(markupDocBuilder, operation), operation.getPath() + " " + operation.getMethod());
|
||||
inlineDefinitions(markupDocBuilder, buildResponsesSection(markupDocBuilder, operation), operation.getPath() + " " + operation.getMethod());
|
||||
buildConsumesSection(markupDocBuilder, operation);
|
||||
buildProducesSection(markupDocBuilder, operation);
|
||||
buildTagsSection(markupDocBuilder, operation);
|
||||
buildSecuritySchemeSection(markupDocBuilder, operation);
|
||||
buildExamplesSection(markupDocBuilder, operation);
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_END, markupDocBuilder, operation));
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_AFTER, markupDocBuilder, operation));
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the operation title to the document. If the operation has a summary, the title is the summary.
|
||||
* Otherwise the title is the method of the operation and the URL of the operation.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildOperationTitle(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
buildOperationTitle(markupDocBuilder, operation.getTitle(), operation.getId());
|
||||
if (operation.getTitle().equals(operation.getOperation().getSummary())) {
|
||||
markupDocBuilder.block(operation.getMethod() + " " + operation.getPath(), MarkupBlockStyle.LITERAL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a operation title to the document.
|
||||
*
|
||||
* @param title the operation title
|
||||
* @param anchor optional anchor (null => auto-generate from title)
|
||||
*/
|
||||
private void buildOperationTitle(MarkupDocBuilder markupDocBuilder, String title, String anchor) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel2(title, anchor);
|
||||
} else {
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel3(title, anchor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a warning if method is deprecated.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildDeprecatedSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
if (BooleanUtils.isTrue(operation.getOperation().isDeprecated())) {
|
||||
markupDocBuilder.block(DEPRECATED_OPERATION, MarkupBlockStyle.EXAMPLE, null, MarkupAdmonition.CAUTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a operation description to the document.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildDescriptionSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
MarkupDocBuilder descriptionBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_DESCRIPTION_BEGIN, descriptionBuilder, operation));
|
||||
String description = operation.getOperation().getDescription();
|
||||
if (isNotBlank(description)) {
|
||||
descriptionBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
|
||||
}
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_DESCRIPTION_END, descriptionBuilder, operation));
|
||||
String descriptionContent = descriptionBuilder.toString();
|
||||
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_DESCRIPTION_BEFORE, markupDocBuilder, operation));
|
||||
if (isNotBlank(descriptionContent)) {
|
||||
buildSectionTitle(markupDocBuilder, labels.getLabel(Labels.DESCRIPTION));
|
||||
markupDocBuilder.text(descriptionContent);
|
||||
}
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(Position.OPERATION_DESCRIPTION_AFTER, markupDocBuilder, operation));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the parameters section
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private List<ObjectType> buildParametersSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
|
||||
parameterTableComponent.apply(markupDocBuilder, ParameterTableComponent.parameters(
|
||||
operation,
|
||||
inlineDefinitions,
|
||||
getSectionTitleLevel()
|
||||
));
|
||||
|
||||
return inlineDefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the body parameter section
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
* @return a list of inlined types.
|
||||
*/
|
||||
private List<ObjectType> buildBodyParameterSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
|
||||
bodyParameterComponent.apply(markupDocBuilder, BodyParameterComponent.parameters(
|
||||
operation,
|
||||
inlineDefinitions
|
||||
));
|
||||
|
||||
return inlineDefinitions;
|
||||
}
|
||||
|
||||
private List<ObjectType> buildResponsesSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
List<ObjectType> inlineDefinitions = new ArrayList<>();
|
||||
|
||||
responseComponent.apply(markupDocBuilder, ResponseComponent.parameters(
|
||||
operation,
|
||||
getSectionTitleLevel(),
|
||||
inlineDefinitions
|
||||
));
|
||||
|
||||
return inlineDefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a operation section title to the document.
|
||||
*
|
||||
* @param title the section title
|
||||
*/
|
||||
private void buildSectionTitle(MarkupDocBuilder markupDocBuilder, String title) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
markupDocBuilder.sectionTitleLevel3(title);
|
||||
} else {
|
||||
markupDocBuilder.sectionTitleLevel4(title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Builds the title of an inline schema.
|
||||
* Inline definitions should never been referenced in TOC because they have no real existence, so they are just text.
|
||||
*
|
||||
* @param title inline schema title
|
||||
* @param anchor inline schema anchor
|
||||
*/
|
||||
private void addInlineDefinitionTitle(MarkupDocBuilder markupDocBuilder, String title, String anchor) {
|
||||
markupDocBuilder.anchor(anchor);
|
||||
markupDocBuilder.newLine();
|
||||
markupDocBuilder.boldTextLine(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds inline schema definitions
|
||||
|
||||
* @param markupDocBuilder the docbuilder do use for output
|
||||
* @param definitions all inline definitions to display
|
||||
* @param uniquePrefix unique prefix to prepend to inline object names to enforce unicity
|
||||
*/
|
||||
private void inlineDefinitions(MarkupDocBuilder markupDocBuilder, List<ObjectType> definitions, String uniquePrefix) {
|
||||
if (CollectionUtils.isNotEmpty(definitions)) {
|
||||
for (ObjectType definition : definitions) {
|
||||
addInlineDefinitionTitle(markupDocBuilder, definition.getName(), definition.getUniqueName());
|
||||
|
||||
List<ObjectType> localDefinitions = new ArrayList<>();
|
||||
propertiesTableComponent.apply(markupDocBuilder, PropertiesTableComponent.parameters(
|
||||
definition.getProperties(),
|
||||
uniquePrefix,
|
||||
localDefinitions
|
||||
));
|
||||
for (ObjectType localDefinition : localDefinitions)
|
||||
inlineDefinitions(markupDocBuilder, Collections.singletonList(localDefinition), localDefinition.getUniqueName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buildConsumesSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
List<String> consumes = operation.getOperation().getConsumes();
|
||||
if (CollectionUtils.isNotEmpty(consumes)) {
|
||||
consumesComponent.apply(markupDocBuilder, ConsumesComponent.parameters(consumes,
|
||||
getSectionTitleLevel()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buildProducesSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
List<String> produces = operation.getOperation().getProduces();
|
||||
if (CollectionUtils.isNotEmpty(produces)) {
|
||||
producesComponent.apply(markupDocBuilder, ProducesComponent.parameters(produces,
|
||||
getSectionTitleLevel()));
|
||||
}
|
||||
}
|
||||
|
||||
private void buildTagsSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
List<String> tags = operation.getOperation().getTags();
|
||||
if (CollectionUtils.isNotEmpty(tags)) {
|
||||
buildSectionTitle(markupDocBuilder, labels.getLabel(TAGS));
|
||||
if (config.getTagOrdering() != null) {
|
||||
Collections.sort(tags, config.getTagOrdering());
|
||||
}
|
||||
markupDocBuilder.unorderedList(tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the security section of a Swagger Operation.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildSecuritySchemeSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
if (config.isPathSecuritySectionEnabled()) {
|
||||
securitySchemeComponent.apply(markupDocBuilder, SecuritySchemeComponent.parameters(
|
||||
operation,
|
||||
getSectionTitleLevel()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the title level for sections
|
||||
*/
|
||||
private int getSectionTitleLevel() {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
return 3;
|
||||
} else {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the example section of a Swagger Operation.
|
||||
*
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildExamplesSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
|
||||
Map<String, Object> generatedRequestExampleMap = ExamplesUtil.generateRequestExampleMap(config.isGeneratedExamplesEnabled(), operation, definitions, definitionDocumentResolver, markupDocBuilder);
|
||||
Map<String, Object> generatedResponseExampleMap = ExamplesUtil.generateResponseExampleMap(config.isGeneratedExamplesEnabled(), operation, definitions, definitionDocumentResolver, markupDocBuilder);
|
||||
|
||||
exampleMap(markupDocBuilder, generatedRequestExampleMap, labels.getLabel(EXAMPLE_REQUEST), labels.getLabel(REQUEST));
|
||||
exampleMap(markupDocBuilder, generatedResponseExampleMap, labels.getLabel(EXAMPLE_RESPONSE), labels.getLabel(RESPONSE));
|
||||
}
|
||||
|
||||
private void exampleMap(MarkupDocBuilder markupDocBuilder, Map<String, Object> exampleMap, String operationSectionTitle, String sectionTitle) {
|
||||
if (exampleMap.size() > 0) {
|
||||
buildSectionTitle(markupDocBuilder, operationSectionTitle);
|
||||
for (Map.Entry<String, Object> entry : exampleMap.entrySet()) {
|
||||
buildExampleTitle(markupDocBuilder, sectionTitle + " " + entry.getKey());
|
||||
markupDocBuilder.listingBlock(Json.pretty(entry.getValue()), "json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a example title to the document.
|
||||
*
|
||||
* @param title the section title
|
||||
*/
|
||||
private void buildExampleTitle(MarkupDocBuilder markupDocBuilder, String title) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
markupDocBuilder.sectionTitleLevel4(title);
|
||||
} else {
|
||||
markupDocBuilder.sectionTitleLevel5(title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply extension context to all OperationsContentExtension.
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyPathsDocumentExtension(PathsDocumentExtension.Context context) {
|
||||
extensionRegistry.getPathsDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.literalText;
|
||||
|
||||
public class ProducesComponent extends MarkupComponent<ProducesComponent.Parameters> {
|
||||
|
||||
|
||||
public ProducesComponent(Swagger2MarkupConverter.Context context){
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final List<String> produces;
|
||||
private final int titleLevel;
|
||||
|
||||
public Parameters(List<String> produces, int titleLevel){
|
||||
this.produces = Validate.notNull(produces, "Produces must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public static ProducesComponent.Parameters parameters(List<String> consumes,
|
||||
int titleLevel){
|
||||
return new ProducesComponent.Parameters(consumes, titleLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params){
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.PRODUCES));
|
||||
markupDocBuilder.unorderedList(params.produces.stream()
|
||||
.map(value -> literalText(markupDocBuilder, value)).collect(Collectors.toList()));
|
||||
return markupDocBuilder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
import ch.netzwerg.paleo.ColumnIds;
|
||||
import ch.netzwerg.paleo.StringColumn;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.type.Type;
|
||||
import io.github.swagger2markup.internal.adapter.PropertyAdapter;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.InlineSchemaUtils.createInlineType;
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toSortedMap;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
|
||||
public class PropertiesTableComponent extends MarkupComponent<PropertiesTableComponent.Parameters> {
|
||||
|
||||
|
||||
private final DocumentResolver definitionDocumentResolver;
|
||||
private final TableComponent tableComponent;
|
||||
|
||||
/**
|
||||
* Build a generic property table
|
||||
*
|
||||
* @param definitionDocumentResolver definition document resolver to apply to property type cross-reference
|
||||
*/
|
||||
public PropertiesTableComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionDocumentResolver){
|
||||
super(context);
|
||||
this.definitionDocumentResolver = definitionDocumentResolver;
|
||||
this.tableComponent = new TableComponent(context);
|
||||
}
|
||||
|
||||
public static PropertiesTableComponent.Parameters parameters(Map<String, Property> properties,
|
||||
String parameterName,
|
||||
List<ObjectType> inlineDefinitions){
|
||||
return new PropertiesTableComponent.Parameters(properties, parameterName, inlineDefinitions);
|
||||
}
|
||||
|
||||
|
||||
public static class Parameters {
|
||||
private final Map<String, Property> properties;
|
||||
private final String parameterName;
|
||||
private final List<ObjectType> inlineDefinitions;
|
||||
|
||||
public Parameters(Map<String, Property> properties,
|
||||
String parameterName,
|
||||
List<ObjectType> inlineDefinitions){
|
||||
|
||||
this.properties = Validate.notNull(properties, "Properties must not be null");
|
||||
this.parameterName = Validate.notBlank(parameterName, "ParameterName must not be blank");
|
||||
this.inlineDefinitions = Validate.notNull(inlineDefinitions, "InlineDefinitions must not be null");
|
||||
}
|
||||
}
|
||||
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params){
|
||||
StringColumn.Builder nameColumnBuilder = StringColumn.builder(ColumnIds.StringColumnId.of(labels.getLabel(NAME_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "3");
|
||||
StringColumn.Builder descriptionColumnBuilder = StringColumn.builder(ColumnIds.StringColumnId.of(labels.getLabel(DESCRIPTION_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "11")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
StringColumn.Builder schemaColumnBuilder = StringColumn.builder(ColumnIds.StringColumnId.of(labels.getLabel(SCHEMA_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "4")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
Map<String, Property> properties = params.properties;
|
||||
if (MapUtils.isNotEmpty(properties)) {
|
||||
Map<String, Property> sortedProperties = toSortedMap(properties, config.getPropertyOrdering());
|
||||
sortedProperties.forEach((String propertyName, Property property) -> {
|
||||
PropertyAdapter propertyAdapter = new PropertyAdapter(property);
|
||||
Type propertyType = propertyAdapter.getType(definitionDocumentResolver);
|
||||
|
||||
if (config.isInlineSchemaEnabled()) {
|
||||
propertyType = createInlineType(propertyType, propertyName, params.parameterName + " " + propertyName, params.inlineDefinitions);
|
||||
}
|
||||
|
||||
Optional<Object> optionalExample = propertyAdapter.getExample(config.isGeneratedExamplesEnabled(), markupDocBuilder);
|
||||
Optional<Object> optionalDefaultValue = propertyAdapter.getDefaultValue();
|
||||
Optional<Integer> optionalMaxLength = propertyAdapter.getMaxlength();
|
||||
Optional<Integer> optionalMinLength = propertyAdapter.getMinlength();
|
||||
Optional<String> optionalPattern = propertyAdapter.getPattern();
|
||||
Optional<Number> optionalMinValue = propertyAdapter.getMin();
|
||||
boolean exclusiveMin = propertyAdapter.getExclusiveMin();
|
||||
Optional<Number> optionalMaxValue = propertyAdapter.getMax();
|
||||
boolean exclusiveMax = propertyAdapter.getExclusiveMax();
|
||||
|
||||
MarkupDocBuilder propertyNameContent = copyMarkupDocBuilder(markupDocBuilder);
|
||||
propertyNameContent.boldTextLine(propertyName, true);
|
||||
if (property.getRequired())
|
||||
propertyNameContent.italicText(labels.getLabel(FLAGS_REQUIRED).toLowerCase());
|
||||
else
|
||||
propertyNameContent.italicText(labels.getLabel(FLAGS_OPTIONAL).toLowerCase());
|
||||
if (propertyAdapter.getReadOnly()) {
|
||||
propertyNameContent.newLine(true);
|
||||
propertyNameContent.italicText(labels.getLabel(FLAGS_READ_ONLY).toLowerCase());
|
||||
}
|
||||
|
||||
MarkupDocBuilder descriptionContent = copyMarkupDocBuilder(markupDocBuilder);
|
||||
String description = markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, property.getDescription());
|
||||
if (isNotBlank(description))
|
||||
descriptionContent.text(description);
|
||||
|
||||
if (optionalDefaultValue.isPresent()) {
|
||||
if (isNotBlank(descriptionContent.toString())) {
|
||||
descriptionContent.newLine(true);
|
||||
}
|
||||
descriptionContent.boldText(labels.getLabel(DEFAULT_COLUMN)).text(COLON).literalText(Json.pretty(optionalDefaultValue.get()));
|
||||
}
|
||||
|
||||
if (optionalMinLength.isPresent() && optionalMaxLength.isPresent()) {
|
||||
// combination of minlength/maxlength
|
||||
Integer minLength = optionalMinLength.get();
|
||||
Integer maxLength = optionalMaxLength.get();
|
||||
|
||||
if (isNotBlank(descriptionContent.toString())) {
|
||||
descriptionContent.newLine(true);
|
||||
}
|
||||
|
||||
String lengthRange = minLength + " - " + maxLength;
|
||||
if (minLength.equals(maxLength)) {
|
||||
lengthRange = minLength.toString();
|
||||
}
|
||||
|
||||
descriptionContent.boldText(labels.getLabel(LENGTH_COLUMN)).text(COLON).literalText(lengthRange);
|
||||
|
||||
} else {
|
||||
if (optionalMinLength.isPresent()) {
|
||||
if (isNotBlank(descriptionContent.toString())) {
|
||||
descriptionContent.newLine(true);
|
||||
}
|
||||
descriptionContent.boldText(labels.getLabel(MINLENGTH_COLUMN)).text(COLON).literalText(optionalMinLength.get().toString());
|
||||
}
|
||||
|
||||
if (optionalMaxLength.isPresent()) {
|
||||
if (isNotBlank(descriptionContent.toString())) {
|
||||
descriptionContent.newLine(true);
|
||||
}
|
||||
descriptionContent.boldText(labels.getLabel(MAXLENGTH_COLUMN)).text(COLON).literalText(optionalMaxLength.get().toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (optionalPattern.isPresent()) {
|
||||
if (isNotBlank(descriptionContent.toString())) {
|
||||
descriptionContent.newLine(true);
|
||||
}
|
||||
descriptionContent.boldText(labels.getLabel(PATTERN_COLUMN)).text(COLON).literalText(Json.pretty(optionalPattern.get()));
|
||||
}
|
||||
|
||||
if (optionalMinValue.isPresent()) {
|
||||
if (isNotBlank(descriptionContent.toString())) {
|
||||
descriptionContent.newLine(true);
|
||||
}
|
||||
String minValueColumn = exclusiveMin ? labels.getLabel(MINVALUE_EXCLUSIVE_COLUMN) : labels.getLabel(MINVALUE_COLUMN);
|
||||
descriptionContent.boldText(minValueColumn).text(COLON).literalText(optionalMinValue.get().toString());
|
||||
}
|
||||
|
||||
if (optionalMaxValue.isPresent()) {
|
||||
if (isNotBlank(descriptionContent.toString())) {
|
||||
descriptionContent.newLine(true);
|
||||
}
|
||||
String maxValueColumn = exclusiveMax ? labels.getLabel(MAXVALUE_EXCLUSIVE_COLUMN) : labels.getLabel(MAXVALUE_COLUMN);
|
||||
descriptionContent.boldText(maxValueColumn).text(COLON).literalText(optionalMaxValue.get().toString());
|
||||
}
|
||||
|
||||
if (optionalExample.isPresent()) {
|
||||
if (isNotBlank(description) || optionalDefaultValue.isPresent()) {
|
||||
descriptionContent.newLine(true);
|
||||
}
|
||||
descriptionContent.boldText(labels.getLabel(EXAMPLE_COLUMN)).text(COLON).literalText(Json.pretty(optionalExample.get()));
|
||||
}
|
||||
|
||||
nameColumnBuilder.add(propertyNameContent.toString());
|
||||
descriptionColumnBuilder.add(descriptionContent.toString());
|
||||
schemaColumnBuilder.add(propertyType.displaySchema(markupDocBuilder));
|
||||
});
|
||||
}
|
||||
|
||||
return tableComponent.apply(markupDocBuilder, TableComponent.parameters(
|
||||
nameColumnBuilder.build(),
|
||||
descriptionColumnBuilder.build(),
|
||||
schemaColumnBuilder.build()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import ch.netzwerg.paleo.StringColumn;
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.adapter.PropertyAdapter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.internal.type.ObjectType;
|
||||
import io.github.swagger2markup.internal.type.Type;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.PathsDocumentExtension;
|
||||
import io.swagger.models.Response;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static ch.netzwerg.paleo.ColumnIds.StringColumnId;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.InlineSchemaUtils.createInlineType;
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toSortedMap;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.*;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class ResponseComponent extends MarkupComponent<ResponseComponent.Parameters> {
|
||||
|
||||
private final TableComponent tableComponent;
|
||||
private final DocumentResolver definitionDocumentResolver;
|
||||
|
||||
public ResponseComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver definitionDocumentResolver){
|
||||
super(context);
|
||||
this.definitionDocumentResolver = Validate.notNull(definitionDocumentResolver, "DocumentResolver must not be null");
|
||||
this.tableComponent = new TableComponent(context);
|
||||
}
|
||||
|
||||
public static ResponseComponent.Parameters parameters(PathOperation operation,
|
||||
int titleLevel,
|
||||
List<ObjectType> inlineDefinitions){
|
||||
return new ResponseComponent.Parameters(operation, titleLevel, inlineDefinitions);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final PathOperation operation;
|
||||
private final int titleLevel;
|
||||
private final List<ObjectType> inlineDefinitions;
|
||||
|
||||
public Parameters(PathOperation operation,
|
||||
int titleLevel,
|
||||
List<ObjectType> inlineDefinitions){
|
||||
|
||||
this.operation = Validate.notNull(operation, "PathOperation must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
this.inlineDefinitions = Validate.notNull(inlineDefinitions, "InlineDefinitions must not be null");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params){
|
||||
PathOperation operation = params.operation;
|
||||
Map<String, Response> responses = operation.getOperation().getResponses();
|
||||
|
||||
MarkupDocBuilder responsesBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_RESPONSES_BEGIN, responsesBuilder, operation));
|
||||
if (MapUtils.isNotEmpty(responses)) {
|
||||
StringColumn.Builder httpCodeColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(Labels.HTTP_CODE_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "2");
|
||||
StringColumn.Builder descriptionColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(DESCRIPTION_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "14")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
StringColumn.Builder schemaColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(SCHEMA_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "4")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
|
||||
Map<String, Response> sortedResponses = toSortedMap(responses, config.getResponseOrdering());
|
||||
sortedResponses.forEach((String responseName, Response response) -> {
|
||||
String schemaContent = labels.getLabel(NO_CONTENT);
|
||||
if (response.getSchema() != null) {
|
||||
Property property = response.getSchema();
|
||||
Type type = new PropertyAdapter(property).getType(definitionDocumentResolver);
|
||||
|
||||
if (config.isInlineSchemaEnabled()) {
|
||||
type = createInlineType(type, labels.getLabel(Labels.RESPONSE) + " " + responseName, operation.getId() + " " + labels.getLabel(Labels.RESPONSE) + " " + responseName, params.inlineDefinitions);
|
||||
}
|
||||
|
||||
schemaContent = type.displaySchema(markupDocBuilder);
|
||||
}
|
||||
|
||||
MarkupDocBuilder descriptionBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
|
||||
descriptionBuilder.text(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, response.getDescription()));
|
||||
|
||||
Map<String, Property> headers = response.getHeaders();
|
||||
if (MapUtils.isNotEmpty(headers)) {
|
||||
descriptionBuilder.newLine(true).boldText(labels.getLabel(Labels.HEADERS_COLUMN)).text(COLON);
|
||||
for (Map.Entry<String, Property> header : headers.entrySet()) {
|
||||
descriptionBuilder.newLine(true);
|
||||
Property headerProperty = header.getValue();
|
||||
PropertyAdapter headerPropertyAdapter = new PropertyAdapter(headerProperty);
|
||||
Type propertyType = headerPropertyAdapter.getType(null);
|
||||
String headerDescription = markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, headerProperty.getDescription());
|
||||
Optional<Object> optionalDefaultValue = headerPropertyAdapter.getDefaultValue();
|
||||
|
||||
descriptionBuilder
|
||||
.literalText(header.getKey())
|
||||
.text(String.format(" (%s)", propertyType.displaySchema(markupDocBuilder)));
|
||||
|
||||
if (isNotBlank(headerDescription) || optionalDefaultValue.isPresent()) {
|
||||
descriptionBuilder.text(COLON);
|
||||
|
||||
if (isNotBlank(headerDescription) && !headerDescription.endsWith("."))
|
||||
headerDescription += ".";
|
||||
|
||||
descriptionBuilder.text(headerDescription);
|
||||
|
||||
if (optionalDefaultValue.isPresent()) {
|
||||
descriptionBuilder.text(" ").boldText(labels.getLabel(DEFAULT_COLUMN)).text(COLON).literalText(Json.pretty(optionalDefaultValue.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
httpCodeColumnBuilder.add(boldText(markupDocBuilder, responseName));
|
||||
descriptionColumnBuilder.add(descriptionBuilder.toString());
|
||||
schemaColumnBuilder.add(schemaContent);
|
||||
});
|
||||
|
||||
responsesBuilder = tableComponent.apply(responsesBuilder, TableComponent.parameters(httpCodeColumnBuilder.build(),
|
||||
descriptionColumnBuilder.build(),
|
||||
schemaColumnBuilder.build()));
|
||||
}
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_RESPONSES_END, responsesBuilder, operation));
|
||||
String responsesContent = responsesBuilder.toString();
|
||||
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_RESPONSES_BEFORE, markupDocBuilder, operation));
|
||||
if (isNotBlank(responsesContent)) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.RESPONSES));
|
||||
markupDocBuilder.text(responsesContent);
|
||||
}
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_RESPONSES_AFTER, markupDocBuilder, operation));
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all OperationsContentExtension.
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyPathsDocumentExtension(PathsDocumentExtension.Context context) {
|
||||
extensionRegistry.getPathsDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import ch.netzwerg.paleo.StringColumn;
|
||||
import com.google.common.base.Joiner;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.resolver.DocumentResolver;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.PathsDocumentExtension;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static ch.netzwerg.paleo.ColumnIds.StringColumnId;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.boldText;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.crossReference;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class SecuritySchemeComponent extends MarkupComponent<SecuritySchemeComponent.Parameters> {
|
||||
|
||||
private final Map<String, SecuritySchemeDefinition> securityDefinitions;
|
||||
private final DocumentResolver securityDocumentResolver;
|
||||
private final TableComponent tableComponent;
|
||||
|
||||
public SecuritySchemeComponent(Swagger2MarkupConverter.Context context,
|
||||
DocumentResolver securityDocumentResolver){
|
||||
super(context);
|
||||
this.securityDefinitions = context.getSwagger().getSecurityDefinitions();
|
||||
this.securityDocumentResolver = Validate.notNull(securityDocumentResolver, "SecurityDocumentResolver must not be null");
|
||||
this.tableComponent = new TableComponent(context);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final PathOperation operation;
|
||||
private final int titleLevel;
|
||||
|
||||
public Parameters(PathOperation operation,
|
||||
int titleLevel){
|
||||
this.operation = Validate.notNull(operation, "PathOperation must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public static SecuritySchemeComponent.Parameters parameters(PathOperation operation,
|
||||
int titleLevel){
|
||||
return new SecuritySchemeComponent.Parameters(operation, titleLevel);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params){
|
||||
PathOperation operation = params.operation;
|
||||
MarkupDocBuilder securityBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
List<Map<String, List<String>>> securitySchemes = operation.getOperation().getSecurity();
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_SECURITY_BEGIN, securityBuilder, operation));
|
||||
if (CollectionUtils.isNotEmpty(securitySchemes)) {
|
||||
StringColumn.Builder typeColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(TYPE_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "3");
|
||||
StringColumn.Builder nameColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(NAME_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "4");
|
||||
StringColumn.Builder scopeColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(SCOPES_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "13")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
|
||||
|
||||
for (Map<String, List<String>> securityScheme : securitySchemes) {
|
||||
for (Map.Entry<String, List<String>> securityEntry : securityScheme.entrySet()) {
|
||||
String securityKey = securityEntry.getKey();
|
||||
String type = labels.getLabel(UNKNOWN);
|
||||
if (securityDefinitions != null && securityDefinitions.containsKey(securityKey)) {
|
||||
type = securityDefinitions.get(securityKey).getType();
|
||||
}
|
||||
|
||||
typeColumnBuilder.add(boldText(markupDocBuilder, type));
|
||||
nameColumnBuilder.add(boldText(markupDocBuilder, crossReference(markupDocBuilder, securityDocumentResolver.apply(securityKey), securityKey, securityKey)));
|
||||
scopeColumnBuilder.add(Joiner.on(",").join(securityEntry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
securityBuilder = tableComponent.apply(securityBuilder, TableComponent.parameters(typeColumnBuilder.build(),
|
||||
nameColumnBuilder.build(),
|
||||
scopeColumnBuilder.build()));
|
||||
}
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_SECURITY_END, securityBuilder, operation));
|
||||
String securityContent = securityBuilder.toString();
|
||||
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_SECURITY_BEFORE, markupDocBuilder, operation));
|
||||
if (isNotBlank(securityContent)) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(SECURITY));
|
||||
markupDocBuilder.text(securityContent);
|
||||
}
|
||||
applyPathsDocumentExtension(new PathsDocumentExtension.Context(PathsDocumentExtension.Position.OPERATION_SECURITY_AFTER, markupDocBuilder, operation));
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all OperationsContentExtension.
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyPathsDocumentExtension(PathsDocumentExtension.Context context) {
|
||||
extensionRegistry.getPathsDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import ch.netzwerg.paleo.StringColumn;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.github.swagger2markup.spi.SecurityDocumentExtension;
|
||||
import io.swagger.models.auth.ApiKeyAuthDefinition;
|
||||
import io.swagger.models.auth.OAuth2Definition;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static ch.netzwerg.paleo.ColumnIds.StringColumnId;
|
||||
import static io.github.swagger2markup.Labels.*;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription;
|
||||
import static io.github.swagger2markup.spi.SecurityDocumentExtension.Position;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class SecuritySchemeDefinitionComponent extends MarkupComponent<SecuritySchemeDefinitionComponent.Parameters> {
|
||||
|
||||
private final TableComponent tableComponent;
|
||||
|
||||
public SecuritySchemeDefinitionComponent(Swagger2MarkupConverter.Context context){
|
||||
super(context);
|
||||
this.tableComponent = new TableComponent(context);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final String securitySchemeDefinitionName;
|
||||
private final SecuritySchemeDefinition securitySchemeDefinition;
|
||||
private final int titleLevel;
|
||||
|
||||
public Parameters(String securitySchemeDefinitionName,
|
||||
SecuritySchemeDefinition securitySchemeDefinition,
|
||||
int titleLevel){
|
||||
this.securitySchemeDefinitionName = Validate.notBlank(securitySchemeDefinitionName, "SecuritySchemeDefinitionName must not be empty");
|
||||
this.securitySchemeDefinition = Validate.notNull(securitySchemeDefinition, "SecuritySchemeDefinition must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public static SecuritySchemeDefinitionComponent.Parameters parameters(String securitySchemeDefinitionName,
|
||||
SecuritySchemeDefinition securitySchemeDefinition,
|
||||
int titleLevel){
|
||||
return new SecuritySchemeDefinitionComponent.Parameters(securitySchemeDefinitionName, securitySchemeDefinition, titleLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params){
|
||||
String securitySchemeDefinitionName = params.securitySchemeDefinitionName;
|
||||
SecuritySchemeDefinition securitySchemeDefinition = params.securitySchemeDefinition;
|
||||
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_BEFORE, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel(params.titleLevel, securitySchemeDefinitionName);
|
||||
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_BEGIN, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
String description = securitySchemeDefinition.getDescription();
|
||||
if (isNotBlank(description)) {
|
||||
markupDocBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
|
||||
}
|
||||
buildSecurityScheme(markupDocBuilder, securitySchemeDefinition);
|
||||
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_END, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
applySecurityDocumentExtension(new SecurityDocumentExtension.Context(Position.SECURITY_SCHEME_AFTER, markupDocBuilder, securitySchemeDefinitionName, securitySchemeDefinition));
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
private MarkupDocBuilder buildSecurityScheme(MarkupDocBuilder markupDocBuilder, SecuritySchemeDefinition securityScheme) {
|
||||
String type = securityScheme.getType();
|
||||
MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
|
||||
paragraphBuilder.italicText(labels.getLabel(TYPE)).textLine(COLON + type);
|
||||
|
||||
if (securityScheme instanceof ApiKeyAuthDefinition) {
|
||||
paragraphBuilder.italicText(labels.getLabel(NAME)).textLine(COLON + ((ApiKeyAuthDefinition) securityScheme).getName());
|
||||
paragraphBuilder.italicText(labels.getLabel(IN)).textLine(COLON + ((ApiKeyAuthDefinition) securityScheme).getIn());
|
||||
|
||||
return markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
} else if (securityScheme instanceof OAuth2Definition) {
|
||||
OAuth2Definition oauth2Scheme = (OAuth2Definition) securityScheme;
|
||||
String flow = oauth2Scheme.getFlow();
|
||||
paragraphBuilder.italicText(labels.getLabel(FLOW)).textLine(COLON + flow);
|
||||
if (isNotBlank(oauth2Scheme.getAuthorizationUrl())) {
|
||||
paragraphBuilder.italicText(labels.getLabel(AUTHORIZATION_URL)).textLine(COLON + oauth2Scheme.getAuthorizationUrl());
|
||||
}
|
||||
if (isNotBlank(oauth2Scheme.getTokenUrl())) {
|
||||
paragraphBuilder.italicText(labels.getLabel(TOKEN_URL)).textLine(COLON + oauth2Scheme.getTokenUrl());
|
||||
}
|
||||
StringColumn.Builder nameColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(NAME_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "3")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
StringColumn.Builder descriptionColumnBuilder = StringColumn.builder(StringColumnId.of(labels.getLabel(DESCRIPTION_COLUMN)))
|
||||
.putMetaData(TableComponent.WIDTH_RATIO, "17")
|
||||
.putMetaData(TableComponent.HEADER_COLUMN, "true");
|
||||
|
||||
if(oauth2Scheme.getScopes() != null) {
|
||||
for (Map.Entry<String, String> scope : oauth2Scheme.getScopes().entrySet()) {
|
||||
nameColumnBuilder.add(scope.getKey());
|
||||
descriptionColumnBuilder.add(scope.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
return tableComponent.apply(markupDocBuilder, TableComponent.parameters(nameColumnBuilder.build(),
|
||||
descriptionColumnBuilder.build()));
|
||||
} else {
|
||||
return markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all SecurityContentExtension
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applySecurityDocumentExtension(SecurityDocumentExtension.Context context) {
|
||||
extensionRegistry.getSecurityDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
import ch.netzwerg.paleo.DataFrame;
|
||||
import ch.netzwerg.paleo.StringColumn;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.markup.builder.MarkupLanguage;
|
||||
import io.github.swagger2markup.markup.builder.MarkupTableColumn;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import javaslang.collection.Array;
|
||||
import javaslang.collection.IndexedSeq;
|
||||
import javaslang.collection.List;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
public class TableComponent extends MarkupComponent<TableComponent.Parameters> {
|
||||
|
||||
public static final String WIDTH_RATIO = "widthRatio";
|
||||
public static final String HEADER_COLUMN = "headerColumn";
|
||||
|
||||
public TableComponent(Swagger2MarkupConverter.Context context){
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static TableComponent.Parameters parameters(StringColumn... columns){
|
||||
return new TableComponent.Parameters(columns);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final DataFrame dataFrame;
|
||||
public Parameters(StringColumn... columns){
|
||||
this.dataFrame = DataFrame.ofAll(List.of(columns).filter(TableComponent::isNotBlank));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isNotBlank(StringColumn column) {
|
||||
return !column.getValues().filter(StringUtils::isNotBlank).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params){
|
||||
DataFrame dataFrame = params.dataFrame;
|
||||
java.util.List<MarkupTableColumn> columnSpecs = dataFrame.getColumns().map(column -> {
|
||||
Integer widthRatio = Integer.valueOf(column.getMetaData().get(WIDTH_RATIO).getOrElse("0"));
|
||||
return new MarkupTableColumn(column.getId().getName())
|
||||
.withWidthRatio(widthRatio)
|
||||
.withHeaderColumn(Boolean.parseBoolean(column.getMetaData().get(HEADER_COLUMN).getOrElse("false")))
|
||||
.withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^" + widthRatio);
|
||||
}
|
||||
).toJavaList();
|
||||
|
||||
IndexedSeq<IndexedSeq<String>> columnValues = dataFrame.getColumns()
|
||||
.map(column -> ((StringColumn) column).getValues());
|
||||
|
||||
java.util.List<java.util.List<String>> cells = Array.range(0, dataFrame.getRowCount())
|
||||
.map(rowNumber -> columnValues.map(values -> values.get(rowNumber)).toJavaList()).toJavaList();
|
||||
|
||||
return markupDocBuilder.tableWithColumnSpecs(columnSpecs, cells);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Tag;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class TagsComponent extends MarkupComponent<TagsComponent.Parameters> {
|
||||
|
||||
public TagsComponent(Swagger2MarkupConverter.Context context){
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static TagsComponent.Parameters parameters(List<Tag> tags,
|
||||
int titleLevel){
|
||||
return new TagsComponent.Parameters(tags, titleLevel);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
|
||||
private final List<Tag> tags;
|
||||
private final int titleLevel;
|
||||
|
||||
public Parameters(List<Tag> tags,
|
||||
int titleLevel){
|
||||
this.tags = Validate.notNull(tags, "Tags must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params){
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.TAGS));
|
||||
|
||||
List<String> tagsList = params.tags.stream()
|
||||
.map(this::mapToString).collect(Collectors.toList());
|
||||
|
||||
if (config.getTagOrdering() != null)
|
||||
Collections.sort(tagsList, config.getTagOrdering());
|
||||
|
||||
markupDocBuilder.unorderedList(tagsList);
|
||||
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
private String mapToString(Tag tag){
|
||||
String name = tag.getName();
|
||||
String description = tag.getDescription();
|
||||
if(isNotBlank(description)){
|
||||
return name + COLON + description;
|
||||
}else{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Swagger;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.join;
|
||||
|
||||
public class UriSchemeComponent extends MarkupComponent<UriSchemeComponent.Parameters> {
|
||||
|
||||
|
||||
public UriSchemeComponent(Swagger2MarkupConverter.Context context){
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static UriSchemeComponent.Parameters parameters(Swagger swagger, int titleLevel){
|
||||
return new UriSchemeComponent.Parameters(swagger, titleLevel);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
|
||||
private final int titleLevel;
|
||||
private final Swagger swagger;
|
||||
|
||||
public Parameters(Swagger swagger, int titleLevel){
|
||||
|
||||
this.swagger = Validate.notNull(swagger);
|
||||
this.titleLevel = titleLevel;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params){
|
||||
Swagger swagger = params.swagger;
|
||||
if(isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) {
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.URI_SCHEME));
|
||||
MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
if (isNotBlank(swagger.getHost())) {
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.HOST))
|
||||
.textLine(COLON + swagger.getHost());
|
||||
}
|
||||
if (isNotBlank(swagger.getBasePath())) {
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.BASE_PATH))
|
||||
.textLine(COLON + swagger.getBasePath());
|
||||
}
|
||||
if (isNotEmpty(swagger.getSchemes())) {
|
||||
List<String> schemes = swagger.getSchemes().stream()
|
||||
.map(Enum::toString)
|
||||
.collect(Collectors.toList());
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.SCHEMES))
|
||||
.textLine(COLON + join(schemes, ", "));
|
||||
}
|
||||
markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
}
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.component;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Info;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class VersionInfoComponent extends MarkupComponent<VersionInfoComponent.Parameters> {
|
||||
|
||||
|
||||
|
||||
public VersionInfoComponent(Swagger2MarkupConverter.Context context){
|
||||
super(context);
|
||||
}
|
||||
|
||||
public static VersionInfoComponent.Parameters parameters(Info info,
|
||||
int titleLevel){
|
||||
return new VersionInfoComponent.Parameters(info, titleLevel);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
|
||||
private final int titleLevel;
|
||||
private final Info info;
|
||||
|
||||
public Parameters(
|
||||
Info info,
|
||||
int titleLevel){
|
||||
this.info = Validate.notNull(info, "Info must not be null");
|
||||
this.titleLevel = titleLevel;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params){
|
||||
String version = params.info.getVersion();
|
||||
if(isNotBlank(version)){
|
||||
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.CURRENT_VERSION));
|
||||
MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
paragraphBuilder.italicText(labels.getLabel(Labels.VERSION)).textLine(COLON + version);
|
||||
markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
|
||||
}
|
||||
return markupDocBuilder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.document;
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.component.DefinitionComponent;
|
||||
import io.github.swagger2markup.internal.resolver.DefinitionDocumentResolverDefault;
|
||||
import io.github.swagger2markup.internal.resolver.DefinitionDocumentResolverFromDefinition;
|
||||
import io.github.swagger2markup.internal.resolver.DefinitionDocumentNameResolver;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Model;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toSortedMap;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.crossReference;
|
||||
import static io.github.swagger2markup.spi.DefinitionsDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.DefinitionsDocumentExtension.Position;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class DefinitionsDocument extends MarkupComponent<DefinitionsDocument.Parameters> {
|
||||
|
||||
private static final String DEFINITIONS_ANCHOR = "definitions";
|
||||
|
||||
private static final List<String> IGNORED_DEFINITIONS = Collections.singletonList("Void");
|
||||
private final DefinitionComponent definitionComponent;
|
||||
private final DefinitionDocumentResolverDefault definitionDocumentResolverDefault;
|
||||
private final DefinitionDocumentNameResolver definitionDocumentNameResolver;
|
||||
|
||||
public DefinitionsDocument(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
if (config.isSeparatedDefinitionsEnabled()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated definition files is enabled.");
|
||||
}
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated definition files is disabled.");
|
||||
}
|
||||
}
|
||||
this.definitionDocumentNameResolver = new DefinitionDocumentNameResolver(context);
|
||||
this.definitionComponent = new DefinitionComponent(context, new DefinitionDocumentResolverFromDefinition(context));
|
||||
this.definitionDocumentResolverDefault = new DefinitionDocumentResolverDefault(context);
|
||||
}
|
||||
|
||||
public static DefinitionsDocument.Parameters parameters(Map<String, Model> definitions){
|
||||
return new DefinitionsDocument.Parameters(definitions);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final Map<String, Model> definitions;
|
||||
|
||||
public Parameters(Map<String, Model> definitions){
|
||||
this.definitions = definitions;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the definitions MarkupDocument.
|
||||
*
|
||||
* @return the definitions MarkupDocument
|
||||
*/
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, DefinitionsDocument.Parameters params) {
|
||||
Map<String, Model> definitions = params.definitions;
|
||||
if (MapUtils.isNotEmpty(definitions)) {
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_BEFORE, markupDocBuilder));
|
||||
buildDefinitionsTitle(markupDocBuilder, labels.getLabel(Labels.DEFINITIONS));
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_BEGIN, markupDocBuilder));
|
||||
buildDefinitionsSection(markupDocBuilder, definitions);
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_END, markupDocBuilder));
|
||||
applyDefinitionsDocumentExtension(new Context(Position.DOCUMENT_AFTER, markupDocBuilder));
|
||||
}
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
private void buildDefinitionsTitle(MarkupDocBuilder markupDocBuilder, String title) {
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel1(title, DEFINITIONS_ANCHOR);
|
||||
}
|
||||
|
||||
private void buildDefinitionsSection(MarkupDocBuilder markupDocBuilder, Map<String, Model> definitions) {
|
||||
Map<String, Model> sortedMap = toSortedMap(definitions, config.getDefinitionOrdering());
|
||||
sortedMap.forEach((String definitionName, Model model) -> {
|
||||
if(isNotBlank(definitionName)
|
||||
&& checkThatDefinitionIsNotInIgnoreList(definitionName)){
|
||||
buildDefinition(markupDocBuilder, definitionName, model);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all DefinitionsContentExtension
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyDefinitionsDocumentExtension(Context context) {
|
||||
extensionRegistry.getDefinitionsDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate definition files depending on the generation mode
|
||||
*
|
||||
* @param definitionName definition name to process
|
||||
* @param model definition model to process
|
||||
*/
|
||||
private void buildDefinition(MarkupDocBuilder markupDocBuilder, String definitionName, Model model) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Definition processed : '{}'", definitionName);
|
||||
}
|
||||
if (config.isSeparatedDefinitionsEnabled()) {
|
||||
MarkupDocBuilder defDocBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
applyDefinitionComponent(defDocBuilder, definitionName, model);
|
||||
Path definitionFile = context.getOutputPath().resolve(definitionDocumentNameResolver.apply(definitionName));
|
||||
defDocBuilder.writeToFileWithoutExtension(definitionFile, StandardCharsets.UTF_8);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Separate definition file produced : '{}'", definitionFile);
|
||||
}
|
||||
|
||||
definitionRef(markupDocBuilder, definitionName);
|
||||
|
||||
} else {
|
||||
applyDefinitionComponent(markupDocBuilder, definitionName, model);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the definition is not in the list of ignored definitions.
|
||||
*
|
||||
* @param definitionName the name of the definition
|
||||
* @return true if the definition can be processed
|
||||
*/
|
||||
private boolean checkThatDefinitionIsNotInIgnoreList(String definitionName) {
|
||||
return !IGNORED_DEFINITIONS.contains(definitionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a concrete definition
|
||||
*
|
||||
* @param markupDocBuilder the markupDocBuilder do use for output
|
||||
* @param definitionName the name of the definition
|
||||
* @param model the Swagger Model of the definition
|
||||
*/
|
||||
private void applyDefinitionComponent(MarkupDocBuilder markupDocBuilder, String definitionName, Model model) {
|
||||
definitionComponent.apply(markupDocBuilder, DefinitionComponent.parameters(
|
||||
definitionName,
|
||||
model,
|
||||
2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a cross-reference to a separated definition file.
|
||||
*
|
||||
* @param definitionName definition name to target
|
||||
*/
|
||||
private void definitionRef(MarkupDocBuilder markupDocBuilder, String definitionName) {
|
||||
buildDefinitionTitle(markupDocBuilder, crossReference(markupDocBuilder, definitionDocumentResolverDefault.apply(definitionName), definitionName, definitionName), "ref-" + definitionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds definition title
|
||||
|
||||
* @param markupDocBuilder the markupDocBuilder do use for output
|
||||
* @param title definition title
|
||||
* @param anchor optional anchor (null => auto-generate from title)
|
||||
*/
|
||||
private void buildDefinitionTitle(MarkupDocBuilder markupDocBuilder, String title, String anchor) {
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel2(title, anchor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.document;
|
||||
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.component.*;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Contact;
|
||||
import io.swagger.models.Info;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.Tag;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.markupDescription;
|
||||
import static io.github.swagger2markup.spi.OverviewDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.OverviewDocumentExtension.Position;
|
||||
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
public class OverviewDocument extends MarkupComponent<OverviewDocument.Parameters> {
|
||||
|
||||
private static final String OVERVIEW_ANCHOR = "overview";
|
||||
public static final int SECTION_TITLE_LEVEL = 2;
|
||||
private final VersionInfoComponent versionInfoComponent;
|
||||
private final ContactInfoComponent contactInfoComponent;
|
||||
private final LicenseInfoComponent licenseInfoComponent;
|
||||
private final UriSchemeComponent uriSchemeComponent;
|
||||
private final TagsComponent tagsComponent;
|
||||
private final ProducesComponent producesComponent;
|
||||
private final ConsumesComponent consumesComponent;
|
||||
|
||||
public OverviewDocument(Swagger2MarkupConverter.Context context){
|
||||
super(context);
|
||||
versionInfoComponent = new VersionInfoComponent(context);
|
||||
contactInfoComponent = new ContactInfoComponent(context);
|
||||
licenseInfoComponent = new LicenseInfoComponent(context);
|
||||
uriSchemeComponent = new UriSchemeComponent(context);
|
||||
tagsComponent = new TagsComponent(context);
|
||||
producesComponent = new ProducesComponent(context);
|
||||
consumesComponent = new ConsumesComponent(context);
|
||||
}
|
||||
|
||||
public static OverviewDocument.Parameters parameters(Swagger swagger){
|
||||
return new OverviewDocument.Parameters(swagger);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final Swagger swagger;
|
||||
|
||||
public Parameters(Swagger swagger){
|
||||
this.swagger = Validate.notNull(swagger, "Swagger must not be null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the overview MarkupDocument.
|
||||
*
|
||||
* @return the overview MarkupDocument
|
||||
*/
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, OverviewDocument.Parameters params) {
|
||||
Swagger swagger = params.swagger;
|
||||
Info info = swagger.getInfo();
|
||||
buildDocumentTitle(markupDocBuilder, info.getTitle());
|
||||
applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEFORE, markupDocBuilder));
|
||||
buildOverviewTitle(markupDocBuilder, labels.getLabel(Labels.OVERVIEW));
|
||||
applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEGIN, markupDocBuilder));
|
||||
buildDescriptionParagraph(markupDocBuilder, info.getDescription());
|
||||
buildVersionInfoSection(markupDocBuilder, info);
|
||||
buildContactInfoSection(markupDocBuilder, info.getContact());
|
||||
buildLicenseInfoSection(markupDocBuilder, info);
|
||||
buildUriSchemeSection(markupDocBuilder, swagger);
|
||||
buildTagsSection(markupDocBuilder, swagger.getTags());
|
||||
buildConsumesSection(markupDocBuilder, swagger.getConsumes());
|
||||
buildProducesSection(markupDocBuilder, swagger.getProduces());
|
||||
applyOverviewDocumentExtension(new Context(Position.DOCUMENT_END, markupDocBuilder));
|
||||
applyOverviewDocumentExtension(new Context(Position.DOCUMENT_AFTER, markupDocBuilder));
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
private void buildDocumentTitle(MarkupDocBuilder markupDocBuilder, String title) {
|
||||
markupDocBuilder.documentTitle(title);
|
||||
}
|
||||
|
||||
private void buildOverviewTitle(MarkupDocBuilder markupDocBuilder, String title) {
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel1(title, OVERVIEW_ANCHOR);
|
||||
}
|
||||
|
||||
void buildDescriptionParagraph(MarkupDocBuilder markupDocBuilder, String description) {
|
||||
if (isNotBlank(description)) {
|
||||
markupDocBuilder.paragraph(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, description));
|
||||
}
|
||||
}
|
||||
|
||||
private void buildVersionInfoSection(MarkupDocBuilder markupDocBuilder, Info info) {
|
||||
if (info != null) {
|
||||
versionInfoComponent.apply(markupDocBuilder, VersionInfoComponent.parameters(info, SECTION_TITLE_LEVEL));
|
||||
}
|
||||
}
|
||||
|
||||
private void buildContactInfoSection(MarkupDocBuilder markupDocBuilder, Contact contact) {
|
||||
if(contact != null){
|
||||
contactInfoComponent.apply(markupDocBuilder, ContactInfoComponent.parameters(contact, SECTION_TITLE_LEVEL));
|
||||
}
|
||||
}
|
||||
|
||||
private void buildLicenseInfoSection(MarkupDocBuilder markupDocBuilder, Info info) {
|
||||
if (info != null) {
|
||||
licenseInfoComponent.apply(markupDocBuilder, LicenseInfoComponent.parameters(info, SECTION_TITLE_LEVEL));
|
||||
}
|
||||
}
|
||||
|
||||
private void buildUriSchemeSection(MarkupDocBuilder markupDocBuilder, Swagger swagger) {
|
||||
uriSchemeComponent.apply(markupDocBuilder, UriSchemeComponent.parameters(swagger, SECTION_TITLE_LEVEL));
|
||||
}
|
||||
|
||||
private void buildTagsSection(MarkupDocBuilder markupDocBuilder, List<Tag> tags) {
|
||||
if(isNotEmpty(tags)){
|
||||
tagsComponent.apply(markupDocBuilder, TagsComponent.parameters(tags, SECTION_TITLE_LEVEL));
|
||||
}
|
||||
}
|
||||
|
||||
private void buildConsumesSection(MarkupDocBuilder markupDocBuilder, List<String> consumes) {
|
||||
if (isNotEmpty(consumes)) {
|
||||
consumesComponent.apply(markupDocBuilder, ConsumesComponent.parameters(consumes, SECTION_TITLE_LEVEL));;
|
||||
}
|
||||
}
|
||||
|
||||
private void buildProducesSection(MarkupDocBuilder markupDocBuilder, List<String> produces) {
|
||||
if (isNotEmpty(produces)) {
|
||||
producesComponent.apply(markupDocBuilder, ProducesComponent.parameters(produces, SECTION_TITLE_LEVEL));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all OverviewContentExtension
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyOverviewDocumentExtension(Context context) {
|
||||
extensionRegistry.getOverviewDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.document;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import io.github.swagger2markup.GroupBy;
|
||||
import io.github.swagger2markup.Labels;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.component.PathOperationComponent;
|
||||
import io.github.swagger2markup.internal.resolver.DefinitionDocumentResolverFromOperation;
|
||||
import io.github.swagger2markup.internal.resolver.OperationDocumentNameResolver;
|
||||
import io.github.swagger2markup.internal.resolver.OperationDocumentResolverDefault;
|
||||
import io.github.swagger2markup.internal.resolver.SecurityDocumentResolver;
|
||||
import io.github.swagger2markup.internal.utils.PathUtils;
|
||||
import io.github.swagger2markup.internal.utils.TagUtils;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Tag;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.copyMarkupDocBuilder;
|
||||
import static io.github.swagger2markup.internal.utils.MarkupDocBuilderUtils.crossReference;
|
||||
import static io.github.swagger2markup.spi.PathsDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.PathsDocumentExtension.Position;
|
||||
import static io.github.swagger2markup.utils.IOUtils.normalizeName;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class PathsDocument extends MarkupComponent<PathsDocument.Parameters> {
|
||||
|
||||
private static final String PATHS_ANCHOR = "paths";
|
||||
private final PathOperationComponent pathOperationComponent;
|
||||
private final OperationDocumentNameResolver operationDocumentNameResolver;
|
||||
private final OperationDocumentResolverDefault operationDocumentResolverDefault;
|
||||
|
||||
public PathsDocument(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
this.pathOperationComponent = new PathOperationComponent(context,
|
||||
new DefinitionDocumentResolverFromOperation(context),
|
||||
new SecurityDocumentResolver(context));
|
||||
this.operationDocumentNameResolver = new OperationDocumentNameResolver(context);
|
||||
this.operationDocumentResolverDefault = new OperationDocumentResolverDefault(context);
|
||||
|
||||
if (config.isGeneratedExamplesEnabled()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Generate examples is enabled.");
|
||||
}
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Generate examples is disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.isSeparatedOperationsEnabled()) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated operation files is enabled.");
|
||||
}
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create separated operation files is disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static PathsDocument.Parameters parameters(Map<String, Path> paths){
|
||||
return new PathsDocument.Parameters(paths);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final Map<String, Path> paths;
|
||||
|
||||
public Parameters(Map<String, Path> paths){
|
||||
this.paths = paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the paths MarkupDocument.
|
||||
*
|
||||
* @return the paths MarkupDocument
|
||||
*/
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, PathsDocument.Parameters params) {
|
||||
Map<String, Path> paths = params.paths;
|
||||
if (MapUtils.isNotEmpty(paths)) {
|
||||
applyPathsDocumentExtension(new Context(Position.DOCUMENT_BEFORE, markupDocBuilder));
|
||||
buildPathsTitle(markupDocBuilder);
|
||||
applyPathsDocumentExtension(new Context(Position.DOCUMENT_BEGIN, markupDocBuilder));
|
||||
buildsPathsSection(markupDocBuilder, paths);
|
||||
applyPathsDocumentExtension(new Context(Position.DOCUMENT_END, markupDocBuilder));
|
||||
applyPathsDocumentExtension(new Context(Position.DOCUMENT_AFTER, markupDocBuilder));
|
||||
}
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the paths section. Groups the paths either as-is or by tags.
|
||||
*
|
||||
* @param paths the Swagger paths
|
||||
*/
|
||||
private void buildsPathsSection(MarkupDocBuilder markupDocBuilder, Map<String, Path> paths) {
|
||||
List<PathOperation> pathOperations = PathUtils.toPathOperationsList(paths, getBasePath(), config.getOperationOrdering());
|
||||
if (CollectionUtils.isNotEmpty(pathOperations)) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
pathOperations.forEach(operation -> buildOperation(markupDocBuilder, operation));
|
||||
} else {
|
||||
Validate.notEmpty(context.getSwagger().getTags(), "Tags must not be empty, when operations are grouped by tags");
|
||||
// Group operations by tag
|
||||
Multimap<String, PathOperation> operationsGroupedByTag = TagUtils.groupOperationsByTag(pathOperations, config.getOperationOrdering());
|
||||
|
||||
Map<String, Tag> tagsMap = TagUtils.toSortedMap(context.getSwagger().getTags(), config.getTagOrdering());
|
||||
|
||||
tagsMap.forEach((String tagName, Tag tag) -> {
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel2(WordUtils.capitalize(tagName), tagName + "_resource");
|
||||
String description = tag.getDescription();
|
||||
if(StringUtils.isNotBlank(description)){
|
||||
markupDocBuilder.paragraph(description);
|
||||
}
|
||||
operationsGroupedByTag.get(tagName).forEach(operation -> buildOperation(markupDocBuilder, operation));
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the path title depending on the operationsGroupedBy configuration setting.
|
||||
*/
|
||||
private void buildPathsTitle(MarkupDocBuilder markupDocBuilder) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
buildPathsTitle(markupDocBuilder, labels.getLabel(Labels.PATHS));
|
||||
} else {
|
||||
buildPathsTitle(markupDocBuilder, labels.getLabel(Labels.RESOURCES));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the basePath which should be prepended to the relative path
|
||||
*
|
||||
* @return either the relative or the full path
|
||||
*/
|
||||
private String getBasePath() {
|
||||
if(config.isBasePathPrefixEnabled()){
|
||||
return StringUtils.defaultString(context.getSwagger().getBasePath());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private void buildPathsTitle(MarkupDocBuilder markupDocBuilder, String title) {
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel1(title, PATHS_ANCHOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all OperationsContentExtension.
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applyPathsDocumentExtension(Context context) {
|
||||
extensionRegistry.getPathsDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a path operation depending on generation mode.
|
||||
*
|
||||
* @param operation operation
|
||||
*/
|
||||
private void buildOperation(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
if (config.isSeparatedOperationsEnabled()) {
|
||||
MarkupDocBuilder pathDocBuilder = copyMarkupDocBuilder(markupDocBuilder);
|
||||
applyPathOperationComponent(pathDocBuilder, operation);
|
||||
java.nio.file.Path operationFile = context.getOutputPath().resolve(operationDocumentNameResolver.apply(operation));
|
||||
pathDocBuilder.writeToFileWithoutExtension(operationFile, StandardCharsets.UTF_8);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Separate operation file produced : '{}'", operationFile);
|
||||
}
|
||||
buildOperationRef(markupDocBuilder, operation);
|
||||
|
||||
} else {
|
||||
applyPathOperationComponent(markupDocBuilder, operation);
|
||||
}
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Operation processed : '{}' (normalized id = '{}')", operation, normalizeName(operation.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a path operation.
|
||||
*
|
||||
* @param markupDocBuilder the docbuilder do use for output
|
||||
* @param operation the Swagger Operation
|
||||
*
|
||||
*/
|
||||
private void applyPathOperationComponent(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
if (operation != null) {
|
||||
pathOperationComponent.apply(markupDocBuilder, PathOperationComponent.parameters(operation));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a cross-reference to a separated operation file
|
||||
*
|
||||
* @param markupDocBuilder the markupDocBuilder do use for output
|
||||
* @param operation the Swagger Operation
|
||||
*/
|
||||
private void buildOperationRef(MarkupDocBuilder markupDocBuilder, PathOperation operation) {
|
||||
buildOperationTitle(markupDocBuilder, crossReference(markupDocBuilder, operationDocumentResolverDefault.apply(operation), operation.getId(), operation.getTitle()), "ref-" + operation.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a operation title to the document.
|
||||
*
|
||||
* @param title the operation title
|
||||
* @param anchor optional anchor (null => auto-generate from title)
|
||||
*/
|
||||
private void buildOperationTitle(MarkupDocBuilder markupDocBuilder, String title, String anchor) {
|
||||
if (config.getPathsGroupedBy() == GroupBy.AS_IS) {
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel2(title, anchor);
|
||||
} else {
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel3(title, anchor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.document;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.internal.component.SecuritySchemeDefinitionComponent;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.spi.MarkupComponent;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.github.swagger2markup.Labels.SECURITY;
|
||||
import static io.github.swagger2markup.internal.utils.MapUtils.toSortedMap;
|
||||
import static io.github.swagger2markup.spi.SecurityDocumentExtension.Context;
|
||||
import static io.github.swagger2markup.spi.SecurityDocumentExtension.Position;
|
||||
|
||||
/**
|
||||
* @author Robert Winkler
|
||||
*/
|
||||
public class SecurityDocument extends MarkupComponent<SecurityDocument.Parameters> {
|
||||
|
||||
private static final String SECURITY_ANCHOR = "securityScheme";
|
||||
private final SecuritySchemeDefinitionComponent securitySchemeDefinitionComponent;
|
||||
|
||||
public SecurityDocument(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
this.securitySchemeDefinitionComponent = new SecuritySchemeDefinitionComponent(context);
|
||||
}
|
||||
|
||||
public static SecurityDocument.Parameters parameters(Map<String, SecuritySchemeDefinition> securitySchemeDefinitions){
|
||||
return new SecurityDocument.Parameters(securitySchemeDefinitions);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private final Map<String, SecuritySchemeDefinition> securitySchemeDefinitions;
|
||||
|
||||
public Parameters(Map<String, SecuritySchemeDefinition> securitySchemeDefinitions){
|
||||
this.securitySchemeDefinitions = securitySchemeDefinitions;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the security MarkupDocument.
|
||||
*
|
||||
* @return the security MarkupDocument
|
||||
*/
|
||||
@Override
|
||||
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, SecurityDocument.Parameters params) {
|
||||
Map<String, SecuritySchemeDefinition> definitions = params.securitySchemeDefinitions;
|
||||
if (MapUtils.isNotEmpty(definitions)) {
|
||||
applySecurityDocumentExtension(new Context(Position.DOCUMENT_BEFORE, markupDocBuilder));
|
||||
buildSecurityTitle(markupDocBuilder, labels.getLabel(SECURITY));
|
||||
applySecurityDocumentExtension(new Context(Position.DOCUMENT_BEGIN, markupDocBuilder));
|
||||
buildSecuritySchemeDefinitionsSection(markupDocBuilder, definitions);
|
||||
applySecurityDocumentExtension(new Context(Position.DOCUMENT_END, markupDocBuilder));
|
||||
applySecurityDocumentExtension(new Context(Position.DOCUMENT_AFTER, markupDocBuilder));
|
||||
}
|
||||
return markupDocBuilder;
|
||||
}
|
||||
|
||||
private void buildSecurityTitle(MarkupDocBuilder markupDocBuilder, String title) {
|
||||
markupDocBuilder.sectionTitleWithAnchorLevel1(title, SECURITY_ANCHOR);
|
||||
}
|
||||
|
||||
private void buildSecuritySchemeDefinitionsSection(MarkupDocBuilder markupDocBuilder, Map<String, SecuritySchemeDefinition> securitySchemes) {
|
||||
Map<String, SecuritySchemeDefinition> securitySchemeNames = toSortedMap(securitySchemes, null); // TODO : provide a dedicated ordering configuration for security schemes
|
||||
securitySchemeNames.forEach((String securitySchemeName, SecuritySchemeDefinition securityScheme) ->
|
||||
securitySchemeDefinitionComponent.apply(markupDocBuilder, SecuritySchemeDefinitionComponent.parameters(
|
||||
securitySchemeName, securityScheme, 2
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension context to all SecurityContentExtension
|
||||
*
|
||||
* @param context context
|
||||
*/
|
||||
private void applySecurityDocumentExtension(Context context) {
|
||||
extensionRegistry.getSecurityDocumentExtensions().forEach(extension -> extension.apply(context));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.resolver;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static io.github.swagger2markup.utils.IOUtils.normalizeName;
|
||||
|
||||
public class DefinitionDocumentNameResolver extends DocumentResolver {
|
||||
|
||||
public DefinitionDocumentNameResolver(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public String apply(String definitionName) {
|
||||
if (config.isSeparatedDefinitionsEnabled())
|
||||
return new File(config.getSeparatedDefinitionsFolder(), markupDocBuilder.addFileExtension(normalizeName(definitionName))).getPath();
|
||||
else
|
||||
return markupDocBuilder.addFileExtension(config.getDefinitionsDocument());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.resolver;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
/**
|
||||
* Default {@code DocumentResolver} functor
|
||||
*/
|
||||
public class DefinitionDocumentResolverDefault extends DocumentResolver {
|
||||
|
||||
private final DefinitionDocumentNameResolver definitionDocumentNameResolver;
|
||||
|
||||
public DefinitionDocumentResolverDefault(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
this.definitionDocumentNameResolver = new DefinitionDocumentNameResolver(context);
|
||||
}
|
||||
|
||||
public String apply(String definitionName) {
|
||||
if (!config.isInterDocumentCrossReferencesEnabled() || context.getOutputPath() == null)
|
||||
return null;
|
||||
else
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + definitionDocumentNameResolver.apply(definitionName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.resolver;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
import static io.github.swagger2markup.utils.IOUtils.normalizeName;
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
/**
|
||||
* Overrides definition document resolver functor for inter-document cross-references from definitions files.
|
||||
* This implementation simplifies the path between two definitions because all definitions are in the same path.
|
||||
*/
|
||||
public class DefinitionDocumentResolverFromDefinition extends DefinitionDocumentResolverDefault {
|
||||
|
||||
public DefinitionDocumentResolverFromDefinition(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public String apply(String definitionName) {
|
||||
String defaultResolver = super.apply(definitionName);
|
||||
|
||||
if (defaultResolver != null && config.isSeparatedDefinitionsEnabled())
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + markupDocBuilder.addFileExtension(normalizeName(definitionName));
|
||||
else
|
||||
return defaultResolver;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.github.swagger2markup.internal.resolver;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
/**
|
||||
* Overrides definition document resolver functor for inter-document cross-references from operations files.
|
||||
* This implementation adapt the relative paths to definitions files
|
||||
*/
|
||||
public class DefinitionDocumentResolverFromOperation extends DefinitionDocumentResolverDefault {
|
||||
|
||||
public DefinitionDocumentResolverFromOperation(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public String apply(String definitionName) {
|
||||
String defaultResolver = super.apply(definitionName);
|
||||
|
||||
if (defaultResolver != null && config.isSeparatedOperationsEnabled())
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + new File("..", defaultResolver).getPath();
|
||||
else
|
||||
return defaultResolver;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.swagger2markup.internal.resolver;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConfig;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import javaslang.Function1;
|
||||
|
||||
/**
|
||||
* A functor to return the document part of an inter-document cross-references, depending on the context.
|
||||
*/
|
||||
public abstract class DocumentResolver implements Function1<String, String> {
|
||||
|
||||
Swagger2MarkupConverter.Context context;
|
||||
MarkupDocBuilder markupDocBuilder;
|
||||
Swagger2MarkupConfig config;
|
||||
|
||||
public DocumentResolver(Swagger2MarkupConverter.Context context) {
|
||||
this.context = context;
|
||||
this.markupDocBuilder = context.createMarkupDocBuilder();
|
||||
this.config = context.getConfig();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.resolver;
|
||||
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static io.github.swagger2markup.utils.IOUtils.normalizeName;
|
||||
|
||||
public class OperationDocumentNameResolver extends OperationDocumentResolver {
|
||||
|
||||
public OperationDocumentNameResolver(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public String apply(PathOperation operation) {
|
||||
if (config.isSeparatedOperationsEnabled())
|
||||
return new File(config.getSeparatedOperationsFolder(), markupDocBuilder.addFileExtension(normalizeName(operation.getId()))).getPath();
|
||||
else
|
||||
return markupDocBuilder.addFileExtension(config.getPathsDocument());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.swagger2markup.internal.resolver;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConfig;
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import javaslang.Function1;
|
||||
|
||||
/**
|
||||
* A functor to return the document part of an inter-document cross-references, depending on the context.
|
||||
*/
|
||||
public abstract class OperationDocumentResolver implements Function1<PathOperation, String> {
|
||||
|
||||
Swagger2MarkupConverter.Context context;
|
||||
MarkupDocBuilder markupDocBuilder;
|
||||
Swagger2MarkupConfig config;
|
||||
|
||||
public OperationDocumentResolver(Swagger2MarkupConverter.Context context) {
|
||||
this.context = context;
|
||||
this.markupDocBuilder = context.createMarkupDocBuilder();
|
||||
this.config = context.getConfig();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.resolver;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
/**
|
||||
* Default {@code DocumentResolver} functor
|
||||
*/
|
||||
public class OperationDocumentResolverDefault extends OperationDocumentResolver {
|
||||
|
||||
private final OperationDocumentNameResolver operationDocumentNameResolver;
|
||||
|
||||
public OperationDocumentResolverDefault(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
this.operationDocumentNameResolver = new OperationDocumentNameResolver(context);
|
||||
}
|
||||
|
||||
public String apply(PathOperation operation) {
|
||||
if (!config.isInterDocumentCrossReferencesEnabled() || context.getOutputPath() == null)
|
||||
return null;
|
||||
else
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + operationDocumentNameResolver.apply(operation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.github.swagger2markup.internal.resolver;
|
||||
|
||||
import io.github.swagger2markup.Swagger2MarkupConverter;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
public class SecurityDocumentResolver extends DocumentResolver {
|
||||
|
||||
public SecurityDocumentResolver(Swagger2MarkupConverter.Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public String apply(String definitionName) {
|
||||
if (!config.isInterDocumentCrossReferencesEnabled() || context.getOutputPath() == null)
|
||||
return null;
|
||||
else
|
||||
return defaultString(config.getInterDocumentCrossReferencesPrefix()) + markupDocBuilder.addFileExtension(config.getSecurityDocument());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.swagger2markup.internal.type;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
/**
|
||||
* Array type abstraction
|
||||
*/
|
||||
public class ArrayType extends Type {
|
||||
|
||||
private String collectionFormat;
|
||||
private Type ofType;
|
||||
|
||||
public ArrayType(String name, Type ofType) {
|
||||
this(name, ofType, null);
|
||||
}
|
||||
|
||||
public ArrayType(String name, Type ofType, String collectionFormat) {
|
||||
super(name);
|
||||
this.collectionFormat = collectionFormat;
|
||||
this.ofType = ofType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displaySchema(MarkupDocBuilder docBuilder) {
|
||||
String ofTypeDisplay = ofType.displaySchema(docBuilder);
|
||||
if (isNotBlank(this.collectionFormat))
|
||||
return String.format("< %s > array(%s)", ofTypeDisplay, collectionFormat);
|
||||
else
|
||||
return String.format("< %s > array", ofTypeDisplay);
|
||||
}
|
||||
|
||||
public String getCollectionFormat() {
|
||||
return collectionFormat;
|
||||
}
|
||||
|
||||
public void setCollectionFormat(String collectionFormat) {
|
||||
this.collectionFormat = collectionFormat;
|
||||
}
|
||||
|
||||
public Type getOfType() {
|
||||
return ofType;
|
||||
}
|
||||
|
||||
public void setOfType(Type ofType) {
|
||||
this.ofType = ofType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.swagger2markup.internal.type;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
/**
|
||||
* Base type abstraction (string, integer, ...)
|
||||
*/
|
||||
public class BasicType extends Type {
|
||||
|
||||
/**
|
||||
* Basic type
|
||||
*/
|
||||
protected String type;
|
||||
protected String format;
|
||||
|
||||
public BasicType(String type, String name) {
|
||||
this(type, name, null);
|
||||
}
|
||||
|
||||
public BasicType(String type, String name, String format) {
|
||||
super(name);
|
||||
Validate.notBlank(type);
|
||||
this.type = type;
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displaySchema(MarkupDocBuilder docBuilder) {
|
||||
if (isNotBlank(this.format))
|
||||
return String.format("%s(%s)", this.type, this.format);
|
||||
else
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
public void setFormat(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.swagger2markup.internal.type;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.join;
|
||||
|
||||
/**
|
||||
* Enum type abstraction
|
||||
*/
|
||||
public class EnumType extends Type {
|
||||
|
||||
protected List<String> values;
|
||||
|
||||
public EnumType(String name, List<String> values) {
|
||||
super(name);
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displaySchema(MarkupDocBuilder docBuilder) {
|
||||
return String.format("enum (%s)", join(values, ", "));
|
||||
}
|
||||
|
||||
public List<String> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void setValues(List<String> values) {
|
||||
this.values = values;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2016 Robert Winkler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.github.swagger2markup.internal.type;
|
||||
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
|
||||
/**
|
||||
* Array type abstraction
|
||||
*/
|
||||
public class MapType extends Type {
|
||||
|
||||
private Type keyType = new BasicType("string", null);
|
||||
private Type valueType;
|
||||
|
||||
public MapType(String name, Type valueType) {
|
||||
super(name);
|
||||
this.valueType = valueType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displaySchema(MarkupDocBuilder docBuilder) {
|
||||
String keyTypeDisplay = keyType.displaySchema(docBuilder);
|
||||
return String.format("< %s, %s > map", keyTypeDisplay, valueType.displaySchema(docBuilder));
|
||||
}
|
||||
|
||||
public Type getKeyType() {
|
||||
return keyType;
|
||||
}
|
||||
|
||||
public Type getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
public void setValueType(Type valueType) {
|
||||
this.valueType = valueType;
|
||||
}
|
||||
}
|
||||