├── .gitignore
├── .travis.yml
├── README.md
├── conf
└── log4j.properties
├── generated
├── document.html
└── swagger-ui
│ └── swagger.json
├── pom.xml
├── src
└── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── kongchen
│ │ └── swagger
│ │ └── sample
│ │ └── wordnik
│ │ ├── data
│ │ ├── PetData.java
│ │ ├── StoreData.java
│ │ └── UserData.java
│ │ ├── exception
│ │ ├── ApiException.java
│ │ ├── BadRequestException.java
│ │ └── NotFoundException.java
│ │ ├── model
│ │ ├── ApiResponse.java
│ │ ├── Category.java
│ │ ├── Order.java
│ │ ├── Pet.java
│ │ ├── Tag.java
│ │ └── User.java
│ │ └── resource
│ │ ├── JavaRestResourceUtil.java
│ │ ├── PetResource.java
│ │ ├── PetStoreResource.java
│ │ └── UserResource.java
│ ├── resources
│ ├── logback.xml
│ └── securityDefinitions.json
│ └── webapp
│ └── WEB-INF
│ └── web.xml
└── templates
├── markdown.hbs
├── operation.hbs
├── security.hbs
└── strapdown.html.hbs
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | swagger-maven-example.iml
3 | target/
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk7
4 | - openjdk7
5 | - openjdk6
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Swagger Maven Plugin Example [](https://travis-ci.org/kongchen/swagger-maven-example)
2 |
3 | This project is an example of using [Swagger-maven-plugin](https://github.com/kongchen/swagger-maven-plugin).
4 |
5 | You can check the detail configuration in [pom.xml](https://github.com/kongchen/swagger-maven-example/blob/master/pom.xml#L40-L49)
6 |
7 | Clone the example in local and then launch:
8 | ```
9 | mvn compile
10 | ```
11 | You'll get the outputs in the */generated* folder.
12 |
13 | >If you wanna see something before clone, I've uploaded the output files, you can view swagger outputs at
14 | [here](https://github.com/kongchen/swagger-maven-example/blob/master/generated/swagger-ui), and
15 | [view the HTML output document](http://htmlpreview.github.io/?https://raw.github.com/kongchen/swagger-maven-example/master/generated/document.html)
16 |
17 | *Enjoy!*
18 |
--------------------------------------------------------------------------------
/conf/log4j.properties:
--------------------------------------------------------------------------------
1 | log4j.rootCategory=ERROR, CONSOLE, LOGFILE
2 |
3 | log4j.logger.com.wordnik=ERROR
4 | log4j.logger.org.atmosphere=ERROR
5 |
6 | # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
7 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
8 | log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
9 | log4j.appender.CONSOLE.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS Z} %c{1} - %m%n
10 |
11 | # LOGFILE is set to be a File appender using a PatternLayout.
12 | log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
13 | log4j.appender.LOGFILE.File=logs/wordnik.log
14 | log4j.appender.LOGFILE.Append=true
15 | log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
16 | log4j.appender.LOGFILE.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS Z} %c{1} - %m%n
17 | log4j.appender.LOGFILE.MaxFileSize=10MB
18 | log4j.appender.LOGFILE.MaxBackupIndex=10
19 |
--------------------------------------------------------------------------------
/generated/document.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
API Document
4 |
5 |
6 | #Swagger Maven Plugin Sample
7 |
8 |
9 | ## HTTP | HTTPS://petstore.swagger.wordnik.com/api
10 |
11 |
12 | This is a sample for swagger-maven-plugin
13 |
14 |
15 | [**Contact the developer**](mailto:kongchen@gmail.com)
16 |
17 |
18 | **Version** v1
19 |
20 | [**Terms of Service**](http://www.github.com/kongchen/swagger-maven-plugin)
21 |
22 | [**Apache 2.0**](http://www.apache.org/licenses/LICENSE-2.0.html)
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | # Security Definitions
32 |
33 |
34 | ### api_key
35 |
36 |
37 |
38 |
39 |
40 | type |
41 | apiKey |
42 |
43 |
44 |
45 |
46 | name |
47 | api_key |
48 |
49 |
50 |
51 |
52 | in |
53 | HEADER |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | ### petstore_auth
62 |
63 |
64 |
65 |
66 | type |
67 | oauth2 |
68 |
69 |
70 |
71 |
72 | authorizationUrl |
73 | http://swagger.io/api/oauth/dialog |
74 |
75 |
76 |
77 |
78 | flow |
79 | implicit |
80 |
81 |
82 |
83 |
84 |
85 | scopes |
86 |
87 | write:pets |
88 | modify pets in your account |
89 |
90 |
91 |
92 | read:pets |
93 | read your pets |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | # APIs
107 |
108 |
109 | ## /pet
110 |
111 |
112 |
113 |
114 | ### PUT
115 |
116 | Update an existing pet
117 |
118 |
119 |
120 |
121 |
122 |
123 | #### Security
124 |
125 |
126 |
127 |
128 | * petstore_auth
129 | * write:pets
130 | * read:pets
131 |
132 |
133 |
134 |
135 | #### Request
136 |
137 |
138 | **Content-Type: ** application/json, application/xml
139 |
140 | ##### Parameters
141 |
142 |
143 |
144 | Name |
145 | Located in |
146 | Required |
147 | Description |
148 | Default |
149 | Schema |
150 |
151 |
152 |
153 |
154 |
155 | body |
156 | body |
157 | yes |
158 | Pet object that needs to be added to the store |
159 | - |
160 |
161 |
162 |
163 | Pet
164 | |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 | #### Response
174 |
175 | **Content-Type: ** application/xml, application/json
176 |
177 |
178 | | Status Code | Reason | Response Model |
179 | |-------------|-------------|----------------|
180 | | 400 | Invalid ID supplied | - |
181 | | 404 | Pet not found | - |
182 | | 405 | Validation exception | - |
183 |
184 |
185 |
186 |
187 |
188 | ### POST
189 |
190 |
191 | Add a new pet to the store
192 |
193 |
194 |
195 |
196 |
197 |
198 | #### Security
199 |
200 |
201 |
202 |
203 | * petstore_auth
204 | * write:pets
205 | * read:pets
206 |
207 |
208 |
209 |
210 | #### Request
211 |
212 |
213 | **Content-Type: ** application/json, application/xml
214 |
215 | ##### Parameters
216 |
217 |
218 |
219 | Name |
220 | Located in |
221 | Required |
222 | Description |
223 | Default |
224 | Schema |
225 |
226 |
227 |
228 |
229 |
230 | body |
231 | body |
232 | yes |
233 | Pet object that needs to be added to the store |
234 | - |
235 |
236 |
237 |
238 | Pet
239 | |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 | #### Response
249 |
250 | **Content-Type: ** application/xml, application/json
251 |
252 |
253 | | Status Code | Reason | Response Model |
254 | |-------------|-------------|----------------|
255 | | 405 | Invalid input | - |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 | ## /pet/findByStatus
272 |
273 |
274 | ### GET
275 |
276 | Finds Pets by status
277 |
278 | Multiple status values can be provided with comma seperated strings
279 |
280 |
281 |
282 |
283 | #### Security
284 |
285 |
286 |
287 |
288 | * petstore_auth
289 | * write:pets
290 | * read:pets
291 |
292 |
293 |
294 |
295 | #### Request
296 |
297 |
298 |
299 | ##### Parameters
300 |
301 |
302 |
303 | Name |
304 | Located in |
305 | Required |
306 | Description |
307 | Default |
308 | Schema |
309 |
310 |
311 |
312 |
313 |
314 | status |
315 | query |
316 | yes |
317 | Status values that need to be considered for filter |
318 | - |
319 |
320 |
321 | Array[string] (csv) |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 | #### Response
332 |
333 | **Content-Type: ** application/xml, application/json
334 |
335 |
336 | | Status Code | Reason | Response Model |
337 | |-------------|-------------|----------------|
338 | | 200 | successful operation | Array[Pet]|
339 | | 400 | Invalid status value | - |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 | ## /pet/findByTags
359 |
360 |
361 | ### GET
362 |
363 | Finds Pets by tags
364 |
365 | Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
366 |
367 |
368 |
369 |
370 | #### Security
371 |
372 |
373 |
374 |
375 | * petstore_auth
376 | * write:pets
377 | * read:pets
378 |
379 |
380 |
381 |
382 | #### Request
383 |
384 |
385 |
386 | ##### Parameters
387 |
388 |
389 |
390 | Name |
391 | Located in |
392 | Required |
393 | Description |
394 | Default |
395 | Schema |
396 |
397 |
398 |
399 |
400 |
401 | tags |
402 | query |
403 | yes |
404 | Tags to filter by |
405 | - |
406 |
407 |
408 | Array[string] (csv) |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 | #### Response
419 |
420 | **Content-Type: ** application/xml, application/json
421 |
422 |
423 | | Status Code | Reason | Response Model |
424 | |-------------|-------------|----------------|
425 | | 200 | successful operation | Array[Pet]|
426 | | 400 | Invalid tag value | - |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 | ## /pet/{petId}
446 |
447 |
448 | ### GET
449 |
450 | Find pet by ID
451 |
452 | Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
453 |
454 |
455 |
456 |
457 | #### Security
458 |
459 |
460 |
461 |
462 | * api_key
463 |
464 |
465 |
466 |
467 | * petstore_auth
468 | * write:pets
469 | * read:pets
470 |
471 |
472 |
473 |
474 | #### Request
475 |
476 |
477 |
478 | ##### Parameters
479 |
480 |
481 |
482 | Name |
483 | Located in |
484 | Required |
485 | Description |
486 | Default |
487 | Schema |
488 |
489 |
490 |
491 |
492 |
493 | petId |
494 | path |
495 | yes |
496 | ID of pet that needs to be fetched |
497 | - |
498 |
499 |
500 | integer (int64) |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 | #### Response
511 |
512 | **Content-Type: ** application/xml, application/json
513 |
514 |
515 | | Status Code | Reason | Response Model |
516 | |-------------|-------------|----------------|
517 | | 200 | successful operation | Pet|
518 | | 400 | Invalid ID supplied | - |
519 | | 404 | Pet not found | - |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 | ### POST
528 |
529 |
530 | Updates a pet in the store with form data
531 |
532 |
533 |
534 |
535 |
536 |
537 | #### Security
538 |
539 |
540 |
541 |
542 | * petstore_auth
543 | * write:pets
544 | * read:pets
545 |
546 |
547 |
548 |
549 | #### Request
550 |
551 |
552 | **Content-Type: ** application/x-www-form-urlencoded
553 |
554 | ##### Parameters
555 |
556 |
557 |
558 | Name |
559 | Located in |
560 | Required |
561 | Description |
562 | Default |
563 | Schema |
564 |
565 |
566 |
567 |
568 |
569 | petId |
570 | path |
571 | yes |
572 | ID of pet that needs to be updated |
573 | - |
574 |
575 |
576 | string |
577 |
578 |
579 |
580 |
581 |
582 | name |
583 | formData |
584 | no |
585 | Updated name of the pet |
586 | - |
587 |
588 |
589 | string |
590 |
591 |
592 |
593 |
594 |
595 | status |
596 | formData |
597 | no |
598 | Updated status of the pet |
599 | - |
600 |
601 |
602 | string |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 | #### Response
613 |
614 | **Content-Type: ** application/xml, application/json
615 |
616 |
617 | | Status Code | Reason | Response Model |
618 | |-------------|-------------|----------------|
619 | | 405 | Invalid input | - |
620 |
621 |
622 |
623 |
624 |
625 |
626 | ### DELETE
627 |
628 | Deletes a pet
629 |
630 |
631 |
632 |
633 |
634 |
635 | #### Security
636 |
637 |
638 |
639 |
640 | * petstore_auth
641 | * write:pets
642 | * read:pets
643 |
644 |
645 |
646 |
647 | #### Request
648 |
649 |
650 |
651 | ##### Parameters
652 |
653 |
654 |
655 | Name |
656 | Located in |
657 | Required |
658 | Description |
659 | Default |
660 | Schema |
661 |
662 |
663 |
664 |
665 |
666 | api_key |
667 | header |
668 | no |
669 | |
670 | - |
671 |
672 |
673 | string |
674 |
675 |
676 |
677 |
678 |
679 | petId |
680 | path |
681 | yes |
682 | Pet id to delete |
683 | - |
684 |
685 |
686 | integer (int64) |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 |
695 |
696 | #### Response
697 |
698 | **Content-Type: ** application/xml, application/json
699 |
700 |
701 | | Status Code | Reason | Response Model |
702 | |-------------|-------------|----------------|
703 | | 400 | Invalid pet value | - |
704 |
705 |
706 |
707 |
708 |
709 |
710 |
711 |
712 |
713 |
714 |
715 |
716 | ## /store/order
717 |
718 |
719 |
720 |
721 |
722 |
723 | ### POST
724 |
725 |
726 | Place an order for a pet
727 |
728 |
729 |
730 |
731 |
732 |
733 |
734 |
735 |
736 | #### Request
737 |
738 |
739 |
740 | ##### Parameters
741 |
742 |
743 |
744 | Name |
745 | Located in |
746 | Required |
747 | Description |
748 | Default |
749 | Schema |
750 |
751 |
752 |
753 |
754 |
755 | body |
756 | body |
757 | yes |
758 | order placed for purchasing the pet |
759 | - |
760 |
761 |
762 |
763 | Order
764 | |
765 |
766 |
767 |
768 |
769 |
770 |
771 |
772 |
773 | #### Response
774 |
775 | **Content-Type: ** application/xml, application/json
776 |
777 |
778 | | Status Code | Reason | Response Model |
779 | |-------------|-------------|----------------|
780 | | 200 | successful operation | Order|
781 | | 400 | Invalid Order | - |
782 |
783 |
784 |
785 |
786 |
787 |
788 |
789 |
790 |
791 |
792 |
793 |
794 |
795 |
796 |
797 | ## /store/order/{orderId}
798 |
799 |
800 | ### GET
801 |
802 | Find purchase order by ID
803 |
804 | For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
805 |
806 |
807 |
808 |
809 |
810 |
811 |
812 | #### Request
813 |
814 |
815 |
816 | ##### Parameters
817 |
818 |
819 |
820 | Name |
821 | Located in |
822 | Required |
823 | Description |
824 | Default |
825 | Schema |
826 |
827 |
828 |
829 |
830 |
831 | orderId |
832 | path |
833 | yes |
834 | ID of pet that needs to be fetched |
835 | - |
836 |
837 |
838 | string |
839 |
840 |
841 |
842 |
843 |
844 |
845 |
846 |
847 |
848 | #### Response
849 |
850 | **Content-Type: ** application/xml, application/json
851 |
852 |
853 | | Status Code | Reason | Response Model |
854 | |-------------|-------------|----------------|
855 | | 200 | successful operation | Order|
856 | | 400 | Invalid ID supplied | - |
857 | | 404 | Order not found | - |
858 |
859 |
860 |
861 |
862 |
863 |
864 |
865 |
866 |
867 | ### DELETE
868 |
869 | Delete purchase order by ID
870 |
871 | For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
872 |
873 |
874 |
875 |
876 |
877 |
878 |
879 | #### Request
880 |
881 |
882 |
883 | ##### Parameters
884 |
885 |
886 |
887 | Name |
888 | Located in |
889 | Required |
890 | Description |
891 | Default |
892 | Schema |
893 |
894 |
895 |
896 |
897 |
898 | orderId |
899 | path |
900 | yes |
901 | ID of the order that needs to be deleted |
902 | - |
903 |
904 |
905 | string |
906 |
907 |
908 |
909 |
910 |
911 |
912 |
913 |
914 |
915 | #### Response
916 |
917 | **Content-Type: ** application/xml, application/json
918 |
919 |
920 | | Status Code | Reason | Response Model |
921 | |-------------|-------------|----------------|
922 | | 400 | Invalid ID supplied | - |
923 | | 404 | Order not found | - |
924 |
925 |
926 |
927 |
928 |
929 |
930 |
931 |
932 |
933 |
934 |
935 |
936 | ## /user
937 |
938 |
939 |
940 |
941 |
942 |
943 | ### POST
944 |
945 |
946 | Create user
947 |
948 | This can only be done by the logged in user.
949 |
950 |
951 |
952 |
953 |
954 |
955 |
956 | #### Request
957 |
958 |
959 |
960 | ##### Parameters
961 |
962 |
963 |
964 | Name |
965 | Located in |
966 | Required |
967 | Description |
968 | Default |
969 | Schema |
970 |
971 |
972 |
973 |
974 |
975 | body |
976 | body |
977 | yes |
978 | Created user object |
979 | - |
980 |
981 |
982 |
983 | User
984 | |
985 |
986 |
987 |
988 |
989 |
990 |
991 |
992 |
993 | #### Response
994 |
995 | **Content-Type: ** application/xml, application/json
996 |
997 |
998 | | Status Code | Reason | Response Model |
999 | |-------------|-------------|----------------|
1000 | | default | successful operation | - |
1001 |
1002 |
1003 |
1004 |
1005 |
1006 |
1007 |
1008 |
1009 |
1010 |
1011 |
1012 |
1013 |
1014 |
1015 |
1016 | ## /user/createWithArray
1017 |
1018 |
1019 |
1020 |
1021 |
1022 |
1023 | ### POST
1024 |
1025 |
1026 | Creates list of users with given input array
1027 |
1028 |
1029 |
1030 |
1031 |
1032 |
1033 |
1034 |
1035 |
1036 | #### Request
1037 |
1038 |
1039 |
1040 | ##### Parameters
1041 |
1042 |
1043 |
1044 | Name |
1045 | Located in |
1046 | Required |
1047 | Description |
1048 | Default |
1049 | Schema |
1050 |
1051 |
1052 |
1053 |
1054 |
1055 | body |
1056 | body |
1057 | yes |
1058 | List of user object |
1059 | - |
1060 |
1061 |
1062 | Array[User]
1063 |
1064 | |
1065 |
1066 |
1067 |
1068 |
1069 |
1070 |
1071 |
1072 |
1073 | #### Response
1074 |
1075 | **Content-Type: ** application/xml, application/json
1076 |
1077 |
1078 | | Status Code | Reason | Response Model |
1079 | |-------------|-------------|----------------|
1080 | | default | successful operation | - |
1081 |
1082 |
1083 |
1084 |
1085 |
1086 |
1087 |
1088 |
1089 |
1090 |
1091 |
1092 |
1093 |
1094 |
1095 |
1096 | ## /user/createWithList
1097 |
1098 |
1099 |
1100 |
1101 |
1102 |
1103 | ### POST
1104 |
1105 |
1106 | Creates list of users with given input array
1107 |
1108 |
1109 |
1110 |
1111 |
1112 |
1113 |
1114 |
1115 |
1116 | #### Request
1117 |
1118 |
1119 |
1120 | ##### Parameters
1121 |
1122 |
1123 |
1124 | Name |
1125 | Located in |
1126 | Required |
1127 | Description |
1128 | Default |
1129 | Schema |
1130 |
1131 |
1132 |
1133 |
1134 |
1135 | body |
1136 | body |
1137 | yes |
1138 | List of user object |
1139 | - |
1140 |
1141 |
1142 | Array[User]
1143 |
1144 | |
1145 |
1146 |
1147 |
1148 |
1149 |
1150 |
1151 |
1152 |
1153 | #### Response
1154 |
1155 | **Content-Type: ** application/xml, application/json
1156 |
1157 |
1158 | | Status Code | Reason | Response Model |
1159 | |-------------|-------------|----------------|
1160 | | default | successful operation | - |
1161 |
1162 |
1163 |
1164 |
1165 |
1166 |
1167 |
1168 |
1169 |
1170 |
1171 |
1172 |
1173 |
1174 |
1175 |
1176 | ## /user/login
1177 |
1178 |
1179 | ### GET
1180 |
1181 | Logs user into the system
1182 |
1183 |
1184 |
1185 |
1186 |
1187 |
1188 |
1189 |
1190 |
1191 | #### Request
1192 |
1193 |
1194 |
1195 | ##### Parameters
1196 |
1197 |
1198 |
1199 | Name |
1200 | Located in |
1201 | Required |
1202 | Description |
1203 | Default |
1204 | Schema |
1205 |
1206 |
1207 |
1208 |
1209 |
1210 | username |
1211 | query |
1212 | yes |
1213 | The user name for login |
1214 | - |
1215 |
1216 |
1217 | string |
1218 |
1219 |
1220 |
1221 |
1222 |
1223 | password |
1224 | query |
1225 | yes |
1226 | The password for login in clear text |
1227 | - |
1228 |
1229 |
1230 | string |
1231 |
1232 |
1233 |
1234 |
1235 |
1236 |
1237 |
1238 |
1239 |
1240 | #### Response
1241 |
1242 | **Content-Type: ** application/xml, application/json
1243 |
1244 |
1245 | | Status Code | Reason | Response Model |
1246 | |-------------|-------------|----------------|
1247 | | 200 | successful operation | |
1248 | | 400 | Invalid username/password supplied | - |
1249 |
1250 |
1251 |
1252 |
1253 |
1254 |
1255 |
1256 |
1257 |
1258 |
1259 |
1260 |
1261 |
1262 |
1263 |
1264 |
1265 |
1266 |
1267 | ## /user/logout
1268 |
1269 |
1270 | ### GET
1271 |
1272 | Logs out current logged in user session
1273 |
1274 |
1275 |
1276 |
1277 |
1278 |
1279 |
1280 |
1281 |
1282 | #### Request
1283 |
1284 |
1285 |
1286 | ##### Parameters
1287 |
1288 |
1289 |
1290 |
1291 |
1292 |
1293 | #### Response
1294 |
1295 | **Content-Type: ** application/xml, application/json
1296 |
1297 |
1298 | | Status Code | Reason | Response Model |
1299 | |-------------|-------------|----------------|
1300 | | default | successful operation | - |
1301 |
1302 |
1303 |
1304 |
1305 |
1306 |
1307 |
1308 |
1309 |
1310 |
1311 |
1312 |
1313 |
1314 |
1315 |
1316 |
1317 |
1318 |
1319 | ## /user/{username}
1320 |
1321 |
1322 | ### GET
1323 |
1324 | Get user by user name
1325 |
1326 |
1327 |
1328 |
1329 |
1330 |
1331 |
1332 |
1333 |
1334 | #### Request
1335 |
1336 |
1337 |
1338 | ##### Parameters
1339 |
1340 |
1341 |
1342 | Name |
1343 | Located in |
1344 | Required |
1345 | Description |
1346 | Default |
1347 | Schema |
1348 |
1349 |
1350 |
1351 |
1352 |
1353 | username |
1354 | path |
1355 | yes |
1356 | The name that needs to be fetched. Use user1 for testing. |
1357 | - |
1358 |
1359 |
1360 | string |
1361 |
1362 |
1363 |
1364 |
1365 |
1366 |
1367 |
1368 |
1369 |
1370 | #### Response
1371 |
1372 | **Content-Type: ** application/xml, application/json
1373 |
1374 |
1375 | | Status Code | Reason | Response Model |
1376 | |-------------|-------------|----------------|
1377 | | 200 | successful operation | User|
1378 | | 400 | Invalid username supplied | - |
1379 | | 404 | User not found | - |
1380 |
1381 |
1382 |
1383 |
1384 |
1385 | ### PUT
1386 |
1387 | Updated user
1388 |
1389 | This can only be done by the logged in user.
1390 |
1391 |
1392 |
1393 |
1394 |
1395 |
1396 |
1397 | #### Request
1398 |
1399 |
1400 |
1401 | ##### Parameters
1402 |
1403 |
1404 |
1405 | Name |
1406 | Located in |
1407 | Required |
1408 | Description |
1409 | Default |
1410 | Schema |
1411 |
1412 |
1413 |
1414 |
1415 |
1416 | username |
1417 | path |
1418 | yes |
1419 | name that need to be deleted |
1420 | - |
1421 |
1422 |
1423 | string |
1424 |
1425 |
1426 |
1427 |
1428 |
1429 | body |
1430 | body |
1431 | yes |
1432 | Updated user object |
1433 | - |
1434 |
1435 |
1436 |
1437 | User
1438 | |
1439 |
1440 |
1441 |
1442 |
1443 |
1444 |
1445 |
1446 |
1447 | #### Response
1448 |
1449 | **Content-Type: ** application/xml, application/json
1450 |
1451 |
1452 | | Status Code | Reason | Response Model |
1453 | |-------------|-------------|----------------|
1454 | | 400 | Invalid user supplied | - |
1455 | | 404 | User not found | - |
1456 |
1457 |
1458 |
1459 |
1460 |
1461 |
1462 |
1463 | ### DELETE
1464 |
1465 | Delete user
1466 |
1467 | This can only be done by the logged in user.
1468 |
1469 |
1470 |
1471 |
1472 |
1473 |
1474 |
1475 | #### Request
1476 |
1477 |
1478 |
1479 | ##### Parameters
1480 |
1481 |
1482 |
1483 | Name |
1484 | Located in |
1485 | Required |
1486 | Description |
1487 | Default |
1488 | Schema |
1489 |
1490 |
1491 |
1492 |
1493 |
1494 | username |
1495 | path |
1496 | yes |
1497 | The name that needs to be deleted |
1498 | - |
1499 |
1500 |
1501 | string |
1502 |
1503 |
1504 |
1505 |
1506 |
1507 |
1508 |
1509 |
1510 |
1511 | #### Response
1512 |
1513 | **Content-Type: ** application/xml, application/json
1514 |
1515 |
1516 | | Status Code | Reason | Response Model |
1517 | |-------------|-------------|----------------|
1518 | | 400 | Invalid username supplied | - |
1519 | | 404 | User not found | - |
1520 |
1521 |
1522 |
1523 |
1524 |
1525 |
1526 |
1527 |
1528 |
1529 |
1530 |
1531 |
1532 |
1533 | # Definitions
1534 |
1535 | ## Category
1536 |
1537 |
1538 |
1539 | name |
1540 | type |
1541 | required |
1542 | description |
1543 | example |
1544 |
1545 |
1546 |
1547 | id |
1548 |
1549 |
1550 |
1551 | integer (int64)
1552 |
1553 | |
1554 | optional |
1555 | - |
1556 | |
1557 |
1558 |
1559 |
1560 | name |
1561 |
1562 |
1563 |
1564 | string
1565 |
1566 | |
1567 | optional |
1568 | - |
1569 | |
1570 |
1571 |
1572 |
1573 |
1574 | ## Order
1575 |
1576 |
1577 |
1578 | name |
1579 | type |
1580 | required |
1581 | description |
1582 | example |
1583 |
1584 |
1585 |
1586 | id |
1587 |
1588 |
1589 |
1590 | integer (int64)
1591 |
1592 | |
1593 | optional |
1594 | - |
1595 | |
1596 |
1597 |
1598 |
1599 | petId |
1600 |
1601 |
1602 |
1603 | integer (int64)
1604 |
1605 | |
1606 | optional |
1607 | - |
1608 | |
1609 |
1610 |
1611 |
1612 | quantity |
1613 |
1614 |
1615 |
1616 | integer (int32)
1617 |
1618 | |
1619 | optional |
1620 | - |
1621 | |
1622 |
1623 |
1624 |
1625 | shipDate |
1626 |
1627 |
1628 |
1629 | string (date-time)
1630 |
1631 | |
1632 | optional |
1633 | - |
1634 | |
1635 |
1636 |
1637 |
1638 | status |
1639 |
1640 |
1641 |
1642 | string
1643 |
1644 | |
1645 | optional |
1646 | Order Status |
1647 | |
1648 |
1649 |
1650 |
1651 | complete |
1652 |
1653 |
1654 |
1655 | boolean
1656 |
1657 | |
1658 | optional |
1659 | - |
1660 | |
1661 |
1662 |
1663 |
1664 |
1665 | ## Pet
1666 |
1667 |
1668 |
1669 | name |
1670 | type |
1671 | required |
1672 | description |
1673 | example |
1674 |
1675 |
1676 |
1677 | id |
1678 |
1679 |
1680 |
1681 | integer (int64)
1682 |
1683 | |
1684 | optional |
1685 | - |
1686 | |
1687 |
1688 |
1689 |
1690 | category |
1691 |
1692 |
1693 | Category
1694 |
1695 |
1696 | |
1697 | optional |
1698 | - |
1699 | |
1700 |
1701 |
1702 |
1703 | name |
1704 |
1705 |
1706 |
1707 | string
1708 |
1709 | |
1710 | required |
1711 | - |
1712 | doggie |
1713 |
1714 |
1715 |
1716 | photoUrls |
1717 |
1718 |
1719 |
1720 | array[string]
1721 |
1722 | |
1723 | required |
1724 | - |
1725 | |
1726 |
1727 |
1728 |
1729 | tags |
1730 |
1731 |
1732 |
1733 | array[Tag]
1734 |
1735 |
1736 |
1737 | |
1738 | optional |
1739 | - |
1740 | |
1741 |
1742 |
1743 |
1744 | status |
1745 |
1746 |
1747 |
1748 | string
1749 |
1750 | |
1751 | optional |
1752 | pet status in the store |
1753 | |
1754 |
1755 |
1756 |
1757 |
1758 | ## Tag
1759 |
1760 |
1761 |
1762 | name |
1763 | type |
1764 | required |
1765 | description |
1766 | example |
1767 |
1768 |
1769 |
1770 | id |
1771 |
1772 |
1773 |
1774 | integer (int64)
1775 |
1776 | |
1777 | optional |
1778 | - |
1779 | |
1780 |
1781 |
1782 |
1783 | name |
1784 |
1785 |
1786 |
1787 | string
1788 |
1789 | |
1790 | optional |
1791 | - |
1792 | |
1793 |
1794 |
1795 |
1796 |
1797 | ## User
1798 |
1799 |
1800 |
1801 | name |
1802 | type |
1803 | required |
1804 | description |
1805 | example |
1806 |
1807 |
1808 |
1809 | id |
1810 |
1811 |
1812 |
1813 | integer (int64)
1814 |
1815 | |
1816 | optional |
1817 | - |
1818 | |
1819 |
1820 |
1821 |
1822 | username |
1823 |
1824 |
1825 |
1826 | string
1827 |
1828 | |
1829 | optional |
1830 | - |
1831 | |
1832 |
1833 |
1834 |
1835 | firstName |
1836 |
1837 |
1838 |
1839 | string
1840 |
1841 | |
1842 | optional |
1843 | - |
1844 | |
1845 |
1846 |
1847 |
1848 | lastName |
1849 |
1850 |
1851 |
1852 | string
1853 |
1854 | |
1855 | optional |
1856 | - |
1857 | |
1858 |
1859 |
1860 |
1861 | email |
1862 |
1863 |
1864 |
1865 | string
1866 |
1867 | |
1868 | optional |
1869 | - |
1870 | |
1871 |
1872 |
1873 |
1874 | password |
1875 |
1876 |
1877 |
1878 | string
1879 |
1880 | |
1881 | optional |
1882 | - |
1883 | |
1884 |
1885 |
1886 |
1887 | phone |
1888 |
1889 |
1890 |
1891 | string
1892 |
1893 | |
1894 | optional |
1895 | - |
1896 | |
1897 |
1898 |
1899 |
1900 | userStatus |
1901 |
1902 |
1903 |
1904 | integer (int32)
1905 |
1906 | |
1907 | optional |
1908 | User Status |
1909 | |
1910 |
1911 |
1912 |
1913 |
1914 |
1915 |
1916 |
1917 |
1918 |
1919 |
--------------------------------------------------------------------------------
/generated/swagger-ui/swagger.json:
--------------------------------------------------------------------------------
1 | {
2 | "swagger" : "2.0",
3 | "info" : {
4 | "description" : "This is a sample for swagger-maven-plugin",
5 | "version" : "v1",
6 | "title" : "Swagger Maven Plugin Sample",
7 | "termsOfService" : "http://www.github.com/kongchen/swagger-maven-plugin",
8 | "contact" : {
9 | "name" : "Kong Chen",
10 | "url" : "http://kongch.com",
11 | "email" : "kongchen@gmail.com"
12 | },
13 | "license" : {
14 | "name" : "Apache 2.0",
15 | "url" : "http://www.apache.org/licenses/LICENSE-2.0.html"
16 | }
17 | },
18 | "host" : "petstore.swagger.wordnik.com",
19 | "basePath" : "/api",
20 | "tags" : [ {
21 | "name" : "store"
22 | }, {
23 | "name" : "user"
24 | }, {
25 | "name" : "pet"
26 | } ],
27 | "schemes" : [ "http", "https" ],
28 | "paths" : {
29 | "/pet" : {
30 | "post" : {
31 | "tags" : [ "pet" ],
32 | "summary" : "Add a new pet to the store",
33 | "description" : "",
34 | "operationId" : "addPet",
35 | "consumes" : [ "application/json", "application/xml" ],
36 | "produces" : [ "application/xml", "application/json" ],
37 | "parameters" : [ {
38 | "in" : "body",
39 | "name" : "body",
40 | "description" : "Pet object that needs to be added to the store",
41 | "required" : true,
42 | "schema" : {
43 | "$ref" : "#/definitions/Pet"
44 | }
45 | } ],
46 | "responses" : {
47 | "405" : {
48 | "description" : "Invalid input"
49 | }
50 | },
51 | "security" : [ {
52 | "petstore_auth" : [ "write:pets", "read:pets" ]
53 | } ]
54 | },
55 | "put" : {
56 | "tags" : [ "pet" ],
57 | "summary" : "Update an existing pet",
58 | "description" : "",
59 | "operationId" : "updatePet",
60 | "consumes" : [ "application/json", "application/xml" ],
61 | "produces" : [ "application/xml", "application/json" ],
62 | "parameters" : [ {
63 | "in" : "body",
64 | "name" : "body",
65 | "description" : "Pet object that needs to be added to the store",
66 | "required" : true,
67 | "schema" : {
68 | "$ref" : "#/definitions/Pet"
69 | }
70 | } ],
71 | "responses" : {
72 | "400" : {
73 | "description" : "Invalid ID supplied"
74 | },
75 | "404" : {
76 | "description" : "Pet not found"
77 | },
78 | "405" : {
79 | "description" : "Validation exception"
80 | }
81 | },
82 | "security" : [ {
83 | "petstore_auth" : [ "write:pets", "read:pets" ]
84 | } ]
85 | }
86 | },
87 | "/pet/findByStatus" : {
88 | "get" : {
89 | "tags" : [ "pet" ],
90 | "summary" : "Finds Pets by status",
91 | "description" : "Multiple status values can be provided with comma seperated strings",
92 | "operationId" : "findPetsByStatus",
93 | "produces" : [ "application/xml", "application/json" ],
94 | "parameters" : [ {
95 | "name" : "status",
96 | "in" : "query",
97 | "description" : "Status values that need to be considered for filter",
98 | "required" : true,
99 | "type" : "array",
100 | "items" : {
101 | "type" : "string",
102 | "default" : "available",
103 | "enum" : [ "available", "pending", "sold" ]
104 | },
105 | "collectionFormat" : "csv"
106 | } ],
107 | "responses" : {
108 | "200" : {
109 | "description" : "successful operation",
110 | "schema" : {
111 | "type" : "array",
112 | "items" : {
113 | "$ref" : "#/definitions/Pet"
114 | }
115 | }
116 | },
117 | "400" : {
118 | "description" : "Invalid status value"
119 | }
120 | },
121 | "security" : [ {
122 | "petstore_auth" : [ "write:pets", "read:pets" ]
123 | } ]
124 | }
125 | },
126 | "/pet/findByTags" : {
127 | "get" : {
128 | "tags" : [ "pet" ],
129 | "summary" : "Finds Pets by tags",
130 | "description" : "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
131 | "operationId" : "findPetsByTags",
132 | "produces" : [ "application/xml", "application/json" ],
133 | "parameters" : [ {
134 | "name" : "tags",
135 | "in" : "query",
136 | "description" : "Tags to filter by",
137 | "required" : true,
138 | "type" : "array",
139 | "items" : {
140 | "type" : "string"
141 | },
142 | "collectionFormat" : "csv"
143 | } ],
144 | "responses" : {
145 | "200" : {
146 | "description" : "successful operation",
147 | "schema" : {
148 | "type" : "array",
149 | "items" : {
150 | "$ref" : "#/definitions/Pet"
151 | }
152 | }
153 | },
154 | "400" : {
155 | "description" : "Invalid tag value"
156 | }
157 | },
158 | "security" : [ {
159 | "petstore_auth" : [ "write:pets", "read:pets" ]
160 | } ]
161 | }
162 | },
163 | "/pet/{petId}" : {
164 | "get" : {
165 | "tags" : [ "pet" ],
166 | "summary" : "Find pet by ID",
167 | "description" : "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
168 | "operationId" : "getPetById",
169 | "produces" : [ "application/xml", "application/json" ],
170 | "parameters" : [ {
171 | "name" : "petId",
172 | "in" : "path",
173 | "description" : "ID of pet that needs to be fetched",
174 | "required" : true,
175 | "type" : "integer",
176 | "maximum" : 5.0,
177 | "minimum" : 1.0,
178 | "format" : "int64"
179 | } ],
180 | "responses" : {
181 | "200" : {
182 | "description" : "successful operation",
183 | "schema" : {
184 | "$ref" : "#/definitions/Pet"
185 | }
186 | },
187 | "400" : {
188 | "description" : "Invalid ID supplied"
189 | },
190 | "404" : {
191 | "description" : "Pet not found"
192 | }
193 | },
194 | "security" : [ {
195 | "api_key" : [ ]
196 | }, {
197 | "petstore_auth" : [ "write:pets", "read:pets" ]
198 | } ]
199 | },
200 | "post" : {
201 | "tags" : [ "pet" ],
202 | "summary" : "Updates a pet in the store with form data",
203 | "description" : "",
204 | "operationId" : "updatePetWithForm",
205 | "consumes" : [ "application/x-www-form-urlencoded" ],
206 | "produces" : [ "application/xml", "application/json" ],
207 | "parameters" : [ {
208 | "name" : "petId",
209 | "in" : "path",
210 | "description" : "ID of pet that needs to be updated",
211 | "required" : true,
212 | "type" : "string"
213 | }, {
214 | "name" : "name",
215 | "in" : "formData",
216 | "description" : "Updated name of the pet",
217 | "required" : false,
218 | "type" : "string"
219 | }, {
220 | "name" : "status",
221 | "in" : "formData",
222 | "description" : "Updated status of the pet",
223 | "required" : false,
224 | "type" : "string"
225 | } ],
226 | "responses" : {
227 | "405" : {
228 | "description" : "Invalid input"
229 | }
230 | },
231 | "security" : [ {
232 | "petstore_auth" : [ "write:pets", "read:pets" ]
233 | } ]
234 | },
235 | "delete" : {
236 | "tags" : [ "pet" ],
237 | "summary" : "Deletes a pet",
238 | "description" : "",
239 | "operationId" : "deletePet",
240 | "produces" : [ "application/xml", "application/json" ],
241 | "parameters" : [ {
242 | "name" : "api_key",
243 | "in" : "header",
244 | "required" : false,
245 | "type" : "string",
246 | "default" : ""
247 | }, {
248 | "name" : "petId",
249 | "in" : "path",
250 | "description" : "Pet id to delete",
251 | "required" : true,
252 | "type" : "integer",
253 | "format" : "int64"
254 | } ],
255 | "responses" : {
256 | "400" : {
257 | "description" : "Invalid pet value"
258 | }
259 | },
260 | "security" : [ {
261 | "petstore_auth" : [ "write:pets", "read:pets" ]
262 | } ]
263 | }
264 | },
265 | "/store/order" : {
266 | "post" : {
267 | "tags" : [ "store" ],
268 | "summary" : "Place an order for a pet",
269 | "description" : "",
270 | "operationId" : "placeOrder",
271 | "produces" : [ "application/xml", "application/json" ],
272 | "parameters" : [ {
273 | "in" : "body",
274 | "name" : "body",
275 | "description" : "order placed for purchasing the pet",
276 | "required" : true,
277 | "schema" : {
278 | "$ref" : "#/definitions/Order"
279 | }
280 | } ],
281 | "responses" : {
282 | "200" : {
283 | "description" : "successful operation",
284 | "schema" : {
285 | "$ref" : "#/definitions/Order"
286 | }
287 | },
288 | "400" : {
289 | "description" : "Invalid Order"
290 | }
291 | }
292 | }
293 | },
294 | "/store/order/{orderId}" : {
295 | "get" : {
296 | "tags" : [ "store" ],
297 | "summary" : "Find purchase order by ID",
298 | "description" : "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
299 | "operationId" : "getOrderById",
300 | "produces" : [ "application/xml", "application/json" ],
301 | "parameters" : [ {
302 | "name" : "orderId",
303 | "in" : "path",
304 | "description" : "ID of pet that needs to be fetched",
305 | "required" : true,
306 | "type" : "string",
307 | "maximum" : 5.0,
308 | "minimum" : 1.0
309 | } ],
310 | "responses" : {
311 | "200" : {
312 | "description" : "successful operation",
313 | "schema" : {
314 | "$ref" : "#/definitions/Order"
315 | }
316 | },
317 | "400" : {
318 | "description" : "Invalid ID supplied"
319 | },
320 | "404" : {
321 | "description" : "Order not found"
322 | }
323 | }
324 | },
325 | "delete" : {
326 | "tags" : [ "store" ],
327 | "summary" : "Delete purchase order by ID",
328 | "description" : "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
329 | "operationId" : "deleteOrder",
330 | "produces" : [ "application/xml", "application/json" ],
331 | "parameters" : [ {
332 | "name" : "orderId",
333 | "in" : "path",
334 | "description" : "ID of the order that needs to be deleted",
335 | "required" : true,
336 | "type" : "string",
337 | "minimum" : 1.0
338 | } ],
339 | "responses" : {
340 | "400" : {
341 | "description" : "Invalid ID supplied"
342 | },
343 | "404" : {
344 | "description" : "Order not found"
345 | }
346 | }
347 | }
348 | },
349 | "/user" : {
350 | "post" : {
351 | "tags" : [ "user" ],
352 | "summary" : "Create user",
353 | "description" : "This can only be done by the logged in user.",
354 | "operationId" : "createUser",
355 | "produces" : [ "application/xml", "application/json" ],
356 | "parameters" : [ {
357 | "in" : "body",
358 | "name" : "body",
359 | "description" : "Created user object",
360 | "required" : true,
361 | "schema" : {
362 | "$ref" : "#/definitions/User"
363 | }
364 | } ],
365 | "responses" : {
366 | "default" : {
367 | "description" : "successful operation"
368 | }
369 | }
370 | }
371 | },
372 | "/user/createWithArray" : {
373 | "post" : {
374 | "tags" : [ "user" ],
375 | "summary" : "Creates list of users with given input array",
376 | "description" : "",
377 | "operationId" : "createUsersWithArrayInput",
378 | "produces" : [ "application/xml", "application/json" ],
379 | "parameters" : [ {
380 | "in" : "body",
381 | "name" : "body",
382 | "description" : "List of user object",
383 | "required" : true,
384 | "schema" : {
385 | "type" : "array",
386 | "items" : {
387 | "$ref" : "#/definitions/User"
388 | }
389 | }
390 | } ],
391 | "responses" : {
392 | "default" : {
393 | "description" : "successful operation"
394 | }
395 | }
396 | }
397 | },
398 | "/user/createWithList" : {
399 | "post" : {
400 | "tags" : [ "user" ],
401 | "summary" : "Creates list of users with given input array",
402 | "description" : "",
403 | "operationId" : "createUsersWithListInput",
404 | "produces" : [ "application/xml", "application/json" ],
405 | "parameters" : [ {
406 | "in" : "body",
407 | "name" : "body",
408 | "description" : "List of user object",
409 | "required" : true,
410 | "schema" : {
411 | "type" : "array",
412 | "items" : {
413 | "$ref" : "#/definitions/User"
414 | }
415 | }
416 | } ],
417 | "responses" : {
418 | "default" : {
419 | "description" : "successful operation"
420 | }
421 | }
422 | }
423 | },
424 | "/user/login" : {
425 | "get" : {
426 | "tags" : [ "user" ],
427 | "summary" : "Logs user into the system",
428 | "description" : "",
429 | "operationId" : "loginUser",
430 | "produces" : [ "application/xml", "application/json" ],
431 | "parameters" : [ {
432 | "name" : "username",
433 | "in" : "query",
434 | "description" : "The user name for login",
435 | "required" : true,
436 | "type" : "string"
437 | }, {
438 | "name" : "password",
439 | "in" : "query",
440 | "description" : "The password for login in clear text",
441 | "required" : true,
442 | "type" : "string"
443 | } ],
444 | "responses" : {
445 | "200" : {
446 | "description" : "successful operation",
447 | "schema" : {
448 | "type" : "string"
449 | }
450 | },
451 | "400" : {
452 | "description" : "Invalid username/password supplied"
453 | }
454 | }
455 | }
456 | },
457 | "/user/logout" : {
458 | "get" : {
459 | "tags" : [ "user" ],
460 | "summary" : "Logs out current logged in user session",
461 | "description" : "",
462 | "operationId" : "logoutUser",
463 | "produces" : [ "application/xml", "application/json" ],
464 | "responses" : {
465 | "default" : {
466 | "description" : "successful operation"
467 | }
468 | }
469 | }
470 | },
471 | "/user/{username}" : {
472 | "get" : {
473 | "tags" : [ "user" ],
474 | "summary" : "Get user by user name",
475 | "description" : "",
476 | "operationId" : "getUserByName",
477 | "produces" : [ "application/xml", "application/json" ],
478 | "parameters" : [ {
479 | "name" : "username",
480 | "in" : "path",
481 | "description" : "The name that needs to be fetched. Use user1 for testing. ",
482 | "required" : true,
483 | "type" : "string"
484 | } ],
485 | "responses" : {
486 | "200" : {
487 | "description" : "successful operation",
488 | "schema" : {
489 | "$ref" : "#/definitions/User"
490 | }
491 | },
492 | "400" : {
493 | "description" : "Invalid username supplied"
494 | },
495 | "404" : {
496 | "description" : "User not found"
497 | }
498 | }
499 | },
500 | "put" : {
501 | "tags" : [ "user" ],
502 | "summary" : "Updated user",
503 | "description" : "This can only be done by the logged in user.",
504 | "operationId" : "updateUser",
505 | "produces" : [ "application/xml", "application/json" ],
506 | "parameters" : [ {
507 | "name" : "username",
508 | "in" : "path",
509 | "description" : "name that need to be deleted",
510 | "required" : true,
511 | "type" : "string"
512 | }, {
513 | "in" : "body",
514 | "name" : "body",
515 | "description" : "Updated user object",
516 | "required" : true,
517 | "schema" : {
518 | "$ref" : "#/definitions/User"
519 | }
520 | } ],
521 | "responses" : {
522 | "400" : {
523 | "description" : "Invalid user supplied"
524 | },
525 | "404" : {
526 | "description" : "User not found"
527 | }
528 | }
529 | },
530 | "delete" : {
531 | "tags" : [ "user" ],
532 | "summary" : "Delete user",
533 | "description" : "This can only be done by the logged in user.",
534 | "operationId" : "deleteUser",
535 | "produces" : [ "application/xml", "application/json" ],
536 | "parameters" : [ {
537 | "name" : "username",
538 | "in" : "path",
539 | "description" : "The name that needs to be deleted",
540 | "required" : true,
541 | "type" : "string"
542 | } ],
543 | "responses" : {
544 | "400" : {
545 | "description" : "Invalid username supplied"
546 | },
547 | "404" : {
548 | "description" : "User not found"
549 | }
550 | }
551 | }
552 | }
553 | },
554 | "securityDefinitions" : {
555 | "api_key" : {
556 | "type" : "apiKey",
557 | "name" : "api_key",
558 | "in" : "header"
559 | },
560 | "petstore_auth" : {
561 | "type" : "oauth2",
562 | "authorizationUrl" : "http://swagger.io/api/oauth/dialog",
563 | "flow" : "implicit",
564 | "scopes" : {
565 | "write:pets" : "modify pets in your account",
566 | "read:pets" : "read your pets"
567 | }
568 | }
569 | },
570 | "definitions" : {
571 | "Category" : {
572 | "type" : "object",
573 | "properties" : {
574 | "id" : {
575 | "type" : "integer",
576 | "format" : "int64"
577 | },
578 | "name" : {
579 | "type" : "string"
580 | }
581 | },
582 | "xml" : {
583 | "name" : "Category"
584 | }
585 | },
586 | "Order" : {
587 | "type" : "object",
588 | "properties" : {
589 | "id" : {
590 | "type" : "integer",
591 | "format" : "int64"
592 | },
593 | "petId" : {
594 | "type" : "integer",
595 | "format" : "int64"
596 | },
597 | "quantity" : {
598 | "type" : "integer",
599 | "format" : "int32"
600 | },
601 | "shipDate" : {
602 | "type" : "string",
603 | "format" : "date-time"
604 | },
605 | "status" : {
606 | "type" : "string",
607 | "description" : "Order Status",
608 | "enum" : [ "placed", "approved", "delivered" ]
609 | },
610 | "complete" : {
611 | "type" : "boolean",
612 | "default" : false
613 | }
614 | },
615 | "xml" : {
616 | "name" : "Order"
617 | }
618 | },
619 | "Pet" : {
620 | "type" : "object",
621 | "required" : [ "name", "photoUrls" ],
622 | "properties" : {
623 | "id" : {
624 | "type" : "integer",
625 | "format" : "int64"
626 | },
627 | "category" : {
628 | "$ref" : "#/definitions/Category"
629 | },
630 | "name" : {
631 | "type" : "string",
632 | "example" : "doggie"
633 | },
634 | "photoUrls" : {
635 | "type" : "array",
636 | "xml" : {
637 | "name" : "photoUrl",
638 | "wrapped" : true
639 | },
640 | "items" : {
641 | "type" : "string"
642 | }
643 | },
644 | "tags" : {
645 | "type" : "array",
646 | "xml" : {
647 | "name" : "tag",
648 | "wrapped" : true
649 | },
650 | "items" : {
651 | "$ref" : "#/definitions/Tag"
652 | }
653 | },
654 | "status" : {
655 | "type" : "string",
656 | "description" : "pet status in the store",
657 | "enum" : [ "available", "pending", "sold" ]
658 | }
659 | },
660 | "xml" : {
661 | "name" : "Pet"
662 | }
663 | },
664 | "Tag" : {
665 | "type" : "object",
666 | "properties" : {
667 | "id" : {
668 | "type" : "integer",
669 | "format" : "int64"
670 | },
671 | "name" : {
672 | "type" : "string"
673 | }
674 | },
675 | "xml" : {
676 | "name" : "Tag"
677 | }
678 | },
679 | "User" : {
680 | "type" : "object",
681 | "properties" : {
682 | "id" : {
683 | "type" : "integer",
684 | "format" : "int64"
685 | },
686 | "username" : {
687 | "type" : "string"
688 | },
689 | "firstName" : {
690 | "type" : "string"
691 | },
692 | "lastName" : {
693 | "type" : "string"
694 | },
695 | "email" : {
696 | "type" : "string"
697 | },
698 | "password" : {
699 | "type" : "string"
700 | },
701 | "phone" : {
702 | "type" : "string"
703 | },
704 | "userStatus" : {
705 | "type" : "integer",
706 | "format" : "int32",
707 | "description" : "User Status"
708 | }
709 | },
710 | "xml" : {
711 | "name" : "User"
712 | }
713 | }
714 | }
715 | }
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | swagger-maven-example
8 | swagger-maven-example
9 | 1.0-SNAPSHOT
10 | war
11 |
12 |
13 |
14 | com.github.kongchen
15 | swagger-maven-plugin
16 | 3.1.1
17 |
18 |
19 |
20 | false
21 | com.github.kongchen.swagger.sample.wordnik.resource
22 | http,https
23 | petstore.swagger.wordnik.com
24 | /api
25 |
26 | Swagger Maven Plugin Sample
27 | v1
28 | This is a sample for swagger-maven-plugin
29 |
30 | http://www.github.com/kongchen/swagger-maven-plugin
31 |
32 |
33 | kongchen@gmail.com
34 | Kong Chen
35 | http://kongch.com
36 |
37 |
38 | http://www.apache.org/licenses/LICENSE-2.0.html
39 | Apache 2.0
40 |
41 |
42 |
46 | ${basedir}/templates/strapdown.html.hbs
47 | ${basedir}/generated/document.html
48 | generated/swagger-ui
49 |
50 |
51 | /securityDefinitions.json
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | compile
60 |
61 | generate
62 |
63 |
64 |
65 |
66 |
67 | org.apache.maven.plugins
68 | maven-war-plugin
69 | 2.1.1
70 |
71 |
72 | org.apache.maven.plugins
73 | maven-compiler-plugin
74 | 3.1
75 |
76 | 1.6
77 | 1.6
78 |
79 |
80 |
81 |
82 |
83 |
84 | io.swagger
85 | swagger-core
86 | compile
87 | 1.5.3
88 |
89 |
90 | javax.ws.rs
91 | jsr311-api
92 |
93 |
94 |
95 |
96 | ch.qos.logback
97 | logback-classic
98 | ${logback-version}
99 | compile
100 |
101 |
102 | ch.qos.logback
103 | logback-core
104 | ${logback-version}
105 | compile
106 |
107 |
108 | javax.servlet
109 | servlet-api
110 | 2.5
111 |
112 |
113 | org.glassfish.jersey.containers
114 | jersey-container-servlet-core
115 | ${jersey2-version}
116 |
117 |
118 | org.glassfish.jersey.media
119 | jersey-media-multipart
120 | ${jersey2-version}
121 |
122 |
123 |
124 | 9.0.7.v20131107
125 | 2.4.1
126 | 1.0.1
127 |
128 |
129 |
130 | sonatype-snapshot
131 | https://oss.sonatype.org/content/repositories/snapshots/
132 |
133 | false
134 |
135 |
136 | true
137 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/data/PetData.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.data;
18 |
19 | import com.github.kongchen.swagger.sample.wordnik.model.Category;
20 | import com.github.kongchen.swagger.sample.wordnik.model.Pet;
21 | import com.github.kongchen.swagger.sample.wordnik.model.Tag;
22 |
23 | import java.util.List;
24 | import java.util.ArrayList;
25 |
26 | public class PetData {
27 | static List pets = new ArrayList();
28 | static List categories = new ArrayList();
29 |
30 | static {
31 | categories.add(createCategory(1, "Dogs"));
32 | categories.add(createCategory(2, "Cats"));
33 | categories.add(createCategory(3, "Rabbits"));
34 | categories.add(createCategory(4, "Lions"));
35 |
36 | pets.add(createPet(1, categories.get(1), "Cat 1", new String[] {
37 | "url1", "url2" }, new String[] { "tag1", "tag2" }, "available"));
38 | pets.add(createPet(2, categories.get(1), "Cat 2", new String[] {
39 | "url1", "url2" }, new String[] { "tag2", "tag3" }, "available"));
40 | pets.add(createPet(3, categories.get(1), "Cat 3", new String[] {
41 | "url1", "url2" }, new String[] { "tag3", "tag4" }, "pending"));
42 |
43 | pets.add(createPet(4, categories.get(0), "Dog 1", new String[] {
44 | "url1", "url2" }, new String[] { "tag1", "tag2" }, "available"));
45 | pets.add(createPet(5, categories.get(0), "Dog 2", new String[] {
46 | "url1", "url2" }, new String[] { "tag2", "tag3" }, "sold"));
47 | pets.add(createPet(6, categories.get(0), "Dog 3", new String[] {
48 | "url1", "url2" }, new String[] { "tag3", "tag4" }, "pending"));
49 |
50 | pets.add(createPet(7, categories.get(3), "Lion 1", new String[] {
51 | "url1", "url2" }, new String[] { "tag1", "tag2" }, "available"));
52 | pets.add(createPet(8, categories.get(3), "Lion 2", new String[] {
53 | "url1", "url2" }, new String[] { "tag2", "tag3" }, "available"));
54 | pets.add(createPet(9, categories.get(3), "Lion 3", new String[] {
55 | "url1", "url2" }, new String[] { "tag3", "tag4" }, "available"));
56 |
57 | pets.add(createPet(10, categories.get(2), "Rabbit 1", new String[] {
58 | "url1", "url2" }, new String[] { "tag3", "tag4" }, "available"));
59 | }
60 |
61 | public Pet getPetbyId(long petId) {
62 | for (Pet pet : pets) {
63 | if (pet.getId() == petId) {
64 | return pet;
65 | }
66 | }
67 | return null;
68 | }
69 |
70 | public void deletePet(long petId) {
71 | if(pets.size() > 0) {
72 | for (int i = pets.size(); i >= 0; i++) {
73 | Pet pet = pets.get(i);
74 | if(pet.getId() == petId) {
75 | pets.remove(i);
76 | }
77 | }
78 | }
79 | }
80 |
81 | public List findPetByStatus(String status) {
82 | String[] statues = status.split(",");
83 | List result = new java.util.ArrayList();
84 | for (Pet pet : pets) {
85 | for (String s : statues) {
86 | if (s.equals(pet.getStatus())) {
87 | result.add(pet);
88 | }
89 | }
90 | }
91 | return result;
92 | }
93 |
94 | public List findPetByTags(String tags) {
95 | String[] tagList = tags.split(",");
96 | List result = new java.util.ArrayList();
97 | for (Pet pet : pets) {
98 | if (null != pet.getTags()) {
99 | for (Tag tag : pet.getTags()) {
100 | for (String tagListString : tagList) {
101 | if (tagListString.equals(tag.getName()))
102 | result.add(pet);
103 | }
104 | }
105 | }
106 | }
107 | return result;
108 | }
109 |
110 | public Pet addPet(Pet pet) {
111 | if(pet.getId() == 0) {
112 | long maxId = 0;
113 | for (int i = pets.size() - 1; i >= 0; i--) {
114 | if(pets.get(i).getId() > maxId) {
115 | maxId = pets.get(i).getId();
116 | }
117 | }
118 | pet.setId(maxId + 1);
119 | }
120 | if (pets.size() > 0) {
121 | for (int i = pets.size() - 1; i >= 0; i--) {
122 | if (pets.get(i).getId() == pet.getId()) {
123 | pets.remove(i);
124 | }
125 | }
126 | }
127 | pets.add(pet);
128 | return pet;
129 | }
130 |
131 | static Pet createPet(long id, Category cat, String name, String[] urls,
132 | String[] tags, String status) {
133 | Pet pet = new Pet();
134 | pet.setId(id);
135 | pet.setCategory(cat);
136 | pet.setName(name);
137 | if (null != urls) {
138 | List urlObjs = new ArrayList();
139 | for (String urlString : urls) {
140 | urlObjs.add(urlString);
141 | }
142 | pet.setPhotoUrls(urlObjs);
143 | }
144 | List tagObjs = new java.util.ArrayList();
145 | int i = 0;
146 | if (null != tags) {
147 | for (String tagString : tags) {
148 | i = i + 1;
149 | Tag tag = new Tag();
150 | tag.setId(i);
151 | tag.setName(tagString);
152 | tagObjs.add(tag);
153 | }
154 | }
155 | pet.setTags(tagObjs);
156 | pet.setStatus(status);
157 | return pet;
158 | }
159 |
160 | static Category createCategory(long id, String name) {
161 | Category category = new Category();
162 | category.setId(id);
163 | category.setName(name);
164 | return category;
165 | }
166 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/data/StoreData.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.data;
18 |
19 | import com.github.kongchen.swagger.sample.wordnik.model.Order;
20 |
21 | import java.util.Date;
22 | import java.util.List;
23 | import java.util.ArrayList;
24 |
25 | public class StoreData {
26 | static List orders = new ArrayList();
27 |
28 | static {
29 | orders.add(createOrder(1, 1, 2, new Date(), "placed"));
30 | orders.add(createOrder(2, 1, 2, new Date(), "delivered"));
31 | orders.add(createOrder(3, 2, 2, new Date(), "placed"));
32 | orders.add(createOrder(4, 2, 2, new Date(), "delivered"));
33 | orders.add(createOrder(5, 3, 2, new Date(), "placed"));
34 | orders.add(createOrder(11, 3, 2, new Date(), "placed"));
35 | orders.add(createOrder(12, 3, 2, new Date(), "placed"));
36 | orders.add(createOrder(13, 3, 2, new Date(), "placed"));
37 | orders.add(createOrder(14, 3, 2, new Date(), "placed"));
38 | orders.add(createOrder(15, 3, 2, new Date(), "placed"));
39 | }
40 |
41 | public Order findOrderById(long orderId) {
42 | for (Order order : orders) {
43 | if (order.getId() == orderId) {
44 | return order;
45 | }
46 | }
47 | return null;
48 | }
49 |
50 | public Order placeOrder(Order order) {
51 | if (orders.size() > 0) {
52 | for (int i = orders.size() - 1; i >= 0; i--) {
53 | if (orders.get(i).getId() == order.getId()) {
54 | orders.remove(i);
55 | }
56 | }
57 | }
58 | orders.add(order);
59 | return order;
60 | }
61 |
62 | public void deleteOrder(long orderId) {
63 | if (orders.size() > 0) {
64 | for (int i = orders.size() - 1; i >= 0; i--) {
65 | if (orders.get(i).getId() == orderId) {
66 | orders.remove(i);
67 | }
68 | }
69 | }
70 | }
71 |
72 | private static Order createOrder(long id, long petId, int quantity,
73 | Date shipDate, String status) {
74 | Order order = new Order();
75 | order.setId(id);
76 | order.setPetId(petId);
77 | order.setQuantity(quantity);
78 | order.setShipDate(shipDate);
79 | order.setStatus(status);
80 | return order;
81 | }
82 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/data/UserData.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.data;
18 |
19 | import com.github.kongchen.swagger.sample.wordnik.model.User;
20 |
21 | import java.util.List;
22 | import java.util.ArrayList;
23 |
24 | public class UserData {
25 | static List users = new ArrayList();
26 |
27 | static {
28 | users.add(createUser(1, "user1", "first name 1", "last name 1",
29 | "email1@test.com", "123-456-7890", 1));
30 | users.add(createUser(2, "user2", "first name 2", "last name 2",
31 | "email2@test.com", "123-456-7890", 2));
32 | users.add(createUser(3, "user3", "first name 3", "last name 3",
33 | "email3@test.com", "123-456-7890", 3));
34 | users.add(createUser(4, "user4", "first name 4", "last name 4",
35 | "email4@test.com", "123-456-7890", 1));
36 | users.add(createUser(5, "user5", "first name 5", "last name 5",
37 | "email5@test.com", "123-456-7890", 2));
38 | users.add(createUser(6, "user6", "first name 6", "last name 6",
39 | "email6@test.com", "123-456-7890", 3));
40 | users.add(createUser(7, "user7", "first name 7", "last name 7",
41 | "email7@test.com", "123-456-7890", 1));
42 | users.add(createUser(8, "user8", "first name 8", "last name 8",
43 | "email8@test.com", "123-456-7890", 2));
44 | users.add(createUser(9, "user9", "first name 9", "last name 9",
45 | "email9@test.com", "123-456-7890", 3));
46 | users.add(createUser(10, "user10", "first name 10", "last name 10",
47 | "email10@test.com", "123-456-7890", 1));
48 | users.add(createUser(11, "user?10", "first name ?10", "last name ?10",
49 | "email101@test.com", "123-456-7890", 1));
50 |
51 | }
52 |
53 | public User findUserByName(String username) {
54 | for (User user : users) {
55 | if (user.getUsername().equals(username)) {
56 | return user;
57 | }
58 | }
59 | return null;
60 | }
61 |
62 | public void addUser(User user) {
63 | if (users.size() > 0) {
64 | for (int i = users.size() - 1; i >= 0; i--) {
65 | if (users.get(i).getUsername().equals(user.getUsername())) {
66 | users.remove(i);
67 | }
68 | }
69 | }
70 | users.add(user);
71 | }
72 |
73 | public void removeUser(String username) {
74 | if (users.size() > 0) {
75 | for (int i = users.size() - 1; i >= 0; i--) {
76 | if (users.get(i).getUsername().equals(username)) {
77 | users.remove(i);
78 | }
79 | }
80 | }
81 | }
82 |
83 | private static User createUser(long id, String username, String firstName,
84 | String lastName, String email, String phone, int userStatus) {
85 | User user = new User();
86 | user.setId(id);
87 | user.setUsername(username);
88 | user.setFirstName(firstName);
89 | user.setLastName(lastName);
90 | user.setEmail(email);
91 | user.setPassword("XXXXXXXXXXX");
92 | user.setPhone(phone);
93 | user.setUserStatus(userStatus);
94 | return user;
95 | }
96 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/exception/ApiException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.exception;
18 |
19 | public class ApiException extends Exception{
20 | private int code;
21 | public ApiException (int code, String msg) {
22 | super(msg);
23 | this.code = code;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/exception/BadRequestException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.exception;
18 |
19 | public class BadRequestException extends ApiException{
20 | private int code;
21 | public BadRequestException (int code, String msg) {
22 | super(code, msg);
23 | this.code = code;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/exception/NotFoundException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.exception;
18 |
19 | public class NotFoundException extends ApiException {
20 | private int code;
21 | public NotFoundException (int code, String msg) {
22 | super(code, msg);
23 | this.code = code;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/model/ApiResponse.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.model;
18 |
19 | import javax.xml.bind.annotation.XmlTransient;
20 |
21 | @javax.xml.bind.annotation.XmlRootElement
22 | public class ApiResponse {
23 | public static final int ERROR = 1;
24 | public static final int WARNING = 2;
25 | public static final int INFO = 3;
26 | public static final int OK = 4;
27 | public static final int TOO_BUSY = 5;
28 |
29 | int code;
30 | String type;
31 | String message;
32 |
33 | public ApiResponse(){}
34 |
35 | public ApiResponse(int code, String message){
36 | this.code = code;
37 | switch(code){
38 | case ERROR:
39 | setType("error");
40 | break;
41 | case WARNING:
42 | setType("warning");
43 | break;
44 | case INFO:
45 | setType("info");
46 | break;
47 | case OK:
48 | setType("ok");
49 | break;
50 | case TOO_BUSY:
51 | setType("too busy");
52 | break;
53 | default:
54 | setType("unknown");
55 | break;
56 | }
57 | this.message = message;
58 | }
59 |
60 | @XmlTransient
61 | public int getCode() {
62 | return code;
63 | }
64 |
65 | public void setCode(int code) {
66 | this.code = code;
67 | }
68 |
69 | public String getType() {
70 | return type;
71 | }
72 |
73 | public void setType(String type) {
74 | this.type = type;
75 | }
76 |
77 | public String getMessage() {
78 | return message;
79 | }
80 |
81 | public void setMessage(String message) {
82 | this.message = message;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/model/Category.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.model;
18 |
19 | import javax.xml.bind.annotation.*;
20 |
21 | @XmlRootElement(name = "Category")
22 | public class Category {
23 | private long id;
24 | private String name;
25 |
26 | @XmlElement(name = "id")
27 | public long getId() {
28 | return id;
29 | }
30 |
31 | public void setId(long id) {
32 | this.id = id;
33 | }
34 |
35 | @XmlElement(name = "name")
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public void setName(String name) {
41 | this.name = name;
42 | }
43 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/model/Order.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.model;
18 |
19 | import io.swagger.annotations.*;
20 |
21 | import java.util.Date;
22 |
23 | import javax.xml.bind.annotation.*;
24 |
25 | @XmlRootElement(name = "Order")
26 | public class Order {
27 | private long id;
28 | private long petId;
29 | private int quantity;
30 | private Date shipDate;
31 | private String status;
32 | private boolean complete;
33 |
34 | @XmlElement(name = "id")
35 | public long getId() {
36 | return id;
37 | }
38 |
39 | public void setId(long id) {
40 | this.id = id;
41 | }
42 |
43 | public boolean isComplete() {
44 | return complete;
45 | }
46 |
47 | public void setComplete(boolean complete) {
48 | this.complete = complete;
49 | }
50 |
51 | @XmlElement(name = "petId")
52 | public long getPetId() {
53 | return petId;
54 | }
55 |
56 | public void setPetId(long petId) {
57 | this.petId = petId;
58 | }
59 |
60 | @XmlElement(name = "quantity")
61 | public int getQuantity() {
62 | return quantity;
63 | }
64 |
65 | public void setQuantity(int quantity) {
66 | this.quantity = quantity;
67 | }
68 |
69 | @XmlElement(name = "status")
70 | @ApiModelProperty(value = "Order Status", allowableValues = "placed, approved, delivered")
71 | public String getStatus() {
72 | return status;
73 | }
74 |
75 | public void setStatus(String status) {
76 | this.status = status;
77 | }
78 |
79 | @XmlElement(name = "shipDate")
80 | public Date getShipDate() {
81 | return shipDate;
82 | }
83 |
84 | public void setShipDate(Date shipDate) {
85 | this.shipDate = shipDate;
86 | }
87 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/model/Pet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.model;
18 |
19 | import io.swagger.annotations.*;
20 |
21 | import java.util.List;
22 | import java.util.ArrayList;
23 |
24 | import javax.xml.bind.annotation.*;
25 |
26 | @XmlRootElement(name = "Pet")
27 | public class Pet {
28 | private long id;
29 | private Category category;
30 | private String name;
31 | private List photoUrls = new ArrayList();
32 | private List tags = new ArrayList();
33 | private String status;
34 |
35 | @XmlElement(name = "id")
36 | public long getId() {
37 | return id;
38 | }
39 |
40 | public void setId(long id) {
41 | this.id = id;
42 | }
43 |
44 | @XmlElement(name = "category")
45 | public Category getCategory() {
46 | return category;
47 | }
48 |
49 | public void setCategory(Category category) {
50 | this.category = category;
51 | }
52 |
53 | @XmlElement(name = "name")
54 | @ApiModelProperty(example = "doggie", required = true)
55 | public String getName() {
56 | return name;
57 | }
58 |
59 | public void setName(String name) {
60 | this.name = name;
61 | }
62 |
63 | @XmlElementWrapper(name = "photoUrls")
64 | @XmlElement(name = "photoUrl", required = true)
65 | public List getPhotoUrls() {
66 | return photoUrls;
67 | }
68 |
69 | public void setPhotoUrls(List photoUrls) {
70 | this.photoUrls = photoUrls;
71 | }
72 |
73 | @XmlElementWrapper(name = "tags")
74 | @XmlElement(name = "tag")
75 | public List getTags() {
76 | return tags;
77 | }
78 |
79 | public void setTags(List tags) {
80 | this.tags = tags;
81 | }
82 |
83 | @XmlElement(name = "status")
84 | @ApiModelProperty(value = "pet status in the store", allowableValues = "available,pending,sold")
85 | public String getStatus() {
86 | return status;
87 | }
88 |
89 | public void setStatus(String status) {
90 | this.status = status;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/model/Tag.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.model;
18 |
19 | import javax.xml.bind.annotation.*;
20 |
21 | @XmlRootElement(name = "Tag")
22 | public class Tag {
23 | private long id;
24 | private String name;
25 |
26 | @XmlElement(name = "id")
27 | public long getId() {
28 | return id;
29 | }
30 |
31 | public void setId(long id) {
32 | this.id = id;
33 | }
34 |
35 | @XmlElement(name = "name")
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public void setName(String name) {
41 | this.name = name;
42 | }
43 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/model/User.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.model;
18 |
19 | import io.swagger.annotations.*;
20 |
21 | import javax.xml.bind.annotation.*;
22 |
23 | @XmlRootElement(name = "User")
24 | public class User {
25 | private long id;
26 | private String username;
27 | private String firstName;
28 | private String lastName;
29 | private String email;
30 | private String password;
31 | private String phone;
32 | private int userStatus;
33 |
34 | @XmlElement(name = "id")
35 | public long getId() {
36 | return id;
37 | }
38 |
39 | public void setId(long id) {
40 | this.id = id;
41 | }
42 |
43 | @XmlElement(name = "firstName")
44 | public String getFirstName() {
45 | return firstName;
46 | }
47 |
48 | public void setFirstName(String firstName) {
49 | this.firstName = firstName;
50 | }
51 |
52 | @XmlElement(name = "username")
53 | public String getUsername() {
54 | return username;
55 | }
56 |
57 | public void setUsername(String username) {
58 | this.username = username;
59 | }
60 |
61 | @XmlElement(name = "lastName")
62 | public String getLastName() {
63 | return lastName;
64 | }
65 |
66 | public void setLastName(String lastName) {
67 | this.lastName = lastName;
68 | }
69 |
70 | @XmlElement(name = "email")
71 | public String getEmail() {
72 | return email;
73 | }
74 |
75 | public void setEmail(String email) {
76 | this.email = email;
77 | }
78 |
79 | @XmlElement(name = "password")
80 | public String getPassword() {
81 | return password;
82 | }
83 |
84 | public void setPassword(String password) {
85 | this.password = password;
86 | }
87 |
88 | @XmlElement(name = "phone")
89 | public String getPhone() {
90 | return phone;
91 | }
92 |
93 | public void setPhone(String phone) {
94 | this.phone = phone;
95 | }
96 |
97 | @XmlElement(name = "userStatus")
98 | @ApiModelProperty(value = "User Status", allowableValues = "1-registered,2-active,3-closed")
99 | public int getUserStatus() {
100 | return userStatus;
101 | }
102 |
103 | public void setUserStatus(int userStatus) {
104 | this.userStatus = userStatus;
105 | }
106 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/resource/JavaRestResourceUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.resource;
18 |
19 | import java.text.SimpleDateFormat;
20 |
21 | import java.util.Date;
22 |
23 | public class JavaRestResourceUtil {
24 | public int getInt(int minVal, int maxVal, int defaultValue, String inputString) {
25 | int output = defaultValue;
26 | try {
27 | output = Integer.parseInt(inputString);
28 | }
29 | catch (Exception e){
30 | output = defaultValue;
31 | }
32 |
33 | if (output < minVal) output = minVal;
34 | if (maxVal == -1) {
35 | if (output < minVal) output = minVal;
36 | }
37 | else if (output > maxVal) output = maxVal;
38 | return output;
39 | }
40 |
41 | public long getLong(long minVal, long maxVal, long defaultValue, String inputString) {
42 | long output = defaultValue;
43 | try {
44 | output = Long.parseLong(inputString);
45 | }
46 | catch (Exception e){
47 | output = defaultValue;
48 | }
49 |
50 | if (output < minVal) output = minVal;
51 | if (maxVal == -1) { if (output < minVal) output = minVal; }
52 | else if (output > maxVal) output = maxVal;
53 | return output;
54 | }
55 |
56 | public double getDouble(double minVal, double maxVal, double defaultValue, String inputString) {
57 | double output = defaultValue;
58 | try {
59 | output = Double.parseDouble(inputString);
60 | }
61 | catch (Exception e){
62 | output = defaultValue;
63 | }
64 |
65 | if (output < minVal) output = minVal;
66 | if (maxVal == -1) {
67 | if (output < minVal) output = minVal;
68 | }
69 | else if (output > maxVal) output = maxVal;
70 | return output;
71 | }
72 |
73 | public boolean getBoolean(boolean defaultValue, String booleanString) {
74 | boolean output = defaultValue;
75 | if (booleanString == null) output = defaultValue;
76 |
77 | // treat "", "YES" as "true"
78 | if ("".equals(booleanString)) output = true;
79 | else if ("YES".equalsIgnoreCase(booleanString)) output = true;
80 | else if ("NO".equalsIgnoreCase(booleanString)) output = false;
81 | else {
82 | try {
83 | output = Boolean.parseBoolean(booleanString);
84 | }
85 | catch (Exception e){
86 | output = defaultValue;
87 | }
88 | }
89 | return output;
90 | }
91 |
92 | public Date getDate(Date defaultValue, String dateString){
93 | try {
94 | return new SimpleDateFormat("yyyy-MM-dd").parse(dateString);
95 | }
96 | catch(Exception e) {
97 | return defaultValue;
98 | }
99 | }
100 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/resource/PetResource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.resource;
18 |
19 | import com.github.kongchen.swagger.sample.wordnik.data.PetData;
20 | import io.swagger.annotations.*;
21 | import com.github.kongchen.swagger.sample.wordnik.model.Pet;
22 | import io.swagger.annotations.ApiResponse;
23 |
24 | import javax.ws.rs.core.Response;
25 | import javax.ws.rs.core.MediaType;
26 | import javax.ws.rs.*;
27 |
28 | @Path("/pet")
29 | @Api(value = "/pet", description = "Operations about pets", authorizations = {
30 | @Authorization(value = "petstore_auth",
31 | scopes = {
32 | @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
33 | @AuthorizationScope(scope = "read:pets", description = "read your pets")
34 | })
35 | })
36 | @Produces({"application/json", "application/xml"})
37 | public class PetResource {
38 | static PetData petData = new PetData();
39 | static JavaRestResourceUtil ru = new JavaRestResourceUtil();
40 |
41 | @GET
42 | @Path("/{petId}")
43 | @ApiOperation(value = "Find pet by ID",
44 | notes = "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
45 | response = Pet.class,
46 | authorizations = @Authorization(value = "api_key")
47 | )
48 | @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
49 | @ApiResponse(code = 404, message = "Pet not found") })
50 | public Response getPetById(
51 | @ApiParam(value = "ID of pet that needs to be fetched", allowableValues = "range[1,5]", required = true) @PathParam("petId") Long petId)
52 | throws com.github.kongchen.swagger.sample.wordnik.exception.NotFoundException {
53 | Pet pet = petData.getPetbyId(petId);
54 | if (null != pet) {
55 | return Response.ok().entity(pet).build();
56 | } else {
57 | throw new com.github.kongchen.swagger.sample.wordnik.exception.NotFoundException(404, "Pet not found");
58 | }
59 | }
60 |
61 | @DELETE
62 | @Path("/{petId}")
63 | @ApiOperation(value = "Deletes a pet")
64 | @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid pet value")})
65 | public Response deletePet(
66 | @ApiParam() @HeaderParam("api_key") String apiKey,
67 | @ApiParam(value = "Pet id to delete", required = true)@PathParam("petId") Long petId) {
68 | petData.deletePet(petId);
69 | return Response.ok().build();
70 | }
71 |
72 | @POST
73 | @Consumes({"application/json", "application/xml"})
74 | @ApiOperation(value = "Add a new pet to the store")
75 | @ApiResponses(value = { @ApiResponse(code = 405, message = "Invalid input") })
76 | public Response addPet(
77 | @ApiParam(value = "Pet object that needs to be added to the store", required = true) Pet pet) {
78 | Pet updatedPet = petData.addPet(pet);
79 | return Response.ok().entity(updatedPet).build();
80 | }
81 |
82 | @PUT
83 | @Consumes({"application/json", "application/xml"})
84 | @ApiOperation(value = "Update an existing pet")
85 | @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
86 | @ApiResponse(code = 404, message = "Pet not found"),
87 | @ApiResponse(code = 405, message = "Validation exception") })
88 | public Response updatePet(
89 | @ApiParam(value = "Pet object that needs to be added to the store", required = true) Pet pet) {
90 | Pet updatedPet = petData.addPet(pet);
91 | return Response.ok().entity(updatedPet).build();
92 | }
93 |
94 | @GET
95 | @Path("/findByStatus")
96 | @ApiOperation(value = "Finds Pets by status",
97 | notes = "Multiple status values can be provided with comma seperated strings",
98 | response = Pet.class,
99 | responseContainer = "List")
100 | @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid status value") })
101 | public Response findPetsByStatus(
102 | @ApiParam(value = "Status values that need to be considered for filter", required = true, defaultValue = "available", allowableValues = "available,pending,sold", allowMultiple = true) @QueryParam("status") String status) {
103 | return Response.ok(petData.findPetByStatus(status)).build();
104 | }
105 |
106 | @GET
107 | @Path("/findByTags")
108 | @ApiOperation(value = "Finds Pets by tags",
109 | notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
110 | response = Pet.class,
111 | responseContainer = "List")
112 | @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") })
113 | @Deprecated
114 | public Response findPetsByTags(
115 | @ApiParam(value = "Tags to filter by", required = true, allowMultiple = true) @QueryParam("tags") String tags) {
116 | return Response.ok(petData.findPetByTags(tags)).build();
117 | }
118 |
119 | @POST
120 | @Path("/{petId}")
121 | @Consumes({MediaType.APPLICATION_FORM_URLENCODED})
122 | @ApiOperation(value = "Updates a pet in the store with form data",
123 | consumes = MediaType.APPLICATION_FORM_URLENCODED)
124 | @ApiResponses(value = {
125 | @ApiResponse(code = 405, message = "Invalid input")})
126 | public Response updatePetWithForm (
127 | @ApiParam(value = "ID of pet that needs to be updated", required = true)@PathParam("petId") String petId,
128 | @ApiParam(value = "Updated name of the pet", required = false)@FormParam("name") String name,
129 | @ApiParam(value = "Updated status of the pet", required = false)@FormParam("status") String status) {
130 | System.out.println(name);
131 | System.out.println(status);
132 | return Response.ok().entity(new com.github.kongchen.swagger.sample.wordnik.model.ApiResponse(200, "SUCCESS")).build();
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/resource/PetStoreResource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.resource;
18 |
19 | import io.swagger.annotations.*;
20 | import com.github.kongchen.swagger.sample.wordnik.data.StoreData;
21 | import com.github.kongchen.swagger.sample.wordnik.model.Order;
22 | import com.github.kongchen.swagger.sample.wordnik.exception.NotFoundException;
23 |
24 | import javax.ws.rs.core.Response;
25 | import javax.ws.rs.*;
26 |
27 | @Path("/store")
28 | @Api(value="/store" , description = "Operations about store")
29 | @Produces({"application/json", "application/xml"})
30 | public class PetStoreResource {
31 | static StoreData storeData = new StoreData();
32 | static JavaRestResourceUtil ru = new JavaRestResourceUtil();
33 |
34 | @GET
35 | @Path("/order/{orderId}")
36 | @ApiOperation(value = "Find purchase order by ID",
37 | notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
38 | response = Order.class)
39 | @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
40 | @ApiResponse(code = 404, message = "Order not found") })
41 | public Response getOrderById(
42 | @ApiParam(value = "ID of pet that needs to be fetched", allowableValues = "range[1,5]", required = true) @PathParam("orderId") String orderId)
43 | throws NotFoundException {
44 | Order order = storeData.findOrderById(ru.getLong(0, 10000, 0, orderId));
45 | if (null != order) {
46 | return Response.ok().entity(order).build();
47 | } else {
48 | throw new NotFoundException(404, "Order not found");
49 | }
50 | }
51 |
52 | @POST
53 | @Path("/order")
54 | @ApiOperation(value = "Place an order for a pet")
55 | @ApiResponses({ @ApiResponse(code = 400, message = "Invalid Order") })
56 | public Order placeOrder(
57 | @ApiParam(value = "order placed for purchasing the pet",
58 | required = true) Order order) {
59 | storeData.placeOrder(order);
60 | return storeData.placeOrder(order);
61 | }
62 |
63 | @DELETE
64 | @Path("/order/{orderId}")
65 | @ApiOperation(value = "Delete purchase order by ID",
66 | notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors")
67 | @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
68 | @ApiResponse(code = 404, message = "Order not found") })
69 | public Response deleteOrder(
70 | @ApiParam(value = "ID of the order that needs to be deleted", allowableValues = "range[1,infinity]", required = true) @PathParam("orderId") String orderId) {
71 | storeData.deleteOrder(ru.getLong(0, 10000, 0, orderId));
72 | return Response.ok().entity("").build();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/com/github/kongchen/swagger/sample/wordnik/resource/UserResource.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2014 Reverb Technologies, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.kongchen.swagger.sample.wordnik.resource;
18 |
19 | import io.swagger.annotations.*;
20 | import com.github.kongchen.swagger.sample.wordnik.data.UserData;
21 | import com.github.kongchen.swagger.sample.wordnik.model.User;
22 | import com.github.kongchen.swagger.sample.wordnik.exception.ApiException;
23 |
24 | import javax.ws.rs.core.Response;
25 | import javax.ws.rs.*;
26 |
27 | @Path("/user")
28 | @Api(value="/user", description = "Operations about user")
29 | @Produces({"application/json", "application/xml"})
30 | public class UserResource {
31 | static UserData userData = new UserData();
32 |
33 | @POST
34 | @ApiOperation(value = "Create user",
35 | notes = "This can only be done by the logged in user.",
36 | position = 1)
37 | public Response createUser(
38 | @ApiParam(value = "Created user object", required = true) User user) {
39 | userData.addUser(user);
40 | return Response.ok().entity("").build();
41 | }
42 |
43 | @POST
44 | @Path("/createWithArray")
45 | @ApiOperation(value = "Creates list of users with given input array",
46 | position = 2)
47 | public Response createUsersWithArrayInput(@ApiParam(value = "List of user object", required = true) User[] users) {
48 | for (User user : users) {
49 | userData.addUser(user);
50 | }
51 | return Response.ok().entity("").build();
52 | }
53 |
54 | @POST
55 | @Path("/createWithList")
56 | @ApiOperation(value = "Creates list of users with given input array",
57 | position = 3)
58 | public Response createUsersWithListInput(@ApiParam(value = "List of user object", required = true) java.util.List users) {
59 | for (User user : users) {
60 | userData.addUser(user);
61 | }
62 | return Response.ok().entity("").build();
63 | }
64 |
65 | @PUT
66 | @Path("/{username}")
67 | @ApiOperation(value = "Updated user",
68 | notes = "This can only be done by the logged in user.",
69 | position = 4)
70 | @ApiResponses(value = {
71 | @ApiResponse(code = 400, message = "Invalid user supplied"),
72 | @ApiResponse(code = 404, message = "User not found") })
73 | public Response updateUser(
74 | @ApiParam(value = "name that need to be deleted", required = true) @PathParam("username") String username,
75 | @ApiParam(value = "Updated user object", required = true) User user) {
76 | userData.addUser(user);
77 | return Response.ok().entity("").build();
78 | }
79 |
80 | @DELETE
81 | @Path("/{username}")
82 | @ApiOperation(value = "Delete user",
83 | notes = "This can only be done by the logged in user.",
84 | position = 5)
85 | @ApiResponses(value = {
86 | @ApiResponse(code = 400, message = "Invalid username supplied"),
87 | @ApiResponse(code = 404, message = "User not found") })
88 | public Response deleteUser(
89 | @ApiParam(value = "The name that needs to be deleted", required = true) @PathParam("username") String username) {
90 | userData.removeUser(username);
91 | return Response.ok().entity("").build();
92 | }
93 |
94 | @GET
95 | @Path("/{username}")
96 | @ApiOperation(value = "Get user by user name",
97 | response = User.class,
98 | position = 0)
99 | @ApiResponses(value = {
100 | @ApiResponse(code = 400, message = "Invalid username supplied"),
101 | @ApiResponse(code = 404, message = "User not found") })
102 | public Response getUserByName(
103 | @ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ", required = true) @PathParam("username") String username)
104 | throws ApiException {
105 | User user = userData.findUserByName(username);
106 | if (null != user) {
107 | return Response.ok().entity(user).build();
108 | } else {
109 | throw new com.github.kongchen.swagger.sample.wordnik.exception.NotFoundException(404, "User not found");
110 | }
111 | }
112 |
113 | @GET
114 | @Path("/login")
115 | @ApiOperation(value = "Logs user into the system",
116 | response = String.class,
117 | position = 6)
118 | @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid username/password supplied") })
119 | public Response loginUser(
120 | @ApiParam(value = "The user name for login", required = true) @QueryParam("username") String username,
121 | @ApiParam(value = "The password for login in clear text", required = true) @QueryParam("password") String password) {
122 | return Response.ok()
123 | .entity("logged in user session:" + System.currentTimeMillis())
124 | .build();
125 | }
126 |
127 | @GET
128 | @Path("/logout")
129 | @ApiOperation(value = "Logs out current logged in user session",
130 | position = 7)
131 | public Response logoutUser() {
132 | return Response.ok().entity("").build();
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/resources/securityDefinitions.json:
--------------------------------------------------------------------------------
1 | {
2 | "api_key": {
3 | "type": "apiKey",
4 | "name": "api_key",
5 | "in": "header"
6 | },
7 | "petstore_auth": {
8 | "type": "oauth2",
9 | "authorizationUrl": "http://swagger.io/api/oauth/dialog",
10 | "flow": "implicit",
11 | "scopes": {
12 | "write:pets": "modify pets in your account",
13 | "read:pets": "read your pets"
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | jersey
8 | org.glassfish.jersey.servlet.ServletContainer
9 |
10 | jersey.config.server.provider.packages
11 |
12 | io.swagger.jaxrs.json,
13 | com.github.kongchen.swagger.sample.wordnik.resource
14 |
15 |
16 |
17 | jersey.config.server.provider.classnames
18 |
19 | io.swagger.jersey.listing.ApiListingResourceJSON,
20 | io.swagger.jersey.listing.JerseyApiDeclarationProvider,
21 | io.swagger.jersey.listing.JerseyResourceListingProvider
22 |
23 |
24 |
25 | jersey.config.server.wadl.disableWadl
26 | true
27 |
28 | 1
29 |
30 |
31 |
32 | jersey
33 | /api/*
34 |
35 |
36 |
37 | Jersey2Config
38 | io.swagger.jersey.config.JerseyJaxrsConfig
39 |
40 | api.version
41 | 1.0.0
42 |
43 |
44 | swagger.api.basepath
45 | http://localhost:8002/api
46 |
47 |
48 | swagger.filter
49 | com.github.kongchen.swagger.sample.wordnik.util.ApiAuthorizationFilterImpl
50 |
51 | 2
52 |
53 |
54 |
55 | ApiOriginFilter
56 | com.github.kongchen.swagger.sample.wordnik.util.ApiOriginFilter
57 |
58 |
59 | Bootstrap
60 | com.github.kongchen.swagger.sample.wordnik.Bootstrap
61 | 2
62 |
63 |
64 | ApiOriginFilter
65 | /*
66 |
67 |
--------------------------------------------------------------------------------
/templates/markdown.hbs:
--------------------------------------------------------------------------------
1 | #{{#info}}{{title}}
2 |
3 |
4 | ## {{join schemes " | "}}://{{host}}{{basePath}}
5 |
6 |
7 | {{description}}
8 |
9 | {{#contact}}
10 | [**Contact the developer**](mailto:{{email}})
11 | {{/contact}}
12 |
13 | **Version** {{version}}
14 |
15 | [**Terms of Service**]({{termsOfService}})
16 |
17 | {{#license}}[**{{name}}**]({{url}}){{/license}}
18 |
19 | {{/info}}
20 |
21 | {{#if consumes}}**Consumes:** {{join consumes ", "}}{{/if}}
22 |
23 | {{#if produces}}**Produces:** {{join produces ", "}}{{/if}}
24 |
25 | {{#if securityDefinitions}}
26 | # Security Definitions
27 | {{/if}}
28 | {{> security}}
29 |
30 | # APIs
31 |
32 | {{#each paths}}
33 | ## {{@key}}
34 | {{#this}}
35 | {{#get}}
36 | ### GET
37 | {{> operation}}
38 | {{/get}}
39 |
40 | {{#put}}
41 | ### PUT
42 | {{> operation}}
43 | {{/put}}
44 |
45 | {{#post}}
46 | ### POST
47 |
48 | {{> operation}}
49 |
50 | {{/post}}
51 |
52 | {{#delete}}
53 | ### DELETE
54 | {{> operation}}
55 | {{/delete}}
56 |
57 | {{#option}}
58 | ### OPTION
59 | {{> operation}}
60 | {{/option}}
61 |
62 | {{#patch}}
63 | ### PATCH
64 | {{> operation}}
65 | {{/patch}}
66 |
67 | {{#head}}
68 | ### HEAD
69 | {{> operation}}
70 | {{/head}}
71 |
72 | {{/this}}
73 | {{/each}}
74 |
75 | # Definitions
76 | {{#each definitions}}
77 | ## {{@key}}
78 |
79 |
80 |
81 | name |
82 | type |
83 | required |
84 | description |
85 | example |
86 |
87 | {{#each this.properties}}
88 |
89 | {{@key}} |
90 |
91 | {{#ifeq type "array"}}
92 | {{#items.$ref}}
93 | {{type}}[{{basename items.$ref}}]
94 | {{/items.$ref}}
95 | {{^items.$ref}}{{type}}[{{items.type}}]{{/items.$ref}}
96 | {{else}}
97 | {{#$ref}}{{basename $ref}}{{/$ref}}
98 | {{^$ref}}{{type}}{{#format}} ({{format}}){{/format}}{{/$ref}}
99 | {{/ifeq}}
100 | |
101 | {{#required}}required{{/required}}{{^required}}optional{{/required}} |
102 | {{#description}}{{{description}}}{{/description}}{{^description}}-{{/description}} |
103 | {{example}} |
104 |
105 | {{/each}}
106 |
107 | {{/each}}
108 |
109 |
--------------------------------------------------------------------------------
/templates/operation.hbs:
--------------------------------------------------------------------------------
1 | {{#deprecated}}-deprecated-{{/deprecated}}
2 | {{summary}}
3 |
4 | {{description}}
5 |
6 | {{#if externalDocs.url}}{{externalDocs.description}}. [See external documents for more details]({{externalDocs.url}})
7 | {{/if}}
8 |
9 | {{#if security}}
10 | #### Security
11 | {{/if}}
12 |
13 | {{#security}}
14 | {{#each this}}
15 | * {{@key}}
16 | {{#this}} * {{this}}
17 | {{/this}}
18 | {{/each}}
19 | {{/security}}
20 |
21 | #### Request
22 |
23 | {{#if consumes}}
24 | **Content-Type: ** {{join consumes ", "}}{{/if}}
25 |
26 | ##### Parameters
27 | {{#if parameters}}
28 |
29 |
30 | Name |
31 | Located in |
32 | Required |
33 | Description |
34 | Default |
35 | Schema |
36 |
37 | {{/if}}
38 |
39 | {{#parameters}}
40 |
41 | {{name}} |
42 | {{in}} |
43 | {{#if required}}yes{{else}}no{{/if}} |
44 | {{description}}{{#if pattern}} (**Pattern**: `{{pattern}}`){{/if}} |
45 | - |
46 | {{#ifeq in "body"}}
47 |
48 | {{#ifeq schema.type "array"}}Array[{{basename schema.items.$ref}}]{{/ifeq}}
49 | {{#schema.$ref}}{{basename schema.$ref}} {{/schema.$ref}}
50 | |
51 | {{else}}
52 | {{#ifeq type "array"}}
53 | Array[{{items.type}}] ({{collectionFormat}}) |
54 | {{else}}
55 | {{type}} {{#format}}({{format}}){{/format}} |
56 | {{/ifeq}}
57 | {{/ifeq}}
58 |
59 | {{/parameters}}
60 | {{#if parameters}}
61 |
62 | {{/if}}
63 |
64 |
65 | #### Response
66 |
67 | {{#if produces}}**Content-Type: ** {{join produces ", "}}{{/if}}
68 |
69 |
70 | | Status Code | Reason | Response Model |
71 | |-------------|-------------|----------------|
72 | {{#each responses}}| {{@key}} | {{description}} | {{#schema.$ref}}{{basename schema.$ref}}{{/schema.$ref}}{{#ifeq schema.type "array"}}Array[{{basename schema.items.$ref}}]{{/ifeq}}{{^schema}} - {{/schema}}|
73 | {{/each}}
74 |
--------------------------------------------------------------------------------
/templates/security.hbs:
--------------------------------------------------------------------------------
1 | {{#each securityDefinitions}}
2 | ### {{@key}}
3 | {{#this}}
4 | {{#ifeq type "oauth2"}}
5 |
6 |
7 | type |
8 | {{type}} |
9 |
10 | {{#if description}}
11 |
12 | description |
13 | {{description}} |
14 |
15 | {{/if}}
16 | {{#if authorizationUrl}}
17 |
18 | authorizationUrl |
19 | {{authorizationUrl}} |
20 |
21 | {{/if}}
22 | {{#if flow}}
23 |
24 | flow |
25 | {{flow}} |
26 |
27 | {{/if}}
28 | {{#if tokenUrl}}
29 |
30 | tokenUrl |
31 | {{tokenUrl}} |
32 |
33 | {{/if}}
34 | {{#if scopes}}
35 |
36 | scopes |
37 | {{#each scopes}}
38 | {{@key}} |
39 | {{this}} |
40 |
41 |
42 | {{/each}}
43 |
44 | {{/if}}
45 |
46 | {{/ifeq}}
47 | {{#ifeq type "apiKey"}}
48 |
49 |
50 | type |
51 | {{type}} |
52 |
53 | {{#if description}}
54 |
55 | description |
56 | {{description}} |
57 |
58 | {{/if}}
59 | {{#if name}}
60 |
61 | name |
62 | {{name}} |
63 |
64 | {{/if}}
65 | {{#if in}}
66 |
67 | in |
68 | {{in}} |
69 |
70 | {{/if}}
71 |
72 | {{/ifeq}}
73 | {{#ifeq type "basic"}}
74 |
75 |
76 | type |
77 | {{type}} |
78 |
79 | {{#if description}}
80 |
81 | description |
82 | {{description}} |
83 |
84 | {{/if}}
85 |
86 | {{/ifeq}}
87 | {{/this}}
88 | {{/each}}
--------------------------------------------------------------------------------
/templates/strapdown.html.hbs:
--------------------------------------------------------------------------------
1 |
2 |
3 | API Document
4 |
5 |
6 | {{>markdown}}
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------