forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Add tags by OpenAPI bundler (elastic#189621)
**Resolves:** elastic#183375 ## Summary This PR implements functionality assigning a provided tag to OpenAPI `Operation object`s in the result bundle. Specified tag is also added as the only root level OpenAPI tag. This approach allows to produce domain bundles having a single tag assigned. At the next step domain bundles are merged together into single Kibana bundle where tags will allow to properly display grouping at Bump.sh (API reference documentation platform). ## Details Bump.sh (our new API reference documentation platform) uses OpenAPI tags for grouping API endpoints. It supports only one tag per endpoint. This PR facilitates preparation of Kibana OpenAPI bundle to be uploaded to Bump.sh by implementing functionality assigning a provided tag to OpenAPI `Operation object`s in the result domain bundles. It's implemented by providing an optional configuration option `assignTag` whose format is OpenAPI Tag Object. When `assignTag` isn't specified the bundler merges existing tags. ## Example Consider the following bundling configuration ```js const { bundle } = require('@kbn/openapi-bundler'); bundle({ // ... options: { assignTag: { name: 'Some Domain API tag name', description: 'Some Domain API description', externalDocs: { url: 'https://some-external-documentation-url', description: 'External documentation description', } }, }); ``` and source OpenAPI specs **spec1.schema.yaml** ```yaml openapi: 3.0.3 info: title: Spec1 version: '2023-10-31' paths: /api/some_api: get: tags: ['Some local tag'] responses: 200: content: 'application/json': schema: type: string ``` **spec2.schema.yaml** ```yaml openapi: 3.0.3 info: title: Spec2 version: '2023-10-31' paths: /api/some_api: post: tags: ['Some global tag'] responses: 200: content: 'application/json': schema: type: string tags: - name: Some global tag ``` **spec2.schema.yaml** ```yaml openapi: 3.0.3 info: title: Spec3 version: '2023-10-31' paths: /api/another_api: get: responses: 200: content: 'application/json': schema: type: string ``` After bundling above OpenAPI specs with the provided bundling script we'll get the following **domain-bundle.schema.yaml** ```yaml openapi: 3.0.3 info: title: Bundled document version: '2023-10-31' paths: /api/some_api: get: tags: ['Some Domain API tag name'] responses: 200: content: 'application/json': schema: type: string post: tags: ['Some Domain API tag name'] responses: 200: content: 'application/json': schema: type: string /api/another_api: get: tags: ['Some Domain API tag name'] responses: 200: content: 'application/json': schema: type: string tags: - name: Some Domain API tag name description: Some Domain API description externalDocs: url: 'https://some-external-documentation-url' description: External documentation description ```
- Loading branch information
Showing
75 changed files
with
950 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
packages/kbn-openapi-bundler/tests/bundler/result_overrides/add_tags.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { createOASDocument } from '../../create_oas_document'; | ||
import { bundleSpecs } from '../bundle_specs'; | ||
|
||
describe('OpenAPI Bundler - assign a tag', () => { | ||
it('adds tags when nothing is set', async () => { | ||
const spec1 = createOASDocument({ | ||
paths: { | ||
'/api/some_api': { | ||
get: { | ||
responses: { | ||
'200': { | ||
description: 'Successful response', | ||
content: { | ||
'application/json': { | ||
schema: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
const spec2 = createOASDocument({ | ||
paths: { | ||
'/api/another_api': { | ||
get: { | ||
responses: { | ||
'200': { | ||
description: 'Successful response', | ||
content: { | ||
'application/json': { | ||
schema: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const [bundledSpec] = Object.values( | ||
await bundleSpecs( | ||
{ | ||
1: spec1, | ||
2: spec2, | ||
}, | ||
{ | ||
prototypeDocument: { | ||
tags: [ | ||
{ | ||
name: 'Some Tag', | ||
description: 'Some tag description', | ||
}, | ||
{ | ||
name: 'Another Tag', | ||
description: 'Another tag description', | ||
}, | ||
], | ||
}, | ||
} | ||
) | ||
); | ||
|
||
expect(bundledSpec.paths['/api/some_api']?.get?.tags).toEqual(['Some Tag', 'Another Tag']); | ||
expect(bundledSpec.paths['/api/another_api']?.get?.tags).toEqual(['Some Tag', 'Another Tag']); | ||
expect(bundledSpec.tags).toEqual([ | ||
{ | ||
name: 'Some Tag', | ||
description: 'Some tag description', | ||
}, | ||
{ | ||
name: 'Another Tag', | ||
description: 'Another tag description', | ||
}, | ||
]); | ||
}); | ||
|
||
it('adds tags to existing tags', async () => { | ||
const spec1 = createOASDocument({ | ||
paths: { | ||
'/api/some_api': { | ||
get: { | ||
tags: ['Local tag'], | ||
responses: { | ||
'200': { | ||
description: 'Successful response', | ||
content: { | ||
'application/json': { | ||
schema: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
const spec2 = createOASDocument({ | ||
paths: { | ||
'/api/another_api': { | ||
get: { | ||
tags: ['Global tag'], | ||
responses: { | ||
'200': { | ||
description: 'Successful response', | ||
content: { | ||
'application/json': { | ||
schema: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
tags: [{ name: 'Global tag', description: 'Global tag description' }], | ||
}); | ||
|
||
const [bundledSpec] = Object.values( | ||
await bundleSpecs( | ||
{ | ||
1: spec1, | ||
2: spec2, | ||
}, | ||
{ | ||
prototypeDocument: { | ||
tags: [ | ||
{ | ||
name: 'Some Tag', | ||
description: 'Some tag description', | ||
}, | ||
{ | ||
name: 'Another Tag', | ||
description: 'Another tag description', | ||
}, | ||
], | ||
}, | ||
} | ||
) | ||
); | ||
|
||
expect(bundledSpec.paths['/api/some_api']?.get?.tags).toEqual([ | ||
'Some Tag', | ||
'Another Tag', | ||
'Local tag', | ||
]); | ||
expect(bundledSpec.paths['/api/another_api']?.get?.tags).toEqual([ | ||
'Some Tag', | ||
'Another Tag', | ||
'Global tag', | ||
]); | ||
expect(bundledSpec.tags).toEqual([ | ||
{ | ||
name: 'Some Tag', | ||
description: 'Some tag description', | ||
}, | ||
{ | ||
name: 'Another Tag', | ||
description: 'Another tag description', | ||
}, | ||
{ name: 'Global tag', description: 'Global tag description' }, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.