Skip to content

Commit 4364707

Browse files
committed
fix: collect openapi version changes for operations
1 parent 21196bb commit 4364707

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/apitypes/rest/rest.changes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import { calculateObjectHash } from '../../utils/hashes'
5959
import { REST_API_TYPE } from './rest.consts'
6060
import { OpenAPIV3 } from 'openapi-types'
6161
import {
62+
extractOpenapiVersionDiff,
6263
extractPathParamRenameDiff,
6364
extractRootSecurityDiffs,
6465
extractRootServersDiffs,
@@ -167,7 +168,8 @@ export const compareDocuments = async (
167168
let operationDiffs: Diff[] = []
168169
if (operationPotentiallyChanged) {
169170
operationDiffs = [
170-
...(methodData as WithAggregatedDiffs<OpenAPIV3.OperationObject>)[DIFFS_AGGREGATED_META_KEY]??[],
171+
...(methodData as WithAggregatedDiffs<OpenAPIV3.OperationObject>)[DIFFS_AGGREGATED_META_KEY] ?? [],
172+
...extractOpenapiVersionDiff(merged),
171173
...extractRootServersDiffs(merged),
172174
...extractRootSecurityDiffs(merged),
173175
...extractPathParamRenameDiff(merged, path),

src/apitypes/rest/rest.utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export const dump = (value: unknown, format: typeof FILE_FORMAT_YAML | typeof FI
7070
throw new Error(`Unsupported format: ${format}`)
7171
}
7272

73+
export const extractOpenapiVersionDiff = (doc: OpenAPIV3.Document): Diff[] => {
74+
const diff = (doc as WithDiffMetaRecord<OpenAPIV3.Document>)[DIFF_META_KEY]?.openapi
75+
return diff ? [diff] : []
76+
}
77+
7378
export const extractPathParamRenameDiff = (doc: OpenAPIV3.Document, path: string): Diff[] => {
7479
const diff = (doc.paths as WithDiffMetaRecord<OpenAPIV3.PathsObject>)[DIFF_META_KEY]?.[path]
7580
return diff && isPathParamRenameDiff(diff) ? [diff] : []

test/changes.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ describe('Changelog build type', () => {
244244
[UNCLASSIFIED_CHANGE_TYPE]: 1,
245245
}))
246246
})
247+
248+
test('Change openapi version', async () => {
249+
const result = await buildChangelogPackage('changelog/change-openapi-version')
250+
251+
expect(result).toEqual(changesSummaryMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
252+
expect(result).toEqual(numberOfImpactedOperationsMatcher({ [ANNOTATION_CHANGE_TYPE]: 1 }))
253+
})
247254
})
248255

249256
test('Operation changes fields are correct', async () => {

0 commit comments

Comments
 (0)