Skip to content

Commit feb0e96

Browse files
[OAS] Update x-state behaviour to include availability.since (#221137)
## Summary Updated the behaviour of `setXState` per #221056. Partially addresses that issue. In future we need to migrate existing routes to add that information, this covers the Core provided capability. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <[email protected]>
1 parent 85efa38 commit feb0e96

File tree

9 files changed

+271
-117
lines changed

9 files changed

+271
-117
lines changed

oas_docs/bundle.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5430,7 +5430,8 @@
54305430
"summary": "Schedule a snooze for the rule",
54315431
"tags": [
54325432
"alerting"
5433-
]
5433+
],
5434+
"x-state": "Generally available; added in 8.19.0"
54345435
}
54355436
},
54365437
"/api/alerting/rule/{ruleId}/snooze_schedule/{scheduleId}": {
@@ -5483,7 +5484,8 @@
54835484
"summary": "Delete a snooze schedule for a rule",
54845485
"tags": [
54855486
"alerting"
5486-
]
5487+
],
5488+
"x-state": "Generally available; added in 8.19.0"
54875489
}
54885490
},
54895491
"/api/alerting/rule/{rule_id}/alert/{alert_id}/_mute": {

oas_docs/bundle.serverless.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5430,7 +5430,8 @@
54305430
"summary": "Schedule a snooze for the rule",
54315431
"tags": [
54325432
"alerting"
5433-
]
5433+
],
5434+
"x-state": "Generally available; added in 8.19.0"
54345435
}
54355436
},
54365437
"/api/alerting/rule/{ruleId}/snooze_schedule/{scheduleId}": {
@@ -5483,7 +5484,8 @@
54835484
"summary": "Delete a snooze schedule for a rule",
54845485
"tags": [
54855486
"alerting"
5486-
]
5487+
],
5488+
"x-state": "Generally available; added in 8.19.0"
54875489
}
54885490
},
54895491
"/api/alerting/rule/{rule_id}/alert/{alert_id}/_mute": {

oas_docs/output/kibana.serverless.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4219,6 +4219,7 @@ paths:
42194219
summary: Schedule a snooze for the rule
42204220
tags:
42214221
- alerting
4222+
x-state: Generally available; added in 8.19.0
42224223
/api/alerting/rule/{rule_id}/alert/{alert_id}/_mute:
42234224
post:
42244225
operationId: post-alerting-rule-rule-id-alert-alert-id-mute
@@ -4324,6 +4325,7 @@ paths:
43244325
summary: Delete a snooze schedule for a rule
43254326
tags:
43264327
- alerting
4328+
x-state: Generally available; added in 8.19.0
43274329
/api/alerting/rules/_find:
43284330
get:
43294331
operationId: get-alerting-rules-find

oas_docs/output/kibana.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4613,6 +4613,7 @@ paths:
46134613
summary: Schedule a snooze for the rule
46144614
tags:
46154615
- alerting
4616+
x-state: Generally available; added in 8.19.0
46164617
/api/alerting/rule/{rule_id}/alert/{alert_id}/_mute:
46174618
post:
46184619
operationId: post-alerting-rule-rule-id-alert-alert-id-mute
@@ -4718,6 +4719,7 @@ paths:
47184719
summary: Delete a snooze schedule for a rule
47194720
tags:
47204721
- alerting
4722+
x-state: Generally available; added in 8.19.0
47214723
/api/alerting/rules/_find:
47224724
get:
47234725
operationId: get-alerting-rules-find

src/platform/packages/shared/kbn-router-to-openapispec/src/generate_oas.test.ts

Lines changed: 188 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
import { schema, Type } from '@kbn/config-schema';
1111
import { get } from 'lodash';
1212
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';
1419
import {
1520
sharedOas,
1621
createSharedZodSchema,
@@ -380,129 +385,206 @@ describe('generateOpenApiDocument', () => {
380385
});
381386

382387
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+
},
401401
},
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+
},
404419
},
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+
},
417472
},
418473
},
419474
},
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+
},
429498
},
430499
},
431500
},
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+
},
441524
},
442525
},
443526
},
444-
},
445-
],
527+
],
528+
},
446529
},
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+
},
456549
},
457550
},
458551
},
459-
},
460-
],
552+
],
553+
},
461554
},
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+
];
490560

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+
);
498576

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+
);
506588
});
507589

508590
it('merges operation objects', async () => {

0 commit comments

Comments
 (0)