Skip to content

Commit

Permalink
[OAS] Support tags (elastic#184320)
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens authored Jun 4, 2024
1 parent c89ee65 commit 5fd4795
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 65 deletions.
6 changes: 4 additions & 2 deletions oas_docs/bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@
"description": "Get Kibana's current status."
}
},
"summary": "Get Kibana's current status."
"summary": "Get Kibana's current status.",
"tags": []
}
}
},
Expand All @@ -534,5 +535,6 @@
{
"url": "http://localhost:5622"
}
]
],
"tags": []
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 58 additions & 1 deletion packages/kbn-router-to-openapispec/src/generate_oas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ interface RecursiveType {
describe('generateOpenApiDocument', () => {
describe('@kbn/config-schema', () => {
it('generates the expected OpenAPI document', () => {
const [routers, versionedRouters] = createTestRouters();
const [routers, versionedRouters] = createTestRouters({
routers: { testRouter: { routes: [{ method: 'get' }, { method: 'post' }] } },
versionedRouters: { testVersionedRouter: { routes: [{}] } },
});
expect(
generateOpenApiDocument(
{
Expand Down Expand Up @@ -185,4 +188,58 @@ describe('generateOpenApiDocument', () => {
).toMatchSnapshot();
});
});

describe('tags', () => {
it('handles tags as expected', () => {
const [routers, versionedRouters] = createTestRouters({
routers: {
testRouter1: {
routes: [
{ path: '/1-1/{id}/{path*}', options: { tags: ['oas-tag:1', 'oas-tag:2', 'foo'] } },
{ path: '/1-2/{id}/{path*}', options: { tags: ['oas-tag:1', 'foo'] } },
],
},
testRouter2: { routes: [{ path: '/2-1/{id}/{path*}', options: { tags: undefined } }] },
},
versionedRouters: {
testVersionedRouter1: {
routes: [
{ path: '/v1-1', options: { access: 'public', options: { tags: ['oas-tag:v1'] } } },
{
path: '/v1-2',
options: {
access: 'public',
options: { tags: ['foo', 'bar', 'oas-tag:v2', 'oas-tag:v3'] },
},
},
],
},
testVersionedRouter2: {
routes: [
{ path: '/v2-1', options: { access: 'public', options: { tags: undefined } } },
],
},
},
});
const result = generateOpenApiDocument(
{
routers,
versionedRouters,
},
{
title: 'test',
baseUrl: 'https://test.oas',
version: '99.99.99',
}
);
// router paths
expect(result.paths['/1-1/{id}/{path*}']!.get!.tags).toEqual(['1', '2']);
expect(result.paths['/1-2/{id}/{path*}']!.get!.tags).toEqual(['1']);
expect(result.paths['/2-1/{id}/{path*}']!.get!.tags).toEqual([]);
// versioned router paths
expect(result.paths['/v1-1']!.get!.tags).toEqual(['v1']);
expect(result.paths['/v1-2']!.get!.tags).toEqual(['v2', 'v3']);
expect(result.paths['/v2-1']!.get!.tags).toEqual([]);
});
});
});
Loading

0 comments on commit 5fd4795

Please sign in to comment.