1414 * limitations under the License.
1515 */
1616
17- import { RestOperationData , VersionRestOperation } from './rest.types'
17+ import { RestOperationData } from './rest.types'
1818import {
1919 areDeprecatedOriginsNotEmpty ,
2020 IGNORE_PATH_PARAM_UNIFIED_PLACEHOLDER ,
2121 isEmpty ,
2222 isOperationRemove ,
2323 isPathParamRenameDiff ,
2424 normalizePath ,
25- removeComponents ,
2625 removeFirstSlash ,
2726 slugify ,
2827} from '../../utils'
2928import {
3029 apiDiff ,
3130 breaking ,
32- COMPARE_MODE_OPERATION ,
3331 Diff ,
3432 DIFF_META_KEY ,
3533 DiffAction ,
@@ -79,12 +77,10 @@ export const compareDocuments = async (apiType: OperationsApiType, operationsMap
7977 const isChangedOperations = prevDoc && currDoc
8078
8179 if ( prevDocData && previousGroup ) {
82- // todo what's with components? why don't remove?
8380 prevDocData = createCopyWithCurrentGroupOperationsOnly ( prevDocData , previousGroup )
8481 }
8582
8683 if ( currDocData && currentGroup ) {
87- // todo what's with components? why don't remove?
8884 currDocData = createCopyWithCurrentGroupOperationsOnly ( currDocData , currentGroup )
8985 }
9086
@@ -158,21 +154,14 @@ export const compareDocuments = async (apiType: OperationsApiType, operationsMap
158154 // ignore removed and added operations, they'll be handled in a separate docs comparison
159155 continue
160156 }
161- // const deprecatedInVersionsCount = previousVersionDeprecations?.operations.find((operation) => operation.operationId === operationId)?.deprecatedInPreviousVersions?.length ?? 0
162- // if (isOperationRemove(operationDiff) && deprecatedInVersionsCount > 1) {
163- // operationDiff.type = risky
164- // }
165157 operationDiffs . push ( operationDiff )
166158 }
167159
168160 if ( isEmpty ( operationDiffs ) ) {
169161 continue
170162 }
171163
172- const onlyBreaking = operationDiffs . filter ( ( diff ) => diff . type === breaking )
173- if ( onlyBreaking . length > 0 && previous ?. operationId ) {
174- await reclassifyBreakingChanges ( previous . operationId , merged , onlyBreaking , ctx )
175- }
164+ await reclassifyBreakingChanges ( previous ?. operationId , merged , operationDiffs , ctx )
176165
177166 changedOperations . push ( createOperationChange ( apiType , operationDiffs , previous , current , currGroupSlug , prevGroupSlug , currentGroup , previousGroup ) )
178167 getOperationTags ( current ?? previous ) . forEach ( tag => tags . add ( tag ) )
@@ -182,57 +171,31 @@ export const compareDocuments = async (apiType: OperationsApiType, operationsMap
182171 return { operationChanges : changedOperations , tags : [ ...tags . values ( ) ] }
183172}
184173
185- /** @deprecated */
186- export const compareRestOperationsData = async ( current : VersionRestOperation | undefined , previous : VersionRestOperation | undefined , ctx : CompareOperationsPairContext ) : Promise < Diff [ ] > => {
187-
188- let previousOperation = removeComponents ( previous ?. data )
189- let currentOperation = removeComponents ( current ?. data )
190- if ( ! previousOperation && currentOperation ) {
191- previousOperation = createCopyWithEmptyPathItems ( currentOperation as RestOperationData )
192- }
193-
194- if ( previousOperation && ! currentOperation ) {
195- currentOperation = createCopyWithEmptyPathItems ( previousOperation as RestOperationData )
196- }
197-
198- const diffResult = apiDiff (
199- previousOperation ,
200- currentOperation ,
201- {
202- ...NORMALIZE_OPTIONS ,
203- originsFlag : ORIGINS_SYMBOL ,
204- mode : COMPARE_MODE_OPERATION ,
205- normalizedResult : true ,
206- beforeSource : previous ?. data ,
207- afterSource : current ?. data ,
208- } ,
209- )
210- const olnyBreaking = diffResult . diffs . filter ( ( diff ) => diff . type === breaking )
211- if ( olnyBreaking . length > 0 && previous ?. operationId ) {
212- await reclassifyBreakingChanges ( previous . operationId , diffResult . merged , olnyBreaking , ctx )
213- }
214- return diffResult . diffs
215- }
216-
217174async function reclassifyBreakingChanges (
218- operationId : string ,
175+ previousOperationId : string | undefined ,
219176 mergedJso : unknown ,
220177 diffs : Diff [ ] ,
221178 ctx : CompareOperationsPairContext ,
222179) : Promise < void > {
223- if ( ! ctx . previousVersion || ! ctx . previousPackageId ) {
180+ if ( ! previousOperationId || ! ctx . previousVersion || ! ctx . previousPackageId ) {
181+ return
182+ }
183+
184+ const onlyBreaking = diffs . filter ( ( diff ) => diff . type === breaking )
185+ if ( isEmpty ( onlyBreaking ) ) {
224186 return
225187 }
226- const previosVersionDeprecations = await ctx . versionDeprecatedResolver ( REST_API_TYPE , ctx . previousVersion , ctx . previousPackageId , [ operationId ] )
227- if ( ! previosVersionDeprecations ) {
188+
189+ const previousVersionDeprecations = await ctx . versionDeprecatedResolver ( REST_API_TYPE , ctx . previousVersion , ctx . previousPackageId , [ previousOperationId ] )
190+ if ( ! previousVersionDeprecations ) {
228191 return
229192 }
230193
231- const previousOperation = previosVersionDeprecations . operations [ 0 ]
194+ const [ previousOperation ] = previousVersionDeprecations . operations
232195
233196 if ( ! previousOperation ?. deprecatedItems ) { return }
234197
235- for ( const diff of diffs ) {
198+ for ( const diff of onlyBreaking ) {
236199 if ( diff . type !== breaking ) {
237200 continue
238201 }
@@ -286,15 +249,13 @@ async function reclassifyBreakingChanges(
286249 }
287250 }
288251 // mark removed required status of the property as risky
289- if ( diffs . length ) {
290- const requiredProperties = findRequiredRemovedProperties ( mergedJso , diffs )
252+ const requiredProperties = findRequiredRemovedProperties ( mergedJso , onlyBreaking )
291253
292- requiredProperties ?. forEach ( prop => {
293- if ( prop . propDiff . type === RISKY_CHANGE_TYPE && prop . requiredDiff ?. type === BREAKING_CHANGE_TYPE ) {
294- prop . requiredDiff . type = risky
295- }
296- } )
297- }
254+ requiredProperties ?. forEach ( prop => {
255+ if ( prop . propDiff . type === RISKY_CHANGE_TYPE && prop . requiredDiff ?. type === BREAKING_CHANGE_TYPE ) {
256+ prop . requiredDiff . type = risky
257+ }
258+ } )
298259}
299260
300261export function createCopyWithEmptyPathItems ( template : RestOperationData ) : RestOperationData {
0 commit comments