Skip to content

Commit e53d68c

Browse files
authored
[OAS] Beautify generated operation ids (#198132)
1 parent 5004763 commit e53d68c

15 files changed

+739
-680
lines changed

oas_docs/bundle.json

Lines changed: 148 additions & 148 deletions
Large diffs are not rendered by default.

oas_docs/bundle.serverless.json

Lines changed: 143 additions & 143 deletions
Large diffs are not rendered by default.

oas_docs/output/kibana.serverless.yaml

Lines changed: 143 additions & 148 deletions
Large diffs are not rendered by default.

oas_docs/output/kibana.yaml

Lines changed: 148 additions & 153 deletions
Large diffs are not rendered by default.

packages/kbn-router-to-openapispec/src/__snapshots__/generate_oas.test.ts.snap

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const sharedOas = {
3535
get: {
3636
deprecated: true,
3737
'x-discontinued': 'route discontinued version or date',
38-
operationId: '%2Fbar#0',
38+
operationId: 'get-bar',
3939
parameters: [
4040
{
4141
description: 'The version of the API to use',
@@ -154,7 +154,7 @@ export const sharedOas = {
154154
'/foo/{id}/{path*}': {
155155
get: {
156156
description: 'route description',
157-
operationId: '%2Ffoo%2F%7Bid%7D%2F%7Bpath*%7D#0',
157+
operationId: 'get-foo-id-path',
158158
parameters: [
159159
{
160160
description: 'The version of the API to use',
@@ -278,7 +278,7 @@ export const sharedOas = {
278278
},
279279
post: {
280280
description: 'route description',
281-
operationId: '%2Ffoo%2F%7Bid%7D%2F%7Bpath*%7D#1',
281+
operationId: 'post-foo-id-path',
282282
parameters: [
283283
{
284284
description: 'The version of the API to use',

packages/kbn-router-to-openapispec/src/generate_oas.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
import type { CoreVersionedRouter, Router } from '@kbn/core-http-router-server-internal';
1111
import type { OpenAPIV3 } from 'openapi-types';
1212
import { OasConverter } from './oas_converter';
13-
import { createOperationIdCounter } from './operation_id_counter';
1413
import { processRouter } from './process_router';
1514
import { processVersionedRouter } from './process_versioned_router';
16-
import { buildGlobalTags } from './util';
15+
import { buildGlobalTags, createOpIdGenerator } from './util';
1716

1817
export const openApiVersion = '3.0.0';
1918

@@ -40,8 +39,8 @@ export const generateOpenApiDocument = (
4039
): OpenAPIV3.Document => {
4140
const { filters } = opts;
4241
const converter = new OasConverter();
43-
const getOpId = createOperationIdCounter();
4442
const paths: OpenAPIV3.PathsObject = {};
43+
const getOpId = createOpIdGenerator();
4544
for (const router of appRouters.routers) {
4645
const result = processRouter(router, converter, getOpId, filters);
4746
Object.assign(paths, result.paths);

packages/kbn-router-to-openapispec/src/operation_id_counter.test.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/kbn-router-to-openapispec/src/operation_id_counter.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

packages/kbn-router-to-openapispec/src/process_router.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import { schema } from '@kbn/config-schema';
1111
import { Router } from '@kbn/core-http-router-server-internal';
1212
import { OasConverter } from './oas_converter';
13-
import { createOperationIdCounter } from './operation_id_counter';
1413
import { extractResponses, processRouter } from './process_router';
1514
import { type InternalRouterRoute } from './type';
15+
import { createOpIdGenerator } from './util';
1616

1717
describe('extractResponses', () => {
1818
let oasConverter: OasConverter;
@@ -86,18 +86,21 @@ describe('processRouter', () => {
8686
const testRouter = {
8787
getRoutes: () => [
8888
{
89+
method: 'get',
8990
path: '/foo',
9091
options: { access: 'internal', deprecated: true, discontinued: 'discontinued router' },
9192
handler: jest.fn(),
9293
validationSchemas: { request: { body: schema.object({}) } },
9394
},
9495
{
96+
method: 'get',
9597
path: '/bar',
9698
options: {},
9799
handler: jest.fn(),
98100
validationSchemas: { request: { body: schema.object({}) } },
99101
},
100102
{
103+
method: 'get',
101104
path: '/baz',
102105
options: {},
103106
handler: jest.fn(),
@@ -125,20 +128,20 @@ describe('processRouter', () => {
125128
} as unknown as Router;
126129

127130
it('only provides routes for version 2023-10-31', () => {
128-
const result1 = processRouter(testRouter, new OasConverter(), createOperationIdCounter(), {
131+
const result1 = processRouter(testRouter, new OasConverter(), createOpIdGenerator(), {
129132
version: '2023-10-31',
130133
});
131134

132135
expect(Object.keys(result1.paths!)).toHaveLength(4);
133136

134-
const result2 = processRouter(testRouter, new OasConverter(), createOperationIdCounter(), {
137+
const result2 = processRouter(testRouter, new OasConverter(), createOpIdGenerator(), {
135138
version: '2024-10-31',
136139
});
137140
expect(Object.keys(result2.paths!)).toHaveLength(0);
138141
});
139142

140143
it('updates description with privileges required', () => {
141-
const result = processRouter(testRouter, new OasConverter(), createOperationIdCounter(), {
144+
const result = processRouter(testRouter, new OasConverter(), createOpIdGenerator(), {
142145
version: '2023-10-31',
143146
});
144147

0 commit comments

Comments
 (0)