|
10 | 10 | import { schema, Type } from '@kbn/config-schema';
|
11 | 11 | import { get } from 'lodash';
|
12 | 12 | import { generateOpenApiDocument } from './generate_oas';
|
13 |
| -import { createTestRouters, createRouter, createVersionedRouter } from './generate_oas.test.util'; |
| 13 | +import { |
| 14 | + createTestRouters, |
| 15 | + createRouter, |
| 16 | + createVersionedRouter, |
| 17 | + CreateTestRouterArgs, |
| 18 | +} from './generate_oas.test.util'; |
14 | 19 | import {
|
15 | 20 | sharedOas,
|
16 | 21 | createSharedZodSchema,
|
@@ -380,129 +385,206 @@ describe('generateOpenApiDocument', () => {
|
380 | 385 | });
|
381 | 386 |
|
382 | 387 | describe('availability', () => {
|
383 |
| - it('creates the expected availability entries', async () => { |
384 |
| - const [routers, versionedRouters] = createTestRouters({ |
385 |
| - routers: { |
386 |
| - testRouter1: { |
387 |
| - routes: [ |
388 |
| - { |
389 |
| - path: '/1-1/{id}/{path*}', |
390 |
| - options: { availability: { stability: 'experimental' }, access: 'public' }, |
391 |
| - }, |
392 |
| - { |
393 |
| - path: '/1-2/{id}/{path*}', |
394 |
| - options: { availability: { stability: 'beta' }, access: 'public' }, |
395 |
| - }, |
396 |
| - { |
397 |
| - path: '/1-3/{id}/{path*}', |
398 |
| - options: { availability: { stability: 'stable' }, access: 'public' }, |
399 |
| - }, |
400 |
| - ], |
| 388 | + const testCases = [ |
| 389 | + { |
| 390 | + name: 'router with experimental stability', |
| 391 | + routerConfig: { |
| 392 | + routers: { |
| 393 | + testRouter: { |
| 394 | + routes: [ |
| 395 | + { |
| 396 | + path: '/test-path/{id}/{path*}', |
| 397 | + options: { availability: { stability: 'experimental' }, access: 'public' }, |
| 398 | + }, |
| 399 | + ], |
| 400 | + }, |
401 | 401 | },
|
402 |
| - testRouter2: { |
403 |
| - routes: [{ path: '/2-1/{id}/{path*}' }], |
| 402 | + versionedRouters: {}, |
| 403 | + } as CreateTestRouterArgs, |
| 404 | + expectedPath: '/test-path/{id}/{path}', |
| 405 | + expectedState: 'Technical Preview', |
| 406 | + }, |
| 407 | + { |
| 408 | + name: 'router with beta stability', |
| 409 | + routerConfig: { |
| 410 | + routers: { |
| 411 | + testRouter: { |
| 412 | + routes: [ |
| 413 | + { |
| 414 | + path: '/test-path/{id}/{path*}', |
| 415 | + options: { availability: { stability: 'beta' }, access: 'public' }, |
| 416 | + }, |
| 417 | + ], |
| 418 | + }, |
404 | 419 | },
|
405 |
| - }, |
406 |
| - versionedRouters: { |
407 |
| - testVersionedRouter1: { |
408 |
| - routes: [ |
409 |
| - { |
410 |
| - path: '/v1-1', |
411 |
| - options: { |
412 |
| - access: 'public', |
413 |
| - options: { availability: { stability: 'experimental' } }, |
414 |
| - security: { |
415 |
| - authz: { |
416 |
| - requiredPrivileges: ['foo'], |
| 420 | + versionedRouters: {}, |
| 421 | + } as CreateTestRouterArgs, |
| 422 | + expectedPath: '/test-path/{id}/{path}', |
| 423 | + expectedState: 'Beta', |
| 424 | + }, |
| 425 | + { |
| 426 | + name: 'router with stable stability', |
| 427 | + routerConfig: { |
| 428 | + routers: { |
| 429 | + testRouter: { |
| 430 | + routes: [ |
| 431 | + { |
| 432 | + path: '/test-path/{id}/{path*}', |
| 433 | + options: { availability: { stability: 'stable' }, access: 'public' }, |
| 434 | + }, |
| 435 | + ], |
| 436 | + }, |
| 437 | + }, |
| 438 | + versionedRouters: {}, |
| 439 | + } as CreateTestRouterArgs, |
| 440 | + expectedPath: '/test-path/{id}/{path}', |
| 441 | + expectedState: 'Generally available', |
| 442 | + }, |
| 443 | + { |
| 444 | + name: 'router without availability', |
| 445 | + routerConfig: { |
| 446 | + routers: { |
| 447 | + testRouter: { |
| 448 | + routes: [{ path: '/test-path/{id}/{path*}' }], |
| 449 | + }, |
| 450 | + }, |
| 451 | + versionedRouters: {}, |
| 452 | + } as CreateTestRouterArgs, |
| 453 | + expectedPath: '/test-path/{id}/{path}', |
| 454 | + expectedState: null, // No x-state expected |
| 455 | + }, |
| 456 | + { |
| 457 | + name: 'versioned router with experimental stability', |
| 458 | + routerConfig: { |
| 459 | + routers: {}, |
| 460 | + versionedRouters: { |
| 461 | + testVersionedRouter: { |
| 462 | + routes: [ |
| 463 | + { |
| 464 | + path: '/test-path', |
| 465 | + options: { |
| 466 | + access: 'public', |
| 467 | + options: { availability: { stability: 'experimental' } }, |
| 468 | + security: { |
| 469 | + authz: { |
| 470 | + requiredPrivileges: ['foo'], |
| 471 | + }, |
417 | 472 | },
|
418 | 473 | },
|
419 | 474 | },
|
420 |
| - }, |
421 |
| - { |
422 |
| - path: '/v1-2', |
423 |
| - options: { |
424 |
| - access: 'public', |
425 |
| - options: { availability: { stability: 'beta' } }, |
426 |
| - security: { |
427 |
| - authz: { |
428 |
| - requiredPrivileges: ['foo'], |
| 475 | + ], |
| 476 | + }, |
| 477 | + }, |
| 478 | + } as CreateTestRouterArgs, |
| 479 | + expectedPath: '/test-path', |
| 480 | + expectedState: 'Technical Preview', |
| 481 | + }, |
| 482 | + { |
| 483 | + name: 'versioned router with beta stability', |
| 484 | + routerConfig: { |
| 485 | + routers: {}, |
| 486 | + versionedRouters: { |
| 487 | + testVersionedRouter: { |
| 488 | + routes: [ |
| 489 | + { |
| 490 | + path: '/test-path', |
| 491 | + options: { |
| 492 | + access: 'public', |
| 493 | + options: { availability: { stability: 'beta' } }, |
| 494 | + security: { |
| 495 | + authz: { |
| 496 | + requiredPrivileges: ['foo'], |
| 497 | + }, |
429 | 498 | },
|
430 | 499 | },
|
431 | 500 | },
|
432 |
| - }, |
433 |
| - { |
434 |
| - path: '/v1-3', |
435 |
| - options: { |
436 |
| - access: 'public', |
437 |
| - options: { availability: { stability: 'stable' } }, |
438 |
| - security: { |
439 |
| - authz: { |
440 |
| - requiredPrivileges: ['foo'], |
| 501 | + ], |
| 502 | + }, |
| 503 | + }, |
| 504 | + } as CreateTestRouterArgs, |
| 505 | + expectedPath: '/test-path', |
| 506 | + expectedState: 'Beta', |
| 507 | + }, |
| 508 | + { |
| 509 | + name: 'versioned router with stable stability', |
| 510 | + routerConfig: { |
| 511 | + routers: {}, |
| 512 | + versionedRouters: { |
| 513 | + testVersionedRouter: { |
| 514 | + routes: [ |
| 515 | + { |
| 516 | + path: '/test-path', |
| 517 | + options: { |
| 518 | + access: 'public', |
| 519 | + options: { availability: { stability: 'stable' } }, |
| 520 | + security: { |
| 521 | + authz: { |
| 522 | + requiredPrivileges: ['foo'], |
| 523 | + }, |
441 | 524 | },
|
442 | 525 | },
|
443 | 526 | },
|
444 |
| - }, |
445 |
| - ], |
| 527 | + ], |
| 528 | + }, |
446 | 529 | },
|
447 |
| - testVersionedRouter2: { |
448 |
| - routes: [ |
449 |
| - { |
450 |
| - path: '/v2-1', |
451 |
| - options: { |
452 |
| - access: 'public', |
453 |
| - security: { |
454 |
| - authz: { |
455 |
| - requiredPrivileges: ['foo'], |
| 530 | + } as CreateTestRouterArgs, |
| 531 | + expectedPath: '/test-path', |
| 532 | + expectedState: 'Generally available', |
| 533 | + }, |
| 534 | + { |
| 535 | + name: 'versioned router without availability', |
| 536 | + routerConfig: { |
| 537 | + routers: {}, |
| 538 | + versionedRouters: { |
| 539 | + testVersionedRouter: { |
| 540 | + routes: [ |
| 541 | + { |
| 542 | + path: '/test-path', |
| 543 | + options: { |
| 544 | + access: 'public', |
| 545 | + security: { |
| 546 | + authz: { |
| 547 | + requiredPrivileges: ['foo'], |
| 548 | + }, |
456 | 549 | },
|
457 | 550 | },
|
458 | 551 | },
|
459 |
| - }, |
460 |
| - ], |
| 552 | + ], |
| 553 | + }, |
461 | 554 | },
|
462 |
| - }, |
463 |
| - }); |
464 |
| - const result = await generateOpenApiDocument( |
465 |
| - { |
466 |
| - routers, |
467 |
| - versionedRouters, |
468 |
| - }, |
469 |
| - { |
470 |
| - title: 'test', |
471 |
| - baseUrl: 'https://test.oas', |
472 |
| - version: '99.99.99', |
473 |
| - } |
474 |
| - ); |
475 |
| - |
476 |
| - // router paths |
477 |
| - expect(result.paths['/1-1/{id}/{path}']!.get).toMatchObject({ |
478 |
| - 'x-state': 'Technical Preview', |
479 |
| - }); |
480 |
| - expect(result.paths['/1-2/{id}/{path}']!.get).toMatchObject({ |
481 |
| - 'x-state': 'Beta', |
482 |
| - }); |
483 |
| - |
484 |
| - expect(result.paths['/1-3/{id}/{path}']!.get).not.toMatchObject({ |
485 |
| - 'x-state': expect.any(String), |
486 |
| - }); |
487 |
| - expect(result.paths['/2-1/{id}/{path}']!.get).not.toMatchObject({ |
488 |
| - 'x-state': expect.any(String), |
489 |
| - }); |
| 555 | + } as CreateTestRouterArgs, |
| 556 | + expectedPath: '/test-path', |
| 557 | + expectedState: null, // No x-state expected |
| 558 | + }, |
| 559 | + ]; |
490 | 560 |
|
491 |
| - // versioned router paths |
492 |
| - expect(result.paths['/v1-1']!.get).toMatchObject({ |
493 |
| - 'x-state': 'Technical Preview', |
494 |
| - }); |
495 |
| - expect(result.paths['/v1-2']!.get).toMatchObject({ |
496 |
| - 'x-state': 'Beta', |
497 |
| - }); |
| 561 | + it.each(testCases)( |
| 562 | + '$name: $expectedState', |
| 563 | + async ({ routerConfig, expectedPath, expectedState }) => { |
| 564 | + const [routers, versionedRouters] = createTestRouters(routerConfig); |
| 565 | + const result = await generateOpenApiDocument( |
| 566 | + { |
| 567 | + routers, |
| 568 | + versionedRouters, |
| 569 | + }, |
| 570 | + { |
| 571 | + title: 'test', |
| 572 | + baseUrl: 'https://test.oas', |
| 573 | + version: '99.99.99', |
| 574 | + } |
| 575 | + ); |
498 | 576 |
|
499 |
| - expect(result.paths['/v1-3']!.get).not.toMatchObject({ |
500 |
| - 'x-state': expect.any(String), |
501 |
| - }); |
502 |
| - expect(result.paths['/v2-1']!.get).not.toMatchObject({ |
503 |
| - 'x-state': expect.any(String), |
504 |
| - }); |
505 |
| - }); |
| 577 | + if (expectedState) { |
| 578 | + expect(result.paths[expectedPath]!.get).toMatchObject({ |
| 579 | + 'x-state': expectedState, |
| 580 | + }); |
| 581 | + } else { |
| 582 | + expect(result.paths[expectedPath]!.get).not.toMatchObject({ |
| 583 | + 'x-state': expect.any(String), |
| 584 | + }); |
| 585 | + } |
| 586 | + } |
| 587 | + ); |
506 | 588 | });
|
507 | 589 |
|
508 | 590 | it('merges operation objects', async () => {
|
|
0 commit comments