Skip to content

Commit 6b2e58a

Browse files
committed
refactor ai code
1 parent 6fe1f97 commit 6b2e58a

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ describe('setXState', () => {
387387
availability: undefined,
388388
expected: undefined,
389389
},
390+
{
391+
name: 'only since',
392+
availability: { since: '8.0.0' },
393+
expected: 'Added in 8.0.0',
394+
},
390395
])('$name', ({ availability, expected }) => {
391396
// Create a minimal valid CustomOperationObject with required responses property
392397
const operation: CustomOperationObject = {

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,26 +186,18 @@ export const setXState = (
186186
operation: CustomOperationObject
187187
): void => {
188188
if (availability) {
189+
let state = '';
189190
if (availability.stability === 'stable') {
190-
if (availability.since) {
191-
operation['x-state'] = `Generally available; added in ${availability.since}`;
192-
} else {
193-
// since is mandatory for stable, but handle the case if it's missing
194-
operation['x-state'] = 'Generally available';
195-
}
191+
state = 'Generally available';
196192
} else if (availability.stability === 'experimental') {
197-
if (availability.since) {
198-
operation['x-state'] = `Technical Preview; added in ${availability.since}`;
199-
} else {
200-
operation['x-state'] = 'Technical Preview';
201-
}
193+
state = 'Technical Preview';
202194
} else if (availability.stability === 'beta') {
203-
if (availability.since) {
204-
operation['x-state'] = `Beta; added in ${availability.since}`;
205-
} else {
206-
operation['x-state'] = 'Beta';
207-
}
195+
state = 'Beta';
196+
}
197+
if (availability.since) {
198+
state = state ? `${state}; added in ${availability.since}` : `Added in ${availability.since}`;
208199
}
200+
operation['x-state'] = state;
209201
}
210202
};
211203

0 commit comments

Comments
 (0)