2
2
3
3
import io .swagger .jaxrs2 .annotations .AbstractAnnotationTest ;
4
4
import io .swagger .jaxrs2 .resources .PetResource ;
5
+ import io .swagger .jaxrs2 .resources .UserResource ;
5
6
import io .swagger .oas .annotations .Operation ;
6
7
import io .swagger .oas .annotations .media .Content ;
7
8
import io .swagger .oas .annotations .media .ExampleObject ;
@@ -208,13 +209,13 @@ public void simpleGet() {
208
209
}
209
210
}
210
211
211
- @ Test (description = "reads an operation from sample" )
212
- public void testCompleteOperation () {
212
+ @ Test (description = "reads the pet resource from sample" )
213
+ public void testCompletePetResource () {
213
214
String openApiYAML = readIntoYaml (PetResource .class );
214
215
int start = 0 ;
215
216
int end = openApiYAML .length () - 1 ;
216
217
String extractedYAML = openApiYAML .substring (start , end );
217
- String expectedYAML = "openapi: 3.0.0-rc2 \n " +
218
+ String expectedYAML = "openapi: 3.0.0\n " +
218
219
"paths:\n " +
219
220
" /pet/{petId}:\n " +
220
221
" get:\n " +
@@ -226,7 +227,6 @@ public void testCompleteOperation() {
226
227
" in: path\n " +
227
228
" description: ID of pet that needs to be fetched\n " +
228
229
" required: true\n " +
229
- " explode: false\n " +
230
230
" schema:\n " +
231
231
" type: integer\n " +
232
232
" format: int64\n " +
@@ -288,7 +288,6 @@ public void testCompleteOperation() {
288
288
" in: query\n " +
289
289
" description: Status values that need to be considered for filter\n " +
290
290
" required: true\n " +
291
- " explode: false\n " +
292
291
" schema:\n " +
293
292
" type: string\n " +
294
293
" - name: skip\n " +
@@ -319,7 +318,6 @@ public void testCompleteOperation() {
319
318
" in: query\n " +
320
319
" description: Tags to filter by\n " +
321
320
" required: true\n " +
322
- " explode: false\n " +
323
321
" schema:\n " +
324
322
" type: string\n " +
325
323
" responses:\n " +
@@ -341,6 +339,8 @@ public void testCompleteOperation() {
341
339
" format: int64\n " +
342
340
" name:\n " +
343
341
" type: string\n " +
342
+ " xml:\n " +
343
+ " name: Category\n " +
344
344
" Tag:\n " +
345
345
" type: object\n " +
346
346
" properties:\n " +
@@ -349,6 +349,8 @@ public void testCompleteOperation() {
349
349
" format: int64\n " +
350
350
" name:\n " +
351
351
" type: string\n " +
352
+ " xml:\n " +
353
+ " name: Tag\n " +
352
354
" Pet:\n " +
353
355
" type: object\n " +
354
356
" properties:\n " +
@@ -361,17 +363,210 @@ public void testCompleteOperation() {
361
363
" type: string\n " +
362
364
" photoUrls:\n " +
363
365
" type: array\n " +
366
+ " xml:\n " +
367
+ " wrapped: true\n " +
364
368
" items:\n " +
365
369
" type: string\n " +
370
+ " xml:\n " +
371
+ " name: photoUrl\n " +
366
372
" tags:\n " +
367
373
" type: array\n " +
374
+ " xml:\n " +
375
+ " wrapped: true\n " +
368
376
" items:\n " +
369
377
" $ref: '#/components/schemas/Tag'\n " +
370
378
" status:\n " +
371
379
" type: string\n " +
372
380
" description: pet status in the store\n " +
373
381
" enum:\n " +
374
- " - available,pending,sold" ;
382
+ " - available,pending,sold\n " +
383
+ " xml:\n " +
384
+ " name: Pet" ;
385
+ assertEquals (extractedYAML , expectedYAML );
386
+ }
387
+
388
+ @ Test (description = "reads the user resource from sample" )
389
+ public void testCompleteUserResource () {
390
+ String openApiYAML = readIntoYaml (UserResource .class );
391
+ int start = 0 ;
392
+ int end = openApiYAML .length () - 1 ;
393
+ String extractedYAML = openApiYAML .substring (start , end );
394
+ String expectedYAML = "openapi: 3.0.0\n " +
395
+ "paths:\n " +
396
+ " /user:\n " +
397
+ " post:\n " +
398
+ " summary: Create user\n " +
399
+ " description: This can only be done by the logged in user.\n " +
400
+ " operationId: createUser\n " +
401
+ " requestBody:\n " +
402
+ " description: Created user object\n " +
403
+ " content:\n " +
404
+ " '*/*':\n " +
405
+ " schema:\n " +
406
+ " $ref: '#/components/schemas/User'\n " +
407
+ " required: true\n " +
408
+ " responses:\n " +
409
+ " default:\n " +
410
+ " description: no description\n " +
411
+ " /user/createWithArray:\n " +
412
+ " post:\n " +
413
+ " summary: Creates list of users with given input array\n " +
414
+ " operationId: createUsersWithArrayInput\n " +
415
+ " requestBody:\n " +
416
+ " description: List of user object\n " +
417
+ " content:\n " +
418
+ " '*/*':\n " +
419
+ " schema:\n " +
420
+ " type: array\n " +
421
+ " items:\n " +
422
+ " $ref: '#/components/schemas/User'\n " +
423
+ " required: true\n " +
424
+ " responses:\n " +
425
+ " default:\n " +
426
+ " description: no description\n " +
427
+ " /user/createWithList:\n " +
428
+ " post:\n " +
429
+ " summary: Creates list of users with given input array\n " +
430
+ " operationId: createUsersWithListInput\n " +
431
+ " requestBody:\n " +
432
+ " description: List of user object\n " +
433
+ " content:\n " +
434
+ " '*/*':\n " +
435
+ " schema:\n " +
436
+ " type: array\n " +
437
+ " items:\n " +
438
+ " $ref: '#/components/schemas/User'\n " +
439
+ " required: true\n " +
440
+ " responses:\n " +
441
+ " default:\n " +
442
+ " description: no description\n " +
443
+ " /user/{username}:\n " +
444
+ " get:\n " +
445
+ " summary: Get user by user name\n " +
446
+ " operationId: getUserByName\n " +
447
+ " parameters:\n " +
448
+ " - name: username\n " +
449
+ " in: path\n " +
450
+ " description: 'The name that needs to be fetched. Use user1 for testing. '\n " +
451
+ " required: true\n " +
452
+ " schema:\n " +
453
+ " type: string\n " +
454
+ " responses:\n " +
455
+ " default:\n " +
456
+ " description: The user\n " +
457
+ " content:\n " +
458
+ " application/json:\n " +
459
+ " schema:\n " +
460
+ " $ref: '#/components/schemas/User'\n " +
461
+ " 400:\n " +
462
+ " description: User not found\n " +
463
+ " put:\n " +
464
+ " summary: Updated user\n " +
465
+ " description: This can only be done by the logged in user.\n " +
466
+ " operationId: updateUser\n " +
467
+ " parameters:\n " +
468
+ " - name: username\n " +
469
+ " in: path\n " +
470
+ " description: name that need to be deleted\n " +
471
+ " required: true\n " +
472
+ " schema:\n " +
473
+ " type: string\n " +
474
+ " requestBody:\n " +
475
+ " description: Updated user object\n " +
476
+ " content:\n " +
477
+ " '*/*':\n " +
478
+ " schema:\n " +
479
+ " $ref: '#/components/schemas/User'\n " +
480
+ " required: true\n " +
481
+ " responses:\n " +
482
+ " 200:\n " +
483
+ " description: user updated\n " +
484
+ " 400:\n " +
485
+ " description: Invalid user supplied\n " +
486
+ " 404:\n " +
487
+ " description: User not found\n " +
488
+ " delete:\n " +
489
+ " summary: Delete user\n " +
490
+ " description: This can only be done by the logged in user.\n " +
491
+ " operationId: deleteUser\n " +
492
+ " parameters:\n " +
493
+ " - name: username\n " +
494
+ " in: path\n " +
495
+ " description: The name that needs to be deleted\n " +
496
+ " required: true\n " +
497
+ " schema:\n " +
498
+ " type: string\n " +
499
+ " responses:\n " +
500
+ " 200:\n " +
501
+ " description: user deteled\n " +
502
+ " 400:\n " +
503
+ " description: Invalid username supplied\n " +
504
+ " 404:\n " +
505
+ " description: User not found\n " +
506
+ " /user/login:\n " +
507
+ " get:\n " +
508
+ " summary: Logs user into the system\n " +
509
+ " operationId: loginUser\n " +
510
+ " parameters:\n " +
511
+ " - name: username\n " +
512
+ " in: query\n " +
513
+ " description: The user name for login\n " +
514
+ " required: true\n " +
515
+ " schema:\n " +
516
+ " type: string\n " +
517
+ " - name: password\n " +
518
+ " in: query\n " +
519
+ " description: The password for login in clear text\n " +
520
+ " required: true\n " +
521
+ " schema:\n " +
522
+ " type: string\n " +
523
+ " responses:\n " +
524
+ " default:\n " +
525
+ " description: Successfully logged in\n " +
526
+ " content:\n " +
527
+ " application/json:\n " +
528
+ " schema:\n " +
529
+ " type: string\n " +
530
+ " application/xml:\n " +
531
+ " schema:\n " +
532
+ " type: string\n " +
533
+ " 400:\n " +
534
+ " description: Invalid username/password supplied\n " +
535
+ " /user/logout:\n " +
536
+ " get:\n " +
537
+ " summary: Logs out current logged in user session\n " +
538
+ " operationId: logoutUser\n " +
539
+ " responses:\n " +
540
+ " default:\n " +
541
+ " description: no description\n " +
542
+ "components:\n " +
543
+ " schemas:\n " +
544
+ " User:\n " +
545
+ " type: object\n " +
546
+ " properties:\n " +
547
+ " id:\n " +
548
+ " type: integer\n " +
549
+ " format: int64\n " +
550
+ " username:\n " +
551
+ " type: string\n " +
552
+ " firstName:\n " +
553
+ " type: string\n " +
554
+ " lastName:\n " +
555
+ " type: string\n " +
556
+ " email:\n " +
557
+ " type: string\n " +
558
+ " password:\n " +
559
+ " type: string\n " +
560
+ " phone:\n " +
561
+ " type: string\n " +
562
+ " userStatus:\n " +
563
+ " type: integer\n " +
564
+ " description: User Status\n " +
565
+ " format: int32\n " +
566
+ " enum:\n " +
567
+ " - null\n " +
568
+ " xml:\n " +
569
+ " name: User" ;
375
570
assertEquals (extractedYAML , expectedYAML );
376
571
}
377
572
}
0 commit comments