Skip to content

Commit 67a7f25

Browse files
committed
fix: servers and security diffs collecting
1 parent fad1ef1 commit 67a7f25

File tree

15 files changed

+193
-13
lines changed

15 files changed

+193
-13
lines changed

src/apitypes/rest/rest.operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
removeFirstSlash,
2626
slugify,
2727
} from '../../utils'
28-
import { getOperationBasePath } from './rest.utils'
28+
import { extractOperationBasePath } from './rest.utils'
2929
import type * as TYPE from './rest.types'
3030
import { HASH_FLAG, INLINE_REFS_FLAG, MESSAGE_SEVERITY, NORMALIZE_OPTIONS, ORIGINS_SYMBOL } from '../../consts'
3131
import { asyncFunction } from '../../utils/async'

src/apitypes/rest/rest.utils.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,21 @@ export const extractPathParamRenameDiff = (doc: OpenAPIV3.Document, path: string
9494
}
9595

9696
export const extractRootServersDiffs = (doc: OpenAPIV3.Document): Diff[] => {
97-
const addedServersDiff = (doc as WithDiffMetaRecord<OpenAPIV3.Document>)[DIFF_META_KEY]?.servers
98-
const serverDiffs = doc.servers?.flatMap(server => {
99-
return Object.values((server as WithDiffMetaRecord<OpenAPIV3.ServerObject>)[DIFF_META_KEY] ?? {})
100-
}) ?? []
97+
const addOrRemoveServersDiff = (doc as WithDiffMetaRecord<OpenAPIV3.Document>)[DIFF_META_KEY]?.servers
98+
const serversInternalDiffs = (doc.servers as WithAggregatedDiffs<OpenAPIV3.ServerObject[]> | undefined)?.[DIFFS_AGGREGATED_META_KEY] ?? []
10199
return [
102-
...(addedServersDiff ? [addedServersDiff] : []),
103-
...serverDiffs,
100+
...(addOrRemoveServersDiff ? [addOrRemoveServersDiff] : []),
101+
...serversInternalDiffs,
104102
]
105103
}
106104

107105
export const extractRootSecurityDiffs = (doc: OpenAPIV3.Document): Diff[] => {
108-
const addedSecurityDiff = (doc as WithDiffMetaRecord<OpenAPIV3.Document>)[DIFF_META_KEY]?.security
109-
const securityDiffs = Object.values((doc.security as WithDiffMetaRecord<OpenAPIV3.SecurityRequirementObject[]>)?.[DIFF_META_KEY] ?? {})
110-
const componentsSecuritySchemesDiffs = (doc.components?.securitySchemes as WithAggregatedDiffs<Record<string, OpenAPIV3.SecuritySchemeObject>>)[DIFFS_AGGREGATED_META_KEY]
106+
const addOrRemoveSecurityDiff = (doc as WithDiffMetaRecord<OpenAPIV3.Document>)[DIFF_META_KEY]?.security
107+
const securityInternalDiffs = (doc.security as WithAggregatedDiffs<OpenAPIV3.SecurityRequirementObject[]> | undefined)?.[DIFFS_AGGREGATED_META_KEY] ?? []
108+
const componentsSecuritySchemesDiffs = (doc.components?.securitySchemes as WithAggregatedDiffs<Record<string, OpenAPIV3.SecuritySchemeObject>>)[DIFFS_AGGREGATED_META_KEY] ?? []
111109
return [
112-
...(addedSecurityDiff ? [addedSecurityDiff] : []),
113-
...securityDiffs,
110+
...(addOrRemoveSecurityDiff ? [addOrRemoveSecurityDiff] : []),
111+
...securityInternalDiffs,
114112
...componentsSecuritySchemesDiffs,
115113
]
116114
}

test/changes.test.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('Changes test', () => {
8585
})
8686

8787
test('Change method content', async () => {
88-
const result = await buildChangelogPackage('changelog/change-method')
88+
const result = await buildChangelogPackage('changelog/change-inside-method')
8989

9090
expect(result).toEqual(changesSummaryMatcher({
9191
[BREAKING_CHANGE_TYPE]: 1,
@@ -113,6 +113,19 @@ describe('Changes test', () => {
113113
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
114114
})
115115

116+
test('Add prefix to server', async () => {
117+
const result = await buildChangelogPackage('changelog/add-prefix-to-server')
118+
119+
expect(result).toEqual(changesSummaryMatcher({
120+
[BREAKING_CHANGE_TYPE]: 1,
121+
[NON_BREAKING_CHANGE_TYPE]: 1,
122+
}))
123+
expect(result).toEqual(numberOfImpactedOperationsMatcher({
124+
[BREAKING_CHANGE_TYPE]: 1,
125+
[NON_BREAKING_CHANGE_TYPE]: 1,
126+
}))
127+
})
128+
116129
test('Remove prefix from server', async () => {
117130
const result = await buildChangelogPackage('changelog/remove-prefix-from-server')
118131

@@ -125,6 +138,13 @@ describe('Changes test', () => {
125138
[NON_BREAKING_CHANGE_TYPE]: 1,
126139
}))
127140
})
141+
142+
test('move-prefix-from-server-to-path', async () => {
143+
const result = await buildChangelogPackage('changelog/move-prefix-from-server-to-path')
144+
145+
expect(result).toEqual(changesSummaryMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
146+
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
147+
})
128148
})
129149

130150
describe('Diffs collecting in the root-level properties', () => {
@@ -135,6 +155,20 @@ describe('Changes test', () => {
135155
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
136156
})
137157

158+
test('Remove root servers', async () => {
159+
const result = await buildChangelogPackage('changelog/remove-root-servers')
160+
161+
expect(result).toEqual(changesSummaryMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
162+
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
163+
})
164+
165+
test('Remove server', async () => {
166+
const result = await buildChangelogPackage('changelog/remove-server')
167+
168+
expect(result).toEqual(changesSummaryMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
169+
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
170+
})
171+
138172
test('Change root servers', async () => {
139173
const result = await buildChangelogPackage('changelog/change-root-servers')
140174

@@ -149,6 +183,13 @@ describe('Changes test', () => {
149183
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [BREAKING_CHANGE_TYPE]: 1 }))
150184
})
151185

186+
test('Remove security', async () => {
187+
const result = await buildChangelogPackage('changelog/remove-security')
188+
189+
expect(result).toEqual(changesSummaryMatcher({ [NON_BREAKING_CHANGE_TYPE]: 2 }))
190+
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [NON_BREAKING_CHANGE_TYPE]: 1 }))
191+
})
192+
152193
test('Add securityScheme', async () => {
153194
const result = await buildChangelogPackage('changelog/add-securityScheme')
154195

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
servers:
6+
- url: https://example2.com
7+
description: It is a description of server
8+
paths:
9+
/path1:
10+
get:
11+
responses:
12+
'200':
13+
description: OK
14+
content: { }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
servers:
6+
- url: https://example1.com/api/v2
7+
description: It is a description of server
8+
paths:
9+
/path1:
10+
get:
11+
responses:
12+
'200':
13+
description: OK
14+
content: { }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
servers:
6+
- url: https://example2.com
7+
description: It is a description of server
8+
paths:
9+
/api/v2/path1:
10+
get:
11+
responses:
12+
'200':
13+
description: OK
14+
content: { }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
servers:
6+
- url: https://example1.com/api/v2
7+
description: It is a description of server
8+
paths:
9+
/path1:
10+
get:
11+
responses:
12+
'200':
13+
description: OK
14+
content: { }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
servers:
6+
- url: https://example2.com
7+
description: It is a description of server
8+
paths:
9+
/path1:
10+
get:
11+
responses:
12+
'200':
13+
description: OK
14+
content: { }

0 commit comments

Comments
 (0)