Skip to content

Commit fad1ef1

Browse files
committed
feat: collect all deep changes in components.securitySchemes
1 parent 7817a91 commit fad1ef1

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

src/apitypes/rest/rest.utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import {
2121
API_AUDIENCE_INTERNAL,
2222
API_AUDIENCE_UNKNOWN,
2323
ApiAudience,
24+
WithAggregatedDiffs,
2425
WithDiffMetaRecord,
2526
} from '../../types'
2627
import { isObject } from '@netcracker/qubership-apihub-json-crawl'
2728
import { CUSTOM_PARAMETER_API_AUDIENCE, FILE_FORMAT_JSON, FILE_FORMAT_YAML } from '../../consts'
2829
import YAML from 'js-yaml'
29-
import { Diff, DIFF_META_KEY } from '@netcracker/qubership-apihub-api-diff'
30+
import { Diff, DIFF_META_KEY, DIFFS_AGGREGATED_META_KEY } from '@netcracker/qubership-apihub-api-diff'
3031
import { isPathParamRenameDiff } from '../../utils'
3132

3233
export const extractOperationBasePath = (servers?: OpenAPIV3.ServerObject[]): string => {
@@ -106,7 +107,7 @@ export const extractRootServersDiffs = (doc: OpenAPIV3.Document): Diff[] => {
106107
export const extractRootSecurityDiffs = (doc: OpenAPIV3.Document): Diff[] => {
107108
const addedSecurityDiff = (doc as WithDiffMetaRecord<OpenAPIV3.Document>)[DIFF_META_KEY]?.security
108109
const securityDiffs = Object.values((doc.security as WithDiffMetaRecord<OpenAPIV3.SecurityRequirementObject[]>)?.[DIFF_META_KEY] ?? {})
109-
const componentsSecuritySchemesDiffs = Object.values((doc.components?.securitySchemes as WithDiffMetaRecord<Record<string, OpenAPIV3.SecuritySchemeObject>>)[DIFF_META_KEY] ?? {})
110+
const componentsSecuritySchemesDiffs = (doc.components?.securitySchemes as WithAggregatedDiffs<Record<string, OpenAPIV3.SecuritySchemeObject>>)[DIFFS_AGGREGATED_META_KEY]
110111
return [
111112
...(addedSecurityDiff ? [addedSecurityDiff] : []),
112113
...securityDiffs,

test/changes.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ import {
2222
numberOfImpactedOperationsMatcher,
2323
operationChangesMatcher,
2424
} from './helpers'
25-
import { ANNOTATION_CHANGE_TYPE, BREAKING_CHANGE_TYPE, BUILD_TYPE, NON_BREAKING_CHANGE_TYPE } from '../src'
25+
import {
26+
ANNOTATION_CHANGE_TYPE,
27+
BREAKING_CHANGE_TYPE,
28+
BUILD_TYPE,
29+
NON_BREAKING_CHANGE_TYPE,
30+
UNCLASSIFIED_CHANGE_TYPE,
31+
} from '../src'
2632

2733
let beforePackage: LocalRegistry
2834
let afterPackage: LocalRegistry
@@ -155,6 +161,17 @@ describe('Changes test', () => {
155161
[NON_BREAKING_CHANGE_TYPE]: 1,
156162
}))
157163
})
164+
165+
test('Change securityScheme content', async () => {
166+
const result = await buildChangelogPackage('changelog/change-inside-securityScheme')
167+
168+
expect(result).toEqual(changesSummaryMatcher({
169+
[UNCLASSIFIED_CHANGE_TYPE]: 1,
170+
}))
171+
expect(result).toEqual(numberOfImpactedOperationsMatcher({
172+
[UNCLASSIFIED_CHANGE_TYPE]: 1,
173+
}))
174+
})
158175
})
159176

160177
test('Operation changes fields are correct (REST)', async () => {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
security:
6+
- ApiKeyAuth1: [ ]
7+
paths:
8+
/path1:
9+
post:
10+
responses:
11+
'200':
12+
description: OK
13+
content: { }
14+
security:
15+
- Oauth2:
16+
- https://www.googleapis.com/auth/bigquery
17+
components:
18+
securitySchemes:
19+
Oauth2:
20+
description: Oauth 2.0 authentication
21+
type: oauth2
22+
flows:
23+
implicit:
24+
authorizationUrl: https://accounts.google.com/o/oauth2/auth
25+
scopes:
26+
https://www.googleapis.com/auth/bigquery: View and manage your data in Google BigQuery
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
security:
6+
- ApiKeyAuth1: [ ]
7+
paths:
8+
/path1:
9+
post:
10+
responses:
11+
'200':
12+
description: OK
13+
content: { }
14+
security:
15+
- Oauth2:
16+
- https://www.googleapis.com/auth/bigquery
17+
components:
18+
securitySchemes:
19+
Oauth2:
20+
description: Oauth 2.0 authentication
21+
type: oauth2
22+
flows:
23+
implicit:
24+
authorizationUrl: https://accounts.google.com/o/oauth2/auth
25+
scopes:
26+
https://www.googleapis.com/auth/bigquery: BigQuery

0 commit comments

Comments
 (0)