@@ -23,7 +23,7 @@ import {
2323 ApiCompatibilityScopeFunction ,
2424} from '@netcracker/qubership-apihub-api-diff'
2525import { Labels } from '../../types'
26- import { findApiKindLabel , getApiKind } from '../document'
26+ import { calculateApiKindFromLabels , getApiKind } from '../document'
2727import { OpenAPIV3 } from 'openapi-types'
2828
2929export const getApiCompatibilityKind = ( beforeJson : unknown , afterJson : unknown ) : ApiCompatibilityKind | undefined => {
@@ -63,10 +63,6 @@ const checkAllMethodsHaveSameApiKind = (obj: unknown, apiKind: string): boolean
6363 if ( ! isObject ( obj ) ) {
6464 return false
6565 }
66-
67- if ( hasApiKind ( obj , apiKind ) ) {
68- return true
69- }
7066 const entries = Object . entries ( obj )
7167
7268 return entries . length > 0 &&
@@ -110,39 +106,40 @@ export const createApiKindChecker = (
110106 * Level 3: When individual operations are deleted/added
111107 */
112108 const isFirstPathSegmentPaths = path ?. [ 0 ] === 'paths'
113- if ( ! isFirstPathSegmentPaths || pathLength < PATH_ITEM_PATH_LENGTH || pathLength > OPERATION_OBJECT_PATH_LENGTH ) {
109+ if ( ! isFirstPathSegmentPaths ) {
114110 return undefined
115111 }
116-
117112 const beforeExists = isObject ( beforeJson )
118113 const afterExists = isObject ( afterJson )
119114
120115 if ( ! beforeExists && ! afterExists ) {
121116 return undefined
122117 }
123118
124- if ( beforeExists && afterExists ) {
125- return getApiCompatibilityKind ( beforeJson , afterJson )
119+ if ( pathLength === PATH_ITEM_PATH_LENGTH ) {
120+ // case remove: when a node disappears, api-diff emits REMOVE diffs for each
121+ // operation. We only mark the deletion as NO_BWC if all removed methods were
122+ // explicitly flagged NO_BWC, keeping deletions consistent with declared scope.
123+ if ( beforeExists && ! afterExists ) {
124+ return getMethodsApiCompatibilityKind ( beforeJson )
125+ }
126+
127+ // case add: additions are checked the same way. A new path or operation is
128+ // considered NO_BWC only when every contained method declares NO_BWC.
129+ if ( afterExists && ! beforeExists ) {
130+ return getMethodsApiCompatibilityKind ( afterJson )
131+ }
126132 }
127133
128- // case remove: when a node disappears, api-diff emits REMOVE diffs for each
129- // operation. We only mark the deletion as NO_BWC if all removed methods were
130- // explicitly flagged NO_BWC, keeping deletions consistent with declared scope.
131- if ( beforeExists && ! afterExists ) {
132- return getMethodsApiCompatibilityKind ( beforeJson )
133- }
134-
135- // case add: additions are checked the same way. A new path or operation is
136- // considered NO_BWC only when every contained method declares NO_BWC.
137- if ( afterExists && ! beforeExists ) {
138- return getMethodsApiCompatibilityKind ( afterJson )
134+ if ( pathLength === OPERATION_OBJECT_PATH_LENGTH ) {
135+ return getApiCompatibilityKind ( beforeJson , afterJson )
139136 }
140137
141138 return undefined
142139 }
143140}
144141
145- export const getApiKindFormLabels = (
142+ export const getApiKindFromLabels = (
146143 info ?: OpenAPIV3 . InfoObject ,
147144 fileLabels ?: Labels ,
148145 versionLabels ?: Labels ,
@@ -152,6 +149,6 @@ export const getApiKindFormLabels = (
152149 return infoApiKind . toLowerCase ( )
153150 }
154151
155- const apiKind = findApiKindLabel ( fileLabels , versionLabels )
152+ const apiKind = calculateApiKindFromLabels ( fileLabels , versionLabels )
156153 return apiKind ?. toLowerCase ( )
157154}
0 commit comments